Giter Site home page Giter Site logo

sprockets-rails's Introduction

Sprockets Rails

Provides Sprockets implementation for Rails 4.x (and beyond) Asset Pipeline.

Installation

gem 'sprockets-rails', :require => 'sprockets/railtie'

Or alternatively require 'sprockets/railtie' in your config/application.rb if you have Bundler auto-require disabled.

Usage

Rake task

rake assets:precompile

Deployment task that compiles any assets listed in config.assets.precompile to public/assets.

rake assets:clean

Only removes old assets (keeps the most recent 3 copies) from public/assets. Useful when doing rolling deploys that may still be serving old assets while the new ones are being compiled.

rake assets:clobber

Nuke public/assets.

Customize

If the basic tasks don't do all that you need, it's straight forward to redefine them and replace them with something more specific to your app.

You can also redefine the task with the built in task generator.

require 'sprockets/rails/task'
Sprockets::Rails::Task.new(Rails.application) do |t|
  t.environment = lambda { Rails.application.assets }
  t.assets = %w( application.js application.css )
  t.keep = 5
end

Each asset task will invoke assets:environment first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment.

Also see Sprockets::Rails::Task and Rake::SprocketsTask.

Initializer options

config.assets.unknown_asset_fallback

When set to a truthy value, a result will be returned even if the requested asset is not found in the asset pipeline. When set to a falsey value it will raise an error when no asset is found in the pipeline. Defaults to true.

config.assets.precompile

Add additional assets to compile on deploy. Defaults to application.js, application.css and any other non-js/css file under app/assets.

config.assets.paths

Add additional load paths to this Array. Rails includes app/assets, lib/assets and vendor/assets for you already. Plugins might want to add their custom paths to this.

config.assets.quiet

Suppresses logger output for asset requests. Uses the config.assets.prefix path to match asset requests. Defaults to false.

config.assets.version

Set a custom cache buster string. Changing it will cause all assets to recompile on the next build.

config.assets.version = 'v1'
# after installing a new plugin, change loads paths
config.assets.version = 'v2'

config.assets.prefix

Defaults to /assets. Changes the directory to compile assets to.

config.assets.digest

When enabled, fingerprints will be added to asset filenames.

config.assets.debug

Enable asset debugging mode. A source map will be included with each asset when this is true.

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.

config.assets.configure

Invokes block with environment when the environment is initialized. Allows direct access to the environment instance and lets you lazily load libraries only needed for asset compiling.

config.assets.configure do |env|
  env.js_compressor  = :uglifier # or :closure, :yui
  env.css_compressor = :sass   # or :yui

  require 'my_processor'
  env.register_preprocessor 'application/javascript', MyProcessor

  env.logger = Rails.logger
end

config.assets.resolve_assets_in_css_urls

When this option is enabled, sprockets-rails will register a CSS postprocessor to resolve assets referenced in url() function calls and replace them with the digested paths. Defaults to true.

config.assets.resolve_with

A list of :environment and :manifest symbols that defines the order that we try to find assets: manifest first, environment second? Manifest only?

By default, we check the manifest first if asset digests are enabled and debug is not enabled, then we check the environment if compiling is enabled:

# Dev where debug is true, or digests are disabled
%i[ environment ]

# Dev default, or production with compile enabled.
%i[ manifest environment ]

# Production default.
%i[ manifest ]

If the resolver list is empty (e.g. if debug is true and compile is false), the standard rails public path resolution will be used.

config.assets.check_precompiled_asset

When enabled, an exception is raised for missing assets. This option is enabled by default.

Complementary plugins

The following plugins provide some extras for the Sprockets Asset Pipeline.

NOTE That these plugins are optional. The core coffee-script, sass, less, uglify, (and many more) features are built into Sprockets itself. Many of these plugins only provide generators and extra helpers. You can probably get by without them.

Changes from Rails 3.x

  • Only compiles digest filenames. Static non-digest assets should simply live in public/.
  • Unmanaged asset paths and urls fallback to linking to public/. This should make it easier to work with both compiled assets and simple static assets. As a side effect, there will never be any "asset not precompiled errors" when linking to missing assets. They will just link to a public file which may or may not exist.
  • JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign config.assets.js_compressor = :uglifier or config.assets.css_compressor = :sass for the standard compressors.
  • The manifest file is now in a JSON format. Since it lives in public/ by default, the initial filename is also randomized to obfuscate public access to the resource.
  • config.assets.manifest (if used) must now include the manifest filename, e.g. Rails.root.join('config/manifest.json'). It cannot be a directory.
  • Two cleanup tasks: rake assets:clean is now a safe cleanup that only removes older assets that are no longer used, while rake assets:clobber nukes the entire public/assets directory. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.

But what if I want sprockets to generate non-digest assets?

You have several options:

Experimental

SRI support

Sprockets 3.x adds experimental support for subresource integrity checks. The spec is still evolving and the API may change in backwards incompatible ways.

javascript_include_tag :application, integrity: true
# => "<script src="/assets/application.js" integrity="sha256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>"

Note that sprockets-rails only adds integrity hashes to assets when served in a secure context (over an HTTPS connection or localhost).

Contributing to Sprockets Rails

Sprockets Rails is work of many contributors. You're encouraged to submit pull requests, propose features and discuss issues.

See CONTRIBUTING.

Releases

sprockets-rails 3.x will primarily target sprockets 3.x. And future versions will target the corresponding sprockets release line.

The minor and patch version will be updated according to semver.

  • Any new APIs or config options that don't break compatibility will be in a minor release
  • Any time the sprockets dependency is bumped, there will be a new minor release
  • Simple bug fixes will be patch releases

License

Sprockets Rails is released under the MIT License.

Code Status

  • Gem Version

sprockets-rails's People

Contributors

amatsuda avatar arthurnn avatar byroot avatar carlosantoniodasilva avatar connorshea avatar dhh avatar eileencodes avatar etiennebarrie avatar ghiculescu avatar guilleiguaran avatar jaredbeck avatar jcoyne avatar jeremy avatar johnnyshields avatar josh avatar lostapathy avatar lucasmazza avatar maclover7 avatar matthewd avatar mquy avatar mvz avatar olleolleolle avatar pixeltrix avatar rafaelfranca avatar rmacklin avatar schneems avatar seuros avatar skipkayhil avatar swisener avatar yahonda 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  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  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  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sprockets-rails's Issues

Asset pre-compilation

Maybe I'm missing something, but the way rake assets:precompile is working seems strange.

When I run it without changing the RAILS_ENV I get the assets precompiled into tmp/cache/assets/development. Ok but I'm trying to precompile for production, so I try setting my RAILS_ENV=production and I get a folder named production instead, but the task fails because production obviously doesn't have the right gems loaded to compile.

Is this a bug or what am I doing wrong?

Sprockets doesn't precompile images/fonts

I'm using sprockets and I have some 3rd party libraries (ckeditor, videojs and others) both as gem or in the vendor folder. Unfortunately when the assets are precompiled it generates in the assets folder only the css/js files, ignoring all the images and fonts, causing the libraries to not working correctly

config.assets.enabled is nil in production in Rails 4 rc1

Hello,

I have an app in Rails 4 which is not loading correctly the assets in production. It has been found that the error comes from the railtie.rb file in sprocket (rails/rails#10334).

When I run rails c in production, the line Rails.application.config.assets.enabled returns nil, so the files served are /stylesheets/application.css instead of /assets/application-digest.css

To fix it I had to add config.assets.enabled = true to line 58 in file https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L99

Maybe I'm configuring wrong my app, can you guys help me fix it?

RAILS_RELATIVE_URL_ROOT is cached in tmp/cache/assets/production/

Running assets:precompile with different values for RELATIVE_URL_ROOT won't regenerate the assets. If you execute:

RAILS_RELATIVE_URL_ROOT="/myroot" RAILS_ENV=production bin/rake assets:precompile

The first time it works as expected. Every subsequent call with different values for RAILS_RELATIVE_URL_ROOT will result in the same generated css files, having "/myroot" prefixed.

The same problems apply if you run assets:precompile the first time without RAILS_RELATIVE_URL_ROOT, then you won't be able to specify a relative root on subsequent calls.

After removing tmp/cache/assets/production/ it works again.

EDIT: I've used Rails 4.0.0.rc2

javascript_include_tag + duplicated files

Please let me know how I can proceed to best help.

I came across an issue that exists in Sprockets::Helpers::RailsHelper.javascript_include_tag (Rails 3.2.9) where in files can be required and loaded multiple times. Calling flatten on the array before uniq resolves this issue. Review an example.

I'll add a commit that resolves this in 3.2, but since all of this is changing and in (what appears to be) heavy flux for 4, I'm unsure how I can approach ensuring that it doesn't linger in the next release. I'm aware that these helpers will go away, and that's where I'm looking for guidance.

Presence of bower.json file can break javascript requiring when using a manifest (index.js)

I discovered that the presence of a bower.json in the asset path was breaking my app. Adding and removing the file had the effect of breaking and fixing my app. I wasn't aware that rails, specifically sprockets was Bower aware, until this happened. Upon tracing the source, I discovered the following...

sprockets-2.10.0/lib/sprockets/base.rb:132
if %w( bower.json component.json ).include?(pathname.basename.to_s)

I know nothing of Bower except that it is for Node, am I right? I used it once in a test Node app.

I just noticed the most recent version comment about support for bower.json.
Maybe there is a bug here, because this dependency I'm using (jQuery-File-Upload) which has the bower.json, definitely breaks my app, and it's right about there.

What is the presence of bower.json meant to acheive/accomplish?
How should it be used?

Rails.application.config.assets.digests

In Rails 3.2, I provided dynamic customization of multiple tenants' CSS via a mechanism which recompiled the SASS files once a client had updated their color palette, rewrote the manifest file with the updates, then updated Rails.application.config.assets.digests with the new manifest file. With Rails 4, is something like that still possible...i.e. updating the store in Rails which holds the manifest? I was unable to track down where that is data is stored with changes to the asset pipeline. Can someone point me in the right direction? Thanks.

Version 2.3.1.1 of the gem is crashing on Rails 4 edge

PLEASE DELETE/IGNORE WRONG REPOSITORY
A change made to the recent upgrade appears to be creating problems with the asset pipeline and processing of scss.css files - I get the following error

ActionView::Template::Error (undefined method []' for nil:NilClass (in /Users/dbk/Development/what2do.asia/app/assets/stylesheets/application.css.scss)): 8: <meta charset="UTF-8"> 9: <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 10: <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 11: <%= stylesheet_link_tag "application" %> 12: <%= javascript_include_tag "application" %> 13: <%= csrf_meta_tags %> 14: <%= yield :javascript_includes %> app/views/layouts/landing.html.erb:11:in_app_views_layouts_landing_html_erb___341406046238958875_70179661990380'

downgrading to v 2.3.1.0 of the gem eliminates this problem. Unfortunately havent had time to probe this further

Add processor-specific directives

I often write code like this in CoffeeScript:

@MyClass = class MyClass
  # ...

while I'd prefer to just write

class MyClass
  # ...

The problem is that I don't know any way of disabling the top-level function wrapper with Sprockets. This is equivalent to the --bare option of the coffee command.

It would be awesome if Sprockets could support custom defined directives per processor. For instance:

# =coffee_bare true
class MyClass
  # ...

Or any other syntax that would allow us to have fine tune over our assets generation.

Is this already possible? I couldn't find how to do that anywhere...

Thanks in advance.

Clarification: asset_path for non-JS/CSS files links to public/ now?

I'm writing an app that requires some static templates on the client-side (using Angular) currently on Rails 4.0.0.rc1. I added the templates into app/assets/templates/example.html and use asset_path in a js.erb file to render out the path to the template for the client.

In previous versions of Rails asset_path would produce a path like /assets/example.html, but now it returns /example.html and can no longer be reached since it's not in the assets/ virtual path AND there's no file by that name in public/.

Is the suggested workflow now to put all static assets in public/ directly? I did that and it obviously works but it's not as clean as keeping all of my client-side assets together in app/assets and having them grouped by sprockets into the virtual assets/ path.

I did see the following point under Changes from Rails 3.x in the README but without further elaboration on the meaning of "unmanaged asset paths" it was still unclear to me:

Unmanaged asset paths and urls fallback to linking to public/. This should make it easier to work with both compiled assets and simple static assets. As a side effect, there will never be any "asset not precompiled errors" when linking to missing assets. They will just link to a public file which may or may not exist."

`config.assets.precompile` behavior has changed

In earlier versions (~> 3.2) it had a proc that covered all non-js/css files as we see here
https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/application/configuration.rb#L48
Those types of files could be in the third party libraries, but for now it limits us within app/assets directory regarding this lambda https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L39

Was it done intentionally? Should the third party libraries append their own settings to config.assets.precompile or we should configure it in apps? Thanks in advance!

Asset logging not disabled after upgrading to rails 4

I see this article about asset logging in rails 4:
http://blog.remarkablelabs.com/2012/12/sprockets-rails-rails-4-countdown-to-2013

After upgrading to rails 4 beta today, I still see logs in my console:

Started GET "/assets/bootstrap-datepicker.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:32 -0800
Started GET "/assets/gmaps.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:32 -0800
Started GET "/assets/items.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:32 -0800
Started GET "/assets/lib/jquery.extensions.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:32 -0800
Started GET "/assets/lib/jquery.glass.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:32 -0800
Started GET "/assets/lib/jquery.overlay.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:32 -0800
Started GET "/assets/messages.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:32 -0800
Started GET "/assets/omniauth_callbacks.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:32 -0800
Started GET "/assets/pages.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:33 -0800
Started GET "/assets/payments.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:33 -0800
Started GET "/assets/rentals.js?body=1" for 127.0.0.1 at 2013-03-03 13:58:33 -0800
....

Is there something I need to do to disable the logging after upgrade?

Non-JS/CSS assets (e.g. images) from lib, vendor are precompiled

I encountered a problem with assets from engines, when using rails 4.0.0.beta + sprockets-rails 2.0.0.rc1:

The documentation of the default rails production.rb environment file says, that 'all' non-JS/CSS assets are already added:

Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added).

But as in https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L38-40 defined, no non-JS/CSS assets from lib or vendor are precompiled.

I fixes with a application local precompile lambda:

config.assets.precompile << lambda do |path, filename|
  filename =~ /(app|lib|vendor)\/assets/ && !%w(.js .css).include?(File.extname(path))
end

I think this should be included to the Sprockets:: Railtie.

Inability to compile nondigest and digest assets breaks compatibility with bad gems

For instance, the jquery_mobile-rails gem does not use image-url in its CSS. This is a bug really, but it "worked fine" in Rails 3. I assume they will fix the gem eventually. But in the meantime, in Rails 4, it is broken and as far as I can tell there's no way to work around it. The simple short term fix is to compile both digest and nondigest assets for this gem, but I don't see any way to do that. I can apparently only turn digest off or on globally for the application.

A rake assets:precompile:nondigest task or something similar would provide a workaround. But it seems to be gone now.

Is there a good way to deal with this, or do I just have to drop the gem and manage jquery mobile manually outside the asset pipeline, which is a pain?

Error when precompiling HTML ERb files

Background

Our error pages use the same stylesheets as our Rails application. We need to be able to point to these stylesheets from our error pages. I moved the error pages into app/assets/pages, and would like them precompiled so we can accomplish this. This solution works fine in development mode where the assets are generated on the fly. However, it breaks precompiling from the command line using any Rails environment.

Error

When I run bundle exec rake assets:precompile inside my Rails 4 app's directory, I receive the following error:

undefined local variable or method 'debug_assets' for #<#<Class:0x007fdba5bd0>:0x007fdba41ed8>

I have HTML ERb files inside my app/assets/pages directory and told Rails about them by doing the following:

module MyApp
  class Application < Rails::Application
    config.assets.paths << "#{Rails.root}/app/pages/html"
    config.assets.precompile += %w(404.html 500.html)
  end
end

Here's the stack trace + HTML ERb file:
https://gist.github.com/chrisledet/b8bb3765dc61f0d532cb

Seems like the error is coming from:
https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/helper.rb#L130

StaticCompiler is gone?

Hello,

I wanted to compile some individual assets in my rails4 project, by using
compiler = Sprockets::StaticCompiler.new...

but that doesn't work anymore. Is there any replacement for StaticCompiler?

Asset rendered without fingerprint

Gemfile:

gem 'rails', '4.0.0'
gem 'sprockets-rails', github: 'rails/sprockets-rails'

I have an image app/assets/images/logo/logo.png and a template file app/assets/templates/test.html.erb. The content of the template file is:

<%= image_tag 'logo/logo.png' %>

With the current sprockets-rails release, this results in:

undefined method `image_tag`

Fortunately commit 868dbf0 fixes this error. However the content of the compiled template is:

<img alt="Logo" src="/assets/logo/logo.png" />

As you can see, the filename doesn't contain the fingerprint.

Stylesheet not picking up @import

I'm not really sure if this is the place to post this.

In rails 3.2 I could use @import in my application.css.scss file to include all my stylesheets but in 4.beta they're not recognized.

For example, I have to import the bourbon gem sass file @import 'bourbon;' in every, sass, stylesheet now. Is this a bug or is it how we handle this from now on?

Make parser to work as advertized in application.js

Blank line warning is wrong. Here what is says in application.js:

// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.

In fact this is not true, the following compiles just fine:

//= require jquery
//= require jquery_ujs
//= require_tree .

//= require turbolinks

For some assets the weird path is returned.

I use Bower to manage frontend packages. All packages are installed under vendor/assets so this is how this folder looks like:

vendor/assets/
|-- backbone
|   |-- backbone.js
|   |-- backbone-min.js
|   |-- backbone-min.map
|   |-- CNAME
|   |-- CONTRIBUTING.md
|   |-- docs
|   |-- examples
|   |-- index.html
|   |-- index.js
|   |-- LICENSE
|   |-- package.json
|   |-- Rakefile
|   |-- README.md
|   `-- test
|-- jquery
|   |-- bower.json
|   |-- component.json
|   |-- composer.json
|   |-- jquery.js
|   |-- jquery-migrate.js
|   |-- jquery-migrate.min.js
|   |-- jquery.min.js
|   |-- jquery.min.map
|   |-- package.json
|   `-- README.md
|-- nprogress
|   |-- bower.json
|   |-- component.json
|   |-- History.md
|   |-- index.html
|   |-- License.md
|   |-- Notes.md
|   |-- nprogress.css
|   |-- nprogress.js
|   |-- package.json
|   |-- Readme.md
|   |-- support
|   |-- test
|   `-- vendor
|-- rivets
|   |-- component.json
|   |-- dist
|   |-- Gruntfile.coffee
|   |-- LICENSE
|   |-- package.json
|   |-- README.md
|   |-- spec
|   `-- src
|-- rivets-backbone
|   |-- example
|   |-- README.md
|   `-- rivets-backbone.js
`-- underscore
    |-- CNAME
    |-- CONTRIBUTING.md
    |-- docs
    |-- favicon.ico
    |-- index.html
    |-- LICENSE
    |-- package.json
    |-- Rakefile
    |-- README.md
    |-- test
    |-- underscore.js
    |-- underscore-min.js
    `-- underscore-min.map

18 directories, 49 files

In my app/assets/javascripts/application.js I have most of them required:

//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require turbolinks
//
//= require bootstrap-collapse
//= require bootstrap-dropdown
//
//= require nprogress
//
//= require underscore
//= require backbone
//= require src/rivets
//= require rivets-backbone
//
//= require base
//
//= require bets

But in view the path to rivets-backbone is bad:

<script data-turbolinks-track="" src="/assets/../rivets-backbone/rivets-backbone.js?body=1" type="text/javascript"></script>

Url image on CSS not fingerprinted

I'm using sprockets 2.10.1 with rails 4, and when i use a tag image-url on a SCSS file, this does not return to me the fingerprinted version of the image, only the real name.

My image is in "app/assets/image/icons/social/facebook.png", when i compile it, it live in:
" public/assets/icons/social/facebook-73d00144595b5a4c37b816604c2fe6ed.png "

The css file is in "vendor/assets/stylesheets/app.css.scss", and the line is:

.social_facebook { background: image-url("icons/social/facebook.png") no-repeat; }

And i call it on the css manifest file this way:

*= require app

And the final css file gives me this piece of code:

.social_facebook {
  background: url(/assets/icons/social/facebook.png) no-repeat; }

Note the non fingerprinted call to the image.

I've tried a lot of configurations, only the live compilation config.assets.compile = true solves the problem, but it is not the best way to let a app on production due to performance issues.

How can i solve this?
Cheers.

Provide a standard way to define custom asset helpers

@sidonath (rails#3282):

While it's easy to define a custom view helper in Rails, it's not trivial to define similar helpers for the Asset Pipeline assets.

Such helpers would be useful for precompiled JS templates, static HTML pages (eg. we have app/assets/html/404.html.erb that is symlinked to public/404.html in production) and probably other code reuse scenarios in not-so-static assets.

Currently, we solve this problem by including a custom AssetHelper module (defined in app/helpers) into Sprockets::Helpers::RailsHelper. We do this in config/application.rb (since initializers are not loaded for assets:precompile).

A better solution could be to define app/helpers/asset_helper.rb and include it by default into both views and assets contexts (since there is a high chance that a helpers would be reused between views and assets). Of course a configuration directive could be provided to allow including any helpers into the asset pipeline context, like:

config.assets.helpers << %w{other_asset_helpers}

@xavierholt (rails#3282):

And an additional request for the implementation: In development mode, changes to the included helpers should be noticed and should trigger a recompile of the asset files that use them.

assets:precompile task running in development environment

$ rake assets:precompile
Loading development environment

And in the compiled public/assets/application-digest.css file image filenames don't include digest part. And server running in production can't find image assets.

For the right behavior must provide RAILS_ENV=production in command line manualy.

Is this expected bahaviour? Or i missed something in documentation?

Sprockets Rails 2.0.0.rc1 breaks rails

After the last commit (Version update) in sprockets. 'bundle update' fail now with this message :

Could not find gem 'sprockets-rails (~> 1.0) ruby', which is required by gem 'rails (>= 0) ruby', in any of the sources.

ERB templated asset using asset_url don't get updated when references get new digests

Common Scenario:

  1. Create an asset like application.js.erb which uses a helper like: var externalTemplate = "<%= asset_url('html-template.html') %>";
  2. Have that helper reference another asset like html-template.html.erb
  3. Run rake assets:precompile to create compiled versions with digests
  4. Change something in html-template.html.erb
  5. Rerun rake assets:precompile which creates a new digest for html-template.html but not for application.js
  6. Verify that the digested version of application.js has not changed and externalTemplate still points to the old digested version of html-template.html.erb

This is the scenario I'm having trouble with but I expect that any thing that changes in the ERB template like <%= Time.now %> would have a similar problem, in that the asset pipeline doesn't think anything will have changed.

This may be intended and one can just call rake assets:clobber or update the asset version to "fix" this. However I'm thinking it might be wise to assume ERB template output can change even if the template itself is the same.

Right now this causes issues for me with Heroku and we need to make sure to update the asset version if we make any changes to our AngularJS templates without changing the Javascript.

2.0.0.backport1 is breaking sass-rails 3.2.6

I just discover this gem has a backport version from here
So I was hoping to speed up asset compilation

But it throws an error on any sass file (the first one it encounters)
And even if the content of the file is empty, the error still exists
But when compile without sprocket-rails and with sprocket only, there is no error

Using

  • rails 3.2.15
  • sass-rails 3.2.6
  • sprocket 2.2.2.backport2

Backtrace:

undefined method `asset_paths' for #<#<Class:0x007fb069f021e0>:0x007fb067eec6d0>
  (in /Users/PikachuEXE/Projects/spacious-rails/app/assets/stylesheets/application-split2.scss)
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sass-rails-3.2.6/lib/sass/rails/template_handlers.rb:23:in `source_path'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sass-rails-3.2.6/lib/sass/rails/template_handlers.rb:84:in `sass_options'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sass-rails-3.2.6/lib/sass/rails/template_handlers.rb:106:in `evaluate'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/context.rb:197:in `block in evaluate'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/context.rb:194:in `each'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/context.rb:194:in `evaluate'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:374:in `new'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:373:in `build_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:93:in `build_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:287:in `find_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:61:in `find_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:377:in `new'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:377:in `build_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:93:in `build_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:287:in `find_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:61:in `find_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:211:in `block in find_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:257:in `benchmark'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:210:in `find_asset'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:119:in `block in compile'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:118:in `each'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:118:in `compile'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-rails-2.0.0.backport1/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-2.2.2.backport2/lib/rake/sprocketstask.rb:146:in `with_logger'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/sprockets-rails-2.0.0.backport1/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
/Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile

Re-add support for manifest path option

In rails/rails#7702 I see that @guilleiguaran removed the config.assets.manifest option.

I use this as part of my deploy workflow, and would like to request to restore it. I compile my assets locally to /public/assets/ ( not version-controlled ) and compile manifest.yml in a separate folder ( version-controlled ). I then push my compiled assets to an asset server (Amazon S3), and I push manifest.yml to my production web servers.

Note that Rails 3 requires manifest.yml to be present on the local web server, even when you are serving your assets from a remote server. (not sure about Rails 4)

support for url_options for assets

maybe there is a better way to do this.
would you accept a patch such as this

rails/rails#11021

at this point, we are still using rails 3.2
so this monkey patch prove to be working to solve our problem.

http://stackoverflow.com/questions/17192082/how-could-the-asset-pipeline-use-url-options-to-automatically-append-parameters/17201818#17201818

I wondered if there would be more interested.

I tried packaging my monkey patch as a gem

https://github.com/mjobin-mdsol/url_options_for_assets

License missing from gemspec

Some companies will only use gems with a certain license.
The canonical and easy way to check is via the gemspec,

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Even for projects that already specify a license, including a license in your gemspec is a good practice, since it is easily
discoverable there without having to check the readme or for a license file.

For example, there is a License Finder gem to help companies ensure all gems they use
meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough
issue that even Bundler now generates gems with a default 'MIT' license.

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file),
github has created a license picker tool.

In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally
looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :).

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue and let me know. In either case, I'll follow up. Thanks!

p.s. I've written a blog post about this project

asset_path, javascript_path etc helpers not working in production on Rails 4 RC1

I've been using Rails 4.0.0.rc1, and the assets helpers are not working correctly.
I've tried many, like asset_path, javascript_path, compute_asset_path, asset_digest_path etc. all return the paths like '...asset.ext' - without the digest, which I am using. digest_assets is also nil and assets_manifest is also nil, but I am using all of these. I don't have compile enabled in production (as per default). I want to get the path of an asset in production.
The web app itself works fine, i.e. the assets are displayed and used correctly by Rails itself, but I need to get the path in my code, and this is not working for me.

Thanks!

Regress GZip compression in Rails 4

I have project with latest Rails 4 and Sprockets Rails 2.0.0.rc1, but when I execute rake assets:precompile, there isn’t any *.gz files in public/assets.

Sprockets will compress file if write_to get :compress option or files with .gz on the end. As I understand in Rails 3.2 static_compiler sent this options. Previous version of Sprockets Rails aslo contain static_compiler, but current version doesn’t have any one. So we regress GZip compression.

Make it easier to override loose asset settings

I have a couple nested README.md files within my asset path that were intended to be kept private. They store developer notes related to subcomponents of the app. Although they don't contain anything sensitive it would be nice to keep them out of the pipeline.

Right now there's no easy way to ignore them. It would be nice if we could override the loose asset settings using something like:

# full override
config.assets.loose_assets = lambda do |filename, path|
  path =~ /app\/assets/ && !%w(.js .css .md).include?(File.extname(filename))
end

# other approaches
config.assets.ignore = %w(.js .css .md)
config.assets.ignore << ".md"

Happy to take a stab at this myself if there's support for it.

Second run assets:precompile takes more time then first. Rails 4.0.0

First run:

>time rake RAILS_ENV=production assets:precompile
I, [2013-10-28T18:14:20.561615 #20892]  INFO -- : Writing /project/public/assets/....-4717b1487838fc7acd71d97b9e6ce5c9.css
I, [2013-10-28T18:14:20.803834 #20892]  INFO -- : Writing /project/public/assets/....-20af0828b5e1d3d761d38757fa5e3f99.css
I, [2013-10-28T18:14:22.298937 #20892]  INFO -- : Writing /project/public/assets/....-3e276bea38897668476fa18bead93447.css
I, [2013-10-28T18:14:22.539208 #20892]  INFO -- : Writing /project/public/assets/....-1c0d4327e9b8048f118abf3ae82cedc8.css
I, [2013-10-28T18:14:23.655921 #20892]  INFO -- : Writing /project/public/assets/....-511114ec374db50424d881b49330705c.css
I, [2013-10-28T18:14:24.021353 #20892]  INFO -- : Writing /project/public/assets/....-c9b62ca79c5dae0f2c0094ff5b8b445c.css
I, [2013-10-28T18:14:24.208657 #20892]  INFO -- : Writing /project/public/assets/....-f1a5c472b57c5e85e6cc019b2329349b.js
..........
real    2m21.684s
user    2m16.510s
sys 0m3.309s

Secon run:

>time rake RAILS_ENV=production assets:precompile
real    3m18.745s
user    3m16.378s
sys 0m2.023s

The same project on Rails 3.2:

First run:

real    1m25.114s
user    1m1.451s
sys 0m7.199s

Second run:

real    1m3.029s
user    0m42.175s
sys 0m5.853s

Library in `vendor/assets` is found nicely but in dev mode it require it by relative path

I have vendor/assets tree like

vendor/assets/
|-- angular-bindonce
|   |-- bindonce.js
|   |-- bower.json
|   `-- README.md
|-- Heyoffline
|   |-- bower.json
|   |-- heyoffline.coffee
|   |-- heyoffline.js
|   `-- README.md
`-- moment
    |-- bower.json
    |-- CONTRIBUTING.md
    |-- ender.js
    |-- grunt.js
    |-- lang
    |-- LICENSE
    |-- min
    |-- moment.js
    |-- package.js
    |-- package.json
    |-- readme.md
    |-- tasks
    `-- test

And when I add //= require bindonce Sprockets do not complain, find path but when I run my app in dev mode I see:

<script src="/assets/../angular-bindonce/bindonce.js?body=1" type="text/javascript"></script>

instead

<script src="/assets/bindonce.js?body=1" type="text/javascript"></script>

loading assets via mountable engine in rails 4

routes.rb

Dummy::Application.routes.draw do
  mount Teabag::Engine => "/teabag"
end

When you attempt to load an asset from within this engine, the mounted path is prefixed before assets.. so /teabag/assets/teabag-jasmine.js, but this file isn't served at that path -- it's still at /assets/teabag-jasmine.js

What are the plans with this? I totally understand having the assets from an engine served from a different path (and agree), so is there something I'm missing in getting that to work?

Last sprockets changes

After discussing on this PR #4 I've started to work on integration last sprockets changes to sprockets-rails and I have a question. Do you know will it rails/rails#5379 be merged to rails/master? Because now sprockets only have a task for generation digest assets and we need workaround it. I've a bit adapted sprockets rake task now but work is going on.

javascript_include_tag/stylesheet_include_tag with :debug => false not working

The following calls:

javascript_include_tag "<some-js>", :debug => false
stylesheet_include_tag "<some-css>", :debug => false

are not working in development mode in Sprockets 2.0 and Rails 4 beta 2.

In development mode, config.assets.debug = true is set globally. But if we specify :debug => false for a specific javascript_include_tag or stylesheet_include_tag - it should override the global option, right? But its not, the global option is always taking precedence, and the per-tag debug option is not working.

Detailed Stackoverflow Issue Thread and probable solution

Support for virtual assets

Hi folks,

Just wanted to know if there are any plans on implementing something like virtual assets – the assets which do not have a representation on the file system. As an example, a white-labeled website could register a virtual asset named styles.css and provide a generator which would be able to yield the contents of the styles.css file based on some iternal settings (i.e. user's session settings). Sprockets then could fetch the content via that generator (expanding requires, doing postprocessing etc) and cache the result (assuming the generator would provide some kind of signature so that it won't be needed to re-compute the result every time).

I have been looking through the source checking if it will be easy to add the support for this, but found that the current code is very heavily tighted to the real file sitting on the FS, thus rendering this feature quite tricky to add.

P.S. Thank you very much for this brilliant lib 👍

Issues with assets in Rails 4

Hi,

I'm having a bunch of issues that I believe to be sprockets related while playing around with the release candidate for Rails 4.

A lot of my images aren't working via image_tag and such anymore in production mode. I've tried precompiling assets:

[ctide@Chriss-MacBook-Pro-3 /development/exposure/app/assets/images] [rails4]:~$ RAILS_ENV=production rake assets:precompile
(in /development/exposure)
I, [2013-05-02T10:56:30.907298 #80461]  INFO -- : Writing /development/exposure/public/assets/bottom-background-18fb50ce0a481e1c4e52a69e584253d3.png
I, [2013-05-02T10:56:30.910107 #80461]  INFO -- : Writing /development/exposure/public/assets/bottom-slide-521d673020f2aeedd95dbb140f3ffd13.png
I, [2013-05-02T10:56:30.914228 #80461]  INFO -- : Writing /development/exposure/public/assets/chute-logo-42e4bac6847ec3a216a54f88c56708f5.png
I, [2013-05-02T10:56:30.916652 #80461]  INFO -- : Writing /development/exposure/public/assets/chute-slide-bg-34239d21c663caf5f6f22f2dd9444e0b.png
I, [2013-05-02T10:56:30.919520 #80461]  INFO -- : Writing /development/exposure/public/assets/exposure-logo-3fdd08002cca9821abf2885c84cd7688.png
I, [2013-05-02T10:56:30.922977 #80461]  INFO -- : Writing /development/exposure/public/assets/exposure-slide-bg-ee5b8b9c8947ed4df766bd009da8a2a8.png
I, [2013-05-02T10:56:30.925359 #80461]  INFO -- : Writing /development/exposure/public/assets/exposure-slide-4ce51514f22f3bf3646fce5ac9def2d7.png
I, [2013-05-02T10:56:30.928099 #80461]  INFO -- : Writing /development/exposure/public/assets/exposure-5f3756074ab04ac8bdc667958c0f05eb.png
I, [2013-05-02T10:56:30.930500 #80461]  INFO -- : Writing /development/exposure/public/assets/faq-button-d6a0256fdcebdd17a458eec1e1291c41.png
I, [2013-05-02T10:56:30.932828 #80461]  INFO -- : Writing /development/exposure/public/assets/film-slide-275cefc7c450dc8f2a5d2bbc0a413874.png
I, [2013-05-02T10:56:30.935306 #80461]  INFO -- : Writing /development/exposure/public/assets/instagram-icon-184500834f87a813c2c1ac5c25965bb9.png
I, [2013-05-02T10:56:30.938413 #80461]  INFO -- : Writing /development/exposure/public/assets/other-instagram-icon-70aa2eddc860a2eb24c6eddac091432a.png
I, [2013-05-02T10:56:30.941861 #80461]  INFO -- : Writing /development/exposure/public/assets/powered_by_chute-cec5a6e51101f4afbe351016138ca4db.png
I, [2013-05-02T10:56:30.946267 #80461]  INFO -- : Writing /development/exposure/public/assets/sign_in_with_instagram-1bd8d00d3bf0f0a3aae937cff338db92.png
I, [2013-05-02T10:56:30.954109 #80461]  INFO -- : Writing /development/exposure/public/assets/top-background-5ac5cafa2ed51426564e04b05ca8fa7e.png

This seems to all work fine, but: image_tag will generate links like this:

/images/exposure.png

Which don't seem to work no matter where I put that image. Tried putting it in /app/assets/images and /public/assets/images. Everything works totally fine in development mode, but I have the same problems with Heroku as I do with local production mode (unsurprising.)

Not realy sure where to begin debugging this, or what to change to try and make things function.

My relevant production.rb settings:

config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true 
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false 
# Generate digests for assets URLs
config.assets.digest = true 
config.assets.enabled = true

Any suggestions?

CSS Unusable now

Can no longer use plain old css if images are used. You either have to use sass or css.erb. Would have been simpler and given easier compatibility with dropin css like bootstrap to automatically interpret plain css url() strings and correctly adjust the relative base paths and cache digest names. Is there a particular reason this route was not used instead?

Want to ask you about assets.enabled

Would it be good if we get rid of assets.enabled option?

If you don't want to generate app with sprockets you can run rails new appname --skip-sprockets and we can just don't require "sprockets/rails/railtie". If you generate app with sprockets and you don't want to use them, you can do the same thing. And the same way you use when you don't want to use an action_mailer and the other components.

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.