Layout filter for rake-pipeline
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
# 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