-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
twinturbo
committed
Oct 19, 2012
1 parent
7468c42
commit 5ce6bc0
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
You may want to do some trickery with your input files. Here is a use | ||
case: you need to sort your files in a custom way. The easiest way to do | ||
this is to insert a new pipeline into your pipeline. This pipeline must | ||
act like a filter because it will be used as such. Let's start out by | ||
describing the most basic pipeline: | ||
|
||
```ruby | ||
class PassThroughPipeline < Rake::Pipeline | ||
# this need to act like a filter | ||
attr_accessor :pipeline | ||
|
||
# simply return the original input_files | ||
def output_files | ||
input_files | ||
end | ||
|
||
# this is very imporant! define this method | ||
# to do nothing and files will not be copied | ||
# to the output directory | ||
def finalize | ||
end | ||
end | ||
``` | ||
|
||
At this point you can insert it into your pipeline: | ||
|
||
```ruby | ||
input "**/*.js" do | ||
# stick our pass through | ||
pass_through = pipeline.copy PassThroughPipeline | ||
pipeline.add_filter pass_through | ||
|
||
# now continue on with your life | ||
concat "application.js" | ||
end | ||
``` | ||
|
||
Now we can begin to do all sorts of crazyness in this pass through | ||
pipeline. You could expand directories to groups of files or you could | ||
collapse then. You could even skip files if you wanted to. Hell, you can | ||
even sort them--and that's what we're going to do. So let's get going | ||
|
||
```ruby | ||
class SortedPipeline < PassThroughPipeline | ||
def output_files | ||
super.sort do |f1, f2| | ||
# just an easy example of reverse sorting | ||
f2.fullpath <=> f1.fullpath | ||
end | ||
end | ||
end | ||
``` | ||
|
||
Now add it to the pipeline: | ||
|
||
```ruby | ||
input "**/*.js" do | ||
# stick our pass through | ||
pass_through = pipeline.copy SortedPipeline | ||
pipeline.add_filter pass_through | ||
|
||
# now continue on with your life | ||
concat "application.js" | ||
end | ||
``` | ||
|
||
Voila! You can sort stuff. Let your mind run wild with possibilities! |