make erb engine configurable
This commit is contained in:
parent
190c563d3e
commit
80546aea75
|
@ -73,6 +73,7 @@ module Middleman
|
|||
autoload :Sass, "middleman/renderers/sass"
|
||||
autoload :Slim, "middleman/renderers/slim"
|
||||
autoload :Markdown, "middleman/renderers/markdown"
|
||||
autoload :ERb, "middleman/renderers/erb"
|
||||
autoload :CoffeeScript, "middleman/renderers/coffee_script"
|
||||
autoload :Liquid, "middleman/renderers/liquid"
|
||||
end
|
||||
|
|
|
@ -101,6 +101,9 @@ module Middleman::CoreExtensions::FrontMatter
|
|||
class ERBTemplate < ::Tilt::ERBTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
class ErubisTemplate < ::Tilt::ErubisTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
class LiquidTemplate < ::Tilt::LiquidTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
|
|
|
@ -11,6 +11,7 @@ module Middleman::CoreExtensions::Rendering
|
|||
app.register Middleman::Renderers::Haml
|
||||
app.register Middleman::Renderers::Sass
|
||||
app.register Middleman::Renderers::Markdown
|
||||
app.register Middleman::Renderers::ERb
|
||||
app.register Middleman::Renderers::CoffeeScript
|
||||
app.register Middleman::Renderers::Liquid
|
||||
end
|
||||
|
|
34
lib/middleman/renderers/erb.rb
Normal file
34
lib/middleman/renderers/erb.rb
Normal 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
|
Loading…
Reference in a new issue