Skip to content

Instantly share code, notes, and snippets.

@huyderman
Created April 27, 2012 13:55
Show Gist options
  • Save huyderman/2509486 to your computer and use it in GitHub Desktop.
Save huyderman/2509486 to your computer and use it in GitHub Desktop.
A rake snippet for auto-erb goodness
class TiltHelper
def initialize(prefix)
@prefix = prefix
end
def include(partial)
Tilt.new("#{@prefix}/#{partial}").render
end
end
rule( /\.((?!erb$)([A-Za-z0-9]))+$/ =>
[ proc { |t| "#{t}.erb" },
proc { |t| FileList.new t.pathmap("%X/*.*")}]) do |t|
puts "Processing ERB Template #{t.source} => #{t.name}"
template = Tilt.new t.source
helper = TiltHelper.new t.name.pathmap "%X"
file = File.new t.name, 'w'
file.write template.render helper
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment