Created
April 2, 2009 12:41
-
-
Save choan/89170 to your computer and use it in GitHub Desktop.
A method to define rake file tasks which depend on multiple files which are concatenated after being processed with ERB
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
module RakeExtensions | |
def concat(*args, &block) | |
t = Rake::FileTask.define_task(*args) | |
out_file = t.name | |
list = [] | |
yield list if block_given? | |
t.enhance(list) do | |
File.open(out_file, 'w+') do |f| | |
f << list.map do |item| | |
ERB.new(IO.read(File.expand_path(item)), nil, '%').result(binding) | |
end * $/ | |
end | |
end | |
end | |
end | |
# usage: | |
# concat some_file do |list| | |
# list << "header" | |
# list << "some_source_file" | |
# end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment