From af9e4989e3e65e694a787ff5ef2227efdb19350b Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Wed, 31 Aug 2011 12:22:45 -0700 Subject: [PATCH] allow setting of markdown engine with symbol --- features/markdown.feature | 7 ++++ fixtures/test-app/config.rb | 1 + .../test-app/source/markdown.html.markdown | 1 + lib/middleman/core_extensions/front_matter.rb | 40 +++++++++---------- lib/middleman/renderers/markdown.rb | 27 ++++++++++++- 5 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 features/markdown.feature create mode 100644 fixtures/test-app/source/markdown.html.markdown diff --git a/features/markdown.feature b/features/markdown.feature new file mode 100644 index 00000000..ee11a120 --- /dev/null +++ b/features/markdown.feature @@ -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 "

Hello World

" \ No newline at end of file diff --git a/fixtures/test-app/config.rb b/fixtures/test-app/config.rb index 07134cb1..f3e08569 100644 --- a/fixtures/test-app/config.rb +++ b/fixtures/test-app/config.rb @@ -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" diff --git a/fixtures/test-app/source/markdown.html.markdown b/fixtures/test-app/source/markdown.html.markdown new file mode 100644 index 00000000..5e1c309d --- /dev/null +++ b/fixtures/test-app/source/markdown.html.markdown @@ -0,0 +1 @@ +Hello World \ No newline at end of file diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index b283c621..fb4653a0 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -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 diff --git a/lib/middleman/renderers/markdown.rb b/lib/middleman/renderers/markdown.rb index a3046c88..6ebece27 100644 --- a/lib/middleman/renderers/markdown.rb +++ b/lib/middleman/renderers/markdown.rb @@ -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 \ No newline at end of file