Skip to content

Instantly share code, notes, and snippets.

@morgoth
Created July 10, 2012 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morgoth/3085346 to your computer and use it in GitHub Desktop.
Save morgoth/3085346 to your computer and use it in GitHub Desktop.
Layout filter for rake-pipeline
# Support for rendering views in layout
# Example usage in Assetfile:
#
# match "views/*.md" do
# markdown
# layout path: "app/views/layout.erb"
# concat { |input| input.sub(%r{views/}, "").sub(/\.md/, ".html") }
# end
require "rake-pipeline"
require "tilt"
module Rake
class Pipeline
module Layout
class Filter < Rake::Pipeline::Filter
attr_reader :options
def initialize(options={}, &block)
super(&block)
@options = options
end
def generate_output(inputs, output)
template = ::Tilt.new(options[:path])
inputs.each do |input|
output.write(template.render { input.read })
end
end
end
module Helpers
def layout(*args, &block)
filter(Rake::Pipeline::Layout::Filter, *args, &block)
end
end
end
end
end
Rake::Pipeline::DSL::PipelineDSL.send(:include, Rake::Pipeline::Layout::Helpers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment