What is assets-include-ruby?
Assets-include is a Ruby wrapper around Assets-Include for including your assets in HTML views.
See example apps for real-world use cases.
Usage
What are the requirements?
Ruby 1.9.3+
Node.js 0.8.0+
How to install assets-include-ruby?
gem install assets_include
How to use assets-include-ruby?
With Sinatra:
require 'sinatra'
require 'assets_include'
# Adds assets.(group|list|inline) helpers
helpers AssetsInclude.helpers
get '/' do
erb :index
end
__END__
@@ layout
<html>
<head>
<%= assets.group('stylesheets/all.css') %>
</head>
<body>
<%= yield %>
<%= assets.group('javascripts/all.js') %>
</body>
</html>
@@ index
<h1>Yay, all assets are included!</h1>AssetsInclude.helpers accepts a configuration block exposing the following variables:
-
bundled- whether to serve bundled (production) or expanded (development) assets. Defaults based on ENV['RACK_ENV'] value. -
config- path to configuration file, defaults to ./assets.yml -
root- root path of all assets, defaults to ./public under config's path -
cache_boosters-truefor cache boosters (timestamp in dev mode, md5 for bundled, production files) -
asset_hosts- prefixes all paths with given asset host(s) -
loading_mode-asyncordeferfor JavaScript assets' loading mode
and adds the following methods to your views:
-
assets.group(locator)- returns a list of<script>or<link>tags for JavaScript or CSS assets respectively -
assets.inline(locator)- returns inlined JavaScript or CSS assets. In development mode works the same way as#group. -
assets.list(locator)- returns an array of assets files to easily embed them into JavaScript or data attributes. -
assets.reset- empties includer's cache
License
Assets-include-ruby is released under the MIT License.