allow setting of markdown engine with symbol

This commit is contained in:
Thomas Reynolds 2011-08-31 12:22:45 -07:00
parent 0df1a7cc28
commit af9e4989e3
5 changed files with 54 additions and 22 deletions

View file

@ -0,0 +1,7 @@
Feature: Markdown support
In order to test included Maruku support
Scenario: Rendering html
Given the Server is running at "test-app"
When I go to "/markdown.html"
Then I should see "<p>Hello World</p>"

View file

@ -11,6 +11,7 @@ page "/target_ignore.html", :proxy => "/should_be_ignored3.html", :ignore => tru
end
with_layout false do
page "/markdown.html"
page "/relative_image.html"
page "/inline-css.html"
page "/inline-js.html"

View file

@ -0,0 +1 @@
Hello World

View file

@ -6,23 +6,23 @@ module Middleman::CoreExtensions::FrontMatter
def registered(app)
app.extend ClassMethods
::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
::Tilt::register RedcarpetTemplate, 'markdown', 'mkd', 'md'
::Tilt::register MarukuTemplate, 'markdown', 'mkd', 'md'
::Tilt::register KramdownTemplate, 'markdown', 'mkd', 'md'
app.set :markdown_engine, MarukuTemplate
Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
Tilt::register RedcarpetTemplate, 'markdown', 'mkd', 'md'
Tilt::register MarukuTemplate, 'markdown', 'mkd', 'md'
Tilt::register KramdownTemplate, 'markdown', 'mkd', 'md'
app.set :markdown_engine_prefix, Middleman::CoreExtensions::FrontMatter
::Tilt::register RedClothTemplate, 'textile'
::Tilt.prefer(RedClothTemplate)
Tilt::register RedClothTemplate, 'textile'
Tilt.prefer(RedClothTemplate)
::Tilt::register ERBTemplate, 'erb', 'rhtml'
::Tilt.prefer(ERBTemplate)
Tilt::register ERBTemplate, 'erb', 'rhtml'
Tilt.prefer(ERBTemplate)
::Tilt::register SlimTemplate, 'slim'
::Tilt.prefer(SlimTemplate)
Tilt::register SlimTemplate, 'slim'
Tilt.prefer(SlimTemplate)
::Tilt::register HamlTemplate, 'haml'
::Tilt.prefer(HamlTemplate)
Tilt::register HamlTemplate, 'haml'
Tilt.prefer(HamlTemplate)
app.after_configuration do
app.before_processing do
@ -82,27 +82,27 @@ module Middleman::CoreExtensions::FrontMatter
end
end
class RDiscountTemplate < ::Tilt::RDiscountTemplate
class RDiscountTemplate < Tilt::RDiscountTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate
class RedcarpetTemplate < Tilt::RedcarpetTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class MarukuTemplate < ::Tilt::MarukuTemplate
class MarukuTemplate < Tilt::MarukuTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class RedClothTemplate < ::Tilt::RedClothTemplate
class RedClothTemplate < Tilt::RedClothTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class KramdownTemplate < ::Tilt::KramdownTemplate
class KramdownTemplate < Tilt::KramdownTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class ERBTemplate < ::Tilt::ERBTemplate
class ERBTemplate < Tilt::ERBTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class HamlTemplate < ::Tilt::HamlTemplate
class HamlTemplate < Tilt::HamlTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end

View file

@ -1,11 +1,34 @@
require "tilt"
module Middleman::Renderers::Markdown
class << self
def registered(app)
app.set :markdown_engine, ::Tilt::MarukuTemplate
app.extend ClassMethods
app.set :markdown_engine, :maruku
if !app.respond_to? :markdown_engine_prefix
app.set :markdown_engine_prefix, Tilt
end
app.after_configuration do
::Tilt.prefer(app.settings.markdown_engine)
engine = app.settings.markdown_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 == "rdiscount" ? "RDiscount" : engine.camelize
settings.markdown_engine_prefix.const_get("#{engine}Template")
end
end
end