Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jquery install example only works with link to dist/jquery.js #11

Open
stuaxo opened this issue Mar 4, 2014 · 8 comments
Open

jquery install example only works with link to dist/jquery.js #11

stuaxo opened this issue Mar 4, 2014 · 8 comments

Comments

@stuaxo
Copy link

stuaxo commented Mar 4, 2014

I installed jquery, but

/static/jquery/jquery.js did not work, however /static/jquery/dist/jquery.js did work - is this a configuration issue on my side ?

@stuaxo
Copy link
Author

stuaxo commented Mar 4, 2014

The same for angular-ui - I have to use angular-ui/build/angular-ui.js

It's a bit confusing, I have to check each component to find it's files.

@stuaxo
Copy link
Author

stuaxo commented Mar 4, 2014

I'm new to bower, but just wondering if the finder should be able to use the 'main' component of bower.json ?

In the jquery case, it points to dist/jquery.js

So, the finder should possibly be able to return it if you do jquery/jquery.js ?

@gsong
Copy link

gsong commented Mar 6, 2014

@stuaxo main could be an array such as is the case with Bootstrap. How would you propose that the finder behaves then?

@stuaxo
Copy link
Author

stuaxo commented Mar 7, 2014

Ah, interesting .. I'm very new to bower .. (as of 3 days ago in fact).

How about template tags instead ?

{% bower_scripts %}

  • would expands to script tags, pointing to any .javascript it finds

To find out if something is javascript, python mimetypes could be used at installation time:

import mimetypes
mimetypes.guess_type("bootstap.js")
('application/javascript', None)

{% bower_stylesheets %}

Could do the same for stylesheets.

These could have options to limit them to certain bower apps

{% bower_scripts "angularjs", "ng-grid" %}

(I'm not entirely sure if that notation will work for templates, but basically some way of passing the script names).

@gsong
Copy link

gsong commented Mar 7, 2014

I don't think an automatic way of discovery is the way to go, since there's no guarantee how each bower package structures its code and artifacts. I think the best you can hope for is to manually add your own mapping to alias the package structure, something like:

BOWER_COMPONENTS_MAPPING = {
    'jquery': 'jquery/dist',
    'angular': 'angular-ui/build',
    'bootstrap': 'bootstrap-sass-official/vendor/assets',
}

I would hook that into the behavior for djangobower.finders.BowerFinder (or your own custom finder) for it to know how to untangle the aliases, or fall back to searching within os.path.join(BOWER_COMPONENTS_ROOT, bower_components).

For certain purposes, template tags are too late, such as django-pipeline.

Your other options are:

  1. Add those paths to your STATICFILES_DIRS:
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'my_project/assets'),
    os.path.join(BOWER_COMPONENTS_ROOT, 'bower_components/jquery/dist'),
    os.path.join(BOWER_COMPONENTS_ROOT, 'bower_components/angular-ui/build'),
    os.path.join(BOOTSTRAP_ROOT, 'bower_components/bootstrap-sass-official/vendor/assets'),
)

But you'll have to be pretty sure that the packages don't collide with each other in terms of their component names.
2. Use something like Vendorer, which gives you the chance to manipulate the directory structure however you want (I haven't tested this code, but you get the idea).

file 'build/jquery.zip',
     'https://github.com/jquery/jquery/archive/2.1.0.zip' do |fp|
  build_dir = File.dirname(fp)
  unzipped_dir = File.join(build_dir, 'jquery-2.1.0')
  static_dir = 'bower_components/jquery'

  system "cd #{build_dir} && unzip -o #{File.basename(fp)}"
  system "rm -rf #{static_dir}"
  system "mkdir -p #{static_dir}"
  system "cp -r #{unzipped_dir}/dist/* #{static_dir}"
end

@stuaxo
Copy link
Author

stuaxo commented Mar 7, 2014

Ahh.. yes, I didn't think about the fact that something listed in main could call resources not listed.

Once I've added more bower dependencies to my project I might have a go at auto discovery and see if I can make it work.

@gsong
Copy link

gsong commented Mar 7, 2014

Good luck! ✌️

On Mar 7, 2014, at 6:26 AM, Stuart Axon notifications@github.com wrote:

Ahh.. yes, I didn't think about the fact that something listed in main could call resources not listed.

Once I've added more bower dependencies to my project I might have a go at auto discovery and see if I can make it work.


Reply to this email directly or view it on GitHub.

@MHellmund
Copy link

Please change the documentation of django-bower and replace the path in the example line
< script type="text/javascript" src='{% static 'jquery/jquery.js' %}'></script >
with 'jquery/dist/jquery.min.js'

It may avoid some initial frustration with this great package and everyone understands that one has to look for the exact path inside bower_components.

ribalba added a commit to ribalba/django-bower that referenced this issue Nov 18, 2014
Please see nvbn#11 for the discussion.
ribalba added a commit to ribalba/django-bower that referenced this issue Nov 18, 2014
See nvbn#11 for the full discussion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants