Rake::Pipeline is a system for packaging assets for deployment to the web. It uses Rake under the hood for dependency management and updating output files based on input changes.
The easiest way to use Rake::Pipeline is via an
in the root of your project.
Assetfile looks like this:
input block defines a collection of files, and a pipeline
that transforms those files. Within each pipeline, you can specify a series
of filters to describe the transformations you'd like to apply to the
Upgrading from Previous Versions
Assetfile syntax has changed in version 0.6.0. In previous
Assetfile defined a single pipeline, and
input statements would add input files to that pipeline. After
version 0.6.0, multiple pipelines can be defined in an
input method now takes a block,
and this block defines a pipeline. This means that any
blocks or filters must be defined inside an
input block, and
no longer at the top level. For example, this:
# Prior to 0.6.0 output "public" input "assets" match "**/*.js" do concat end
would now be written as:
# After 0.6.0 output "public" input "assets" do match "**/*.js" do concat end end
A filter is a simple class that inherits from
which takes two parameters: a list of input files and the output file.
Both the input and output files areobjects. The most important methods on a are:
: the path of the file, relative to its input root
: read the contents of the file
: write a String to the file
For example, a simple concatenation filter would look like:
class ConcatFilter < :::: def generate_output(inputs, output) inputs.each do |input| output.write input.read end end end
If you had a series of input files like:
and you specified the
ConcatFilter in your
filter ConcatFilter, "application.js"
The filter would receive a single call to
an Array of s representing each of
the three files, and a
If your filter is operating on binary data, like images, rather than textual data, like source code, you can specify that in your filter:
class ConcatFilter < :::: processes_binary_files def generate_output(inputs, output) inputs.each do |input| output.write input.read end end end
This will stop `Rake::Pipeline` from trying to interpret the input files as `UTF-8`, which obviously will not work on binary data.
Rake::Pipeline comes with a built-in filter,
. Its implementation is the same as the
ConcatFilter above. Other filters that are useful for web
development like a
SassFilter are available in [rake-pipeline-web-filters](github.com/wycats/rake-pipeline-web-filters).
To start up the preview server, run rakep server. This will start up a server that automatically recompiles files for you on the fly and serves up the files you need.
This should allow you to have a single index.html file pointing at the same files in both development and production.
To compile all assets before deployment, simply run:
$ rakep build
If a filter does not specify that it processes binary files,
Rake::Pipeline will open all inputs and outputs as
This means that if you have files encoded in other encodings, like
Rake::Pipeline will raise an exception.
In this situation, you need to open the offending file in your text editor
and re-save it as
Public Release Requirement
Before publicly releasing this code, we need to properly support encodings
other than UTF-8. That means using the
instead of hardcoding to UTF-8 and providing a mechanism for specifying the
encoding of a file using a magic comment.