make erb engine configurable

This commit is contained in:
Thomas Reynolds 2011-10-27 09:24:48 -07:00
parent 190c563d3e
commit 80546aea75
4 changed files with 39 additions and 0 deletions

View file

@ -73,6 +73,7 @@ module Middleman
autoload :Sass, "middleman/renderers/sass" autoload :Sass, "middleman/renderers/sass"
autoload :Slim, "middleman/renderers/slim" autoload :Slim, "middleman/renderers/slim"
autoload :Markdown, "middleman/renderers/markdown" autoload :Markdown, "middleman/renderers/markdown"
autoload :ERb, "middleman/renderers/erb"
autoload :CoffeeScript, "middleman/renderers/coffee_script" autoload :CoffeeScript, "middleman/renderers/coffee_script"
autoload :Liquid, "middleman/renderers/liquid" autoload :Liquid, "middleman/renderers/liquid"
end end

View file

@ -101,6 +101,9 @@ module Middleman::CoreExtensions::FrontMatter
class ERBTemplate < ::Tilt::ERBTemplate class ERBTemplate < ::Tilt::ERBTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware include Middleman::CoreExtensions::FrontMatter::YamlAware
end end
class ErubisTemplate < ::Tilt::ErubisTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class LiquidTemplate < ::Tilt::LiquidTemplate class LiquidTemplate < ::Tilt::LiquidTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware include Middleman::CoreExtensions::FrontMatter::YamlAware

View file

@ -11,6 +11,7 @@ module Middleman::CoreExtensions::Rendering
app.register Middleman::Renderers::Haml app.register Middleman::Renderers::Haml
app.register Middleman::Renderers::Sass app.register Middleman::Renderers::Sass
app.register Middleman::Renderers::Markdown app.register Middleman::Renderers::Markdown
app.register Middleman::Renderers::ERb
app.register Middleman::Renderers::CoffeeScript app.register Middleman::Renderers::CoffeeScript
app.register Middleman::Renderers::Liquid app.register Middleman::Renderers::Liquid
end end

View file

@ -0,0 +1,34 @@
require "tilt"
module Middleman::Renderers::ERb
class << self
def registered(app)
app.extend ClassMethods
app.set :erb_engine, :erb
if !app.respond_to? :erb_engine_prefix
app.set :erb_engine_prefix, ::Tilt
end
app.after_configuration do
engine = app.settings.erb_engine
if engine.is_a? Symbol
engine = app.tilt_template_from_symbol(engine)
end
::Tilt.prefer(engine)
end
end
alias :included :registered
end
module ClassMethods
def tilt_template_from_symbol(engine)
engine = engine.to_s
engine = engine == "erb" ? "ERB" : engine.camelize
settings.erb_engine_prefix.const_get("#{engine}Template")
end
end
end