cat_herder
Minimal Rails asset pipeline experiment:
Assets are fingerprinted and copied to
public/assets
in development, just likerails assets:precompile
. Thus they are served directly, without any special routes or middleware.ERB assets are evaluated; all other assets are copied verbatim.
ERB assets can call
asset_path
and all otherAssetUrlHelper
helpers.- Currently,
*_url
helpers always return a path instead of a full URL (the same as*_path
helpers). Assuming these helpers are primarily used for import statements (e.g.@import url(...)
), this shouldn't pose a problem, because the browser resolves such partial URLs to the asset host rather than the page host. The benefit of the current implementation is that it sidesteps the issue of cache invalidation whenconfig.asset_host
changes.
- Currently,
ERB assets can call
render
to render the content of another asset inline.ERB assets can call
glob
to iterate over other assets. Using a given pattern,glob
will search all load paths. With a combination ofglob
andrender
, assets can perform their own bundling.ERB assets can call
resolve
to get an absolute path to an asset file. This can be used to pass the asset to an external command, e.g.:<%# styles.css.erb %> <%= `sass #{resolve "styles.sass"}` %>
All calls to
asset_path
/compute_asset_path
,render
, andresolve
will add the resulting asset to the current asset's dependencies, so that the current asset will be recompiled when any of its dependencies are.Partial assets are prefixed with an underscore (like view partials), and are not copied to
public/assets
byrails assets:precompile
. They can be referenced using their logical path without the underscore (like view partials). This allows "private" files, such as raw input files or config files, to be placed in any of the asset load paths and be evaluated like other assets. (Calls tocompute_asset_path
that resolve to a partial asset will raise an error to prevent broken URLs.)
Installation
Add this line to your application's Gemfile:
gem "cat_herder"
And run:
$ bundle install
Then disable Sprockets, and require cat_herder in your config/application.rb
file:
require "cat_herder/railtie"
Contributing
Run bin/test
to run the tests.