Coder Social home page Coder Social logo

js_assets's People

Contributors

guillaume-winddle avatar izaurio avatar kavkaz avatar mahemoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

js_assets's Issues

config.assets.digest=false ignored? (Rails 5)

After Rails upgrade, I notice the assets always have digests, even if config.assets.digest = false is set in development.rb.

The decision is here:

if env.file_digest(filename)

I'm not sure why, but I think that's true even if digest is off. So I guess the condition could be changed to check the config directly.

Custom environments

I have a staging environments. But in code env-s only production and development. In my environment i dont have any paths

Incompatible with Sprockets 3.x

We are using this gem inside one of our rails apps and I just updated to the latest release of the sass-rails gem, which in turn bumped the sprockets version in our Gemfile.lock to 3.0.3, and then when I went to reboot the server I got this message:

/usr/local/lib/ruby/gems/2.1.0/gems/js_assets-0.0.9/lib/js_assets/list.rb:12:in `block in fetch': undefined method `logical_path_for_filename' for #<Sprockets::Environment:0x007f84100e06f0> (NoMethodError)
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/paths.rb:73:in `block (2 levels) in each_file'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/path_utils.rb:223:in `block in stat_tree'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/path_utils.rb:207:in `block in stat_directory'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/path_utils.rb:204:in `each'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/path_utils.rb:204:in `stat_directory'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/path_utils.rb:222:in `stat_tree'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/paths.rb:71:in `each'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/paths.rb:71:in `block in each_file'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/paths.rb:70:in `each'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/paths.rb:70:in `each_file'
    from /usr/local/lib/ruby/gems/2.1.0/gems/js_assets-0.0.9/lib/js_assets/list.rb:11:in `fetch'
    from /usr/local/lib/ruby/gems/2.1.0/gems/js_assets-0.0.9/app/assets/javascripts/app_assets.js.erb:1:in `_evaluate_template'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/erb_processor.rb:26:in `call'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/erb_processor.rb:13:in `call'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/processor_utils.rb:75:in `call_processor'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/processor_utils.rb:56:in `reverse_each'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/processor_utils.rb:56:in `call_processors'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/loader.rb:87:in `load_asset_by_uri'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/loader.rb:45:in `block in load'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/loader.rb:157:in `fetch_asset_from_dependency_cache'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/loader.rb:38:in `load'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/cached_environment.rb:20:in `block in initialize'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/cached_environment.rb:47:in `yield'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/cached_environment.rb:47:in `load'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/bundle.rb:23:in `block in call'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/utils.rb:183:in `dfs'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/bundle.rb:24:in `call'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/processor_utils.rb:75:in `call_processor'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/processor_utils.rb:56:in `reverse_each'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/processor_utils.rb:56:in `call_processors'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/loader.rb:87:in `load_asset_by_uri'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/loader.rb:45:in `block in load'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/loader.rb:157:in `fetch_asset_from_dependency_cache'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/loader.rb:38:in `load'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/cached_environment.rb:20:in `block in initialize'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/cached_environment.rb:47:in `yield'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/cached_environment.rb:47:in `load'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/base.rb:63:in `find_asset'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/environment.rb:30:in `find_asset'
    from /usr/local/lib/ruby/gems/2.1.0/gems/sprockets-3.0.3/lib/sprockets/base.rb:89:in `[]'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/rails/railtie.rb:68:in `block (3 levels) in <class:Railtie>'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/rails/railtie.rb:67:in `map'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/rails/railtie.rb:67:in `block (2 levels) in <class:Railtie>'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/renderer.rb:73:in `call'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/renderer.rb:73:in `setup_combined_js'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/renderer.rb:78:in `reset_combined_js!'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/renderer.rb:20:in `setup!'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/rails/railtie.rb:74:in `block (2 levels) in <class:Railtie>'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/rails/railtie.rb:78:in `call'
    from /home/vagrant/.bundler/ruby/2.1.0/react-rails-99a1b38b28db/lib/react/rails/railtie.rb:78:in `block in <class:Railtie>'
    from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib/active_support/lazy_load_hooks.rb:36:in `call'
    from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/application/finisher.rb:64:in `block in <module:Finisher>'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/initializable.rb:30:in `run'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /usr/local/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/application.rb:300:in `initialize!'
    from /vagrant/config/environment.rb:5:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/application.rb:276:in `require'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/application.rb:276:in `require_environment!'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:8:in `require'
    from bin/rails:8:in `<main>'

Correct me if I'm wrong, but I believe this gem is the one invoking sprockets. At any rate, limiting the max sprockets version to 2.x on our Gemfile stopped these errors from being raised.

The issue appears to be that the method in question, logical_path_for_filename, existed on Sprockets 2.x but was removed at some point prior to the release of Sprockets 3.

I just did some digging... here is the commit moving it of the Sprockets::Environment class.

Here's a commit making it private..

Here's a commit where the method is renamed to normalize_logical_path

At any rate I can't keep tracking it but it looks like for Sprockets 3 the appropriate method to call to find the path for something is Sprockets::Environment#resolve from the Sprockets::Resolve module.

For now I would release a v0.10 of this gem with a gem dependency limiter for sprockets 2.x and then look into making a new release to fix the feature. Sorry I can't be of more help but I am not very familiar with the Sprockets gem / the internals of the asset pipeline.

Not finding my asset

I am using a custom RAILS_ENV=staging for my QA environment, but I think this issue still exists if I set RAILS_ENV=production. I looked through your code for specific references to environment names and found that they had been removed, so I'm guessing this should work. (Maybe it's something addressed by the open pull request. Not sure.)

I have a little red "X" png that is part of my image assets, and it needs to be included in some javascript code that adds nested attributes as part of a workflow for file attachments. The file x_16x16.png is in the asset pipeline.

$ RAILS_ENV=staging rails c
Loading staging environment (Rails 4.2.7.1)
2.3.0 :001 > ActionController::Base.helpers.asset_path('x_16x16.png')
 => "/assets/x_16x16-7d1b5578d7288518ff6184d04063cf116faf9ab5a52d7f19898af57280de5303.png"

However, I include this snippet:

content += "<td><a href='javascript: void(0);' onClick='remove_attachment(this," + i + ");'><img src='" + asset_path('x_16x16.png') + "'></a></td></tr>";

and it comes out like:

<a href="javascript: void(0);" onclick="remove_attachment(this,0);"><img src="/assets/x_16x16.png"></a>

Can you help? I have found no other way to include asset paths in javascript cleanly.

NoMethodError: undefined method `logical_paths' for nil:NilClass

I get this error during precompilation:

NoMethodError: undefined method `logical_paths' for nil:NilClass
/usr/local/rvm/gems/ruby-2.2.2/gems/js_assets-0.1.0/lib/js_assets/list.rb:10:in `fetch'
/usr/local/rvm/gems/ruby-2.2.2/gems/js_assets-0.1.0/app/assets/javascripts/app_assets.js.erb:1:in `_evaluate_template'

This is the relevant line:

::Rails.application.assets.logical_paths do |logical_path, filename|

It's legal for Rails.application.assets to be nil in production:

https://github.com/rails/sprockets-rails

config.assets.compile

Enables Sprockets compile environment. If disabled, Rails.application.assets will be nil to prevent inadvertent compilation calls. View helpers will depend on assets being precompiled to public/assets in order to link to them. Initializers expecting Rails.application.assets during boot should be accessing the environment in a config.assets.configure block. See below.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.