SmartAssetHelper
SmartAssetHelper is a utility that add a number of conveniences for dealing with CSS and Javascript files. The library sprung out of a distain for how “dirty” my CSS and Javascript organization would get over time. SmartAssetHelper introduces an opinionated way to organize CSS and Javascript files and also contains a number of convenient helper methods to make your life easier.
Example
SmartAssetHelper introduces two new methods for including CSS and Javascript within your <head> tag:
# app/views/layouts/application.html.erb
<html>
<head>
<%= include_stylesheets 'global' %>
<%= include_javascript :default %>
</head>
<body>
<%= yield %>
</body>
</html>
The include_stylesheets
and include_javascript
helper methods will include asset files that have been ‘required’ by helper methods:
# app/views/users/new.html.erb
<% require_stylesheet 'form %>
<% require_javascript 'validations' %>
...
When the include_stylesheets
and include_javascript
methods are passed the :auto => true
parameter, they will automatically include assets based on the request parameters (if the files exists). For example, a request to UsersController#index
will automatically include stylesheets at /stylesheets/users.css
and /stylesheets/users/index.css
, if they exsist.
Copyright © 2009 (Jeremy Boles), released under the MIT license