2011-12-31 23:28:17 +01:00
|
|
|
# ERb renderer
|
2012-04-14 22:51:02 +02:00
|
|
|
module Middleman
|
|
|
|
module Renderers
|
|
|
|
module ERb
|
|
|
|
# Setup extension
|
|
|
|
class << self
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-04-14 22:51:02 +02:00
|
|
|
# once registered
|
|
|
|
def registered(app)
|
|
|
|
# Setup a default ERb engine
|
2012-10-14 04:54:55 +02:00
|
|
|
app.config.define_setting :erb_engine, :erb, 'The engine to use for rendering ERb templates'
|
|
|
|
app.config.define_setting :erb_engine_prefix, ::Tilt, 'The parent module for ERb template engines'
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-04-14 22:51:02 +02:00
|
|
|
app.before_configuration do
|
|
|
|
template_extensions :erb => :html
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-04-14 22:51:02 +02:00
|
|
|
# After config
|
|
|
|
app.after_configuration do
|
|
|
|
# Find the user's prefered engine
|
|
|
|
# Convert symbols to classes
|
2012-10-14 04:54:55 +02:00
|
|
|
if config[:erb_engine].is_a? Symbol
|
2012-04-14 22:51:02 +02:00
|
|
|
engine = engine.to_s
|
|
|
|
engine = engine == "erb" ? "ERB" : engine.camelize
|
2012-10-14 04:54:55 +02:00
|
|
|
config[:erb_engine] = config[:erb_engine_prefix].const_get("#{engine}Template")
|
2012-04-14 22:51:02 +02:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-04-14 22:51:02 +02:00
|
|
|
# Tell Tilt to use the preferred engine
|
2012-10-14 04:54:55 +02:00
|
|
|
::Tilt.prefer(config[:erb_engine])
|
2012-04-14 22:51:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
alias :included :registered
|
2011-10-27 18:24:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
end
|