diff --git a/README.md b/README.md index b5009c13..ba4d23c5 100644 --- a/README.md +++ b/README.md @@ -21,30 +21,31 @@ template engines included in the distribution. Support for these template engines is included with the package: - ENGINE FILE EXTENSIONS REQUIRED LIBRARIES - -------------------------- ---------------------- ---------------------------- - ERB .erb, .rhtml none (included ruby stdlib) - Interpolated String .str none (included ruby core) - Erubis .erb, .rhtml, .erubis erubis - Haml .haml haml - Sass .sass haml (< 3.1) or sass (>= 3.1) - Scss .scss haml (< 3.1) or sass (>= 3.1) - Less CSS .less less - Builder .builder builder - Liquid .liquid liquid - RDiscount .markdown, .mkd, .md rdiscount - Redcarpet .markdown, .mkd, .md redcarpet - BlueCloth .markdown, .mkd, .md bluecloth - Kramdown .markdown, .mkd, .md kramdown - Maruku .markdown, .mkd, .md maruku - RedCloth .textile redcloth - RDoc .rdoc rdoc - Radius .radius radius - Markaby .mab markaby - Nokogiri .nokogiri nokogiri - CoffeeScript .coffee coffee-script (+ javascript) - Creole (Wiki markup) .creole creole - Yajl .yajl yajl-ruby + ENGINE FILE EXTENSIONS REQUIRED LIBRARIES + -------------------------- ----------------------- ---------------------------- + ERB .erb, .rhtml none (included ruby stdlib) + Interpolated String .str none (included ruby core) + Erubis .erb, .rhtml, .erubis erubis + Haml .haml haml + Sass .sass haml (< 3.1) or sass (>= 3.1) + Scss .scss haml (< 3.1) or sass (>= 3.1) + Less CSS .less less + Builder .builder builder + Liquid .liquid liquid + RDiscount .markdown, .mkd, .md rdiscount + Redcarpet .markdown, .mkd, .md redcarpet + BlueCloth .markdown, .mkd, .md bluecloth + Kramdown .markdown, .mkd, .md kramdown + Maruku .markdown, .mkd, .md maruku + RedCloth .textile redcloth + RDoc .rdoc rdoc + Radius .radius radius + Markaby .mab markaby + Nokogiri .nokogiri nokogiri + CoffeeScript .coffee coffee-script (+ javascript) + Creole (Wiki markup) .wiki, .creole creole + WikiCloth (Wiki markup) .wiki, .mediawiki, .mw wikicloth + Yajl .yajl yajl-ruby These template engines ship with their own Tilt integration: diff --git a/lib/tilt.rb b/lib/tilt.rb index d69643aa..6d635748 100644 --- a/lib/tilt.rb +++ b/lib/tilt.rb @@ -181,8 +181,9 @@ def clear require 'tilt/rdoc' register RDocTemplate, 'rdoc' - require 'tilt/creole' - register CreoleTemplate, 'creole' + require 'tilt/wiki' + register CreoleTemplate, 'wiki', 'creole' + register WikiClothTemplate, 'wiki', 'mediawiki', 'mw' require 'tilt/yajl' register YajlTemplate, 'yajl' diff --git a/lib/tilt/creole.rb b/lib/tilt/wiki.rb similarity index 53% rename from lib/tilt/creole.rb rename to lib/tilt/wiki.rb index 713a208e..dd1f2852 100644 --- a/lib/tilt/creole.rb +++ b/lib/tilt/wiki.rb @@ -25,4 +25,26 @@ def evaluate(scope, locals, &block) @output ||= @engine.to_html end end + + # WikiCloth implementation. See: + # http://redcloth.org/ + class WikiClothTemplate < Template + def self.engine_initialized? + defined? ::WikiCloth::Parser + end + + def initialize_engine + require_template_library 'wikicloth' + end + + def prepare + @parser = options.delete(:parser) || WikiCloth::Parser + @engine = @parser.new options.merge(:data => data) + @output = nil + end + + def evaluate(scope, locals, &block) + @output ||= @engine.to_html + end + end end diff --git a/test/tilt_creoletemplate_test.rb b/test/tilt_creoletemplate_test.rb index 1ba3ecab..5ef900fd 100644 --- a/test/tilt_creoletemplate_test.rb +++ b/test/tilt_creoletemplate_test.rb @@ -9,6 +9,10 @@ class CreoleTemplateTest < Test::Unit::TestCase assert_equal Tilt::CreoleTemplate, Tilt['test.creole'] end + test "registered for '.wiki' files" do + assert Tilt.mappings['wiki'].include?(Tilt::CreoleTemplate) + end + test "compiles and evaluates the template on #render" do template = Tilt::CreoleTemplate.new { |t| "= Hello World!" } assert_equal "

Hello World!

", template.render diff --git a/test/tilt_wikiclothtemplate_test.rb b/test/tilt_wikiclothtemplate_test.rb new file mode 100644 index 00000000..f9c6e6f0 --- /dev/null +++ b/test/tilt_wikiclothtemplate_test.rb @@ -0,0 +1,32 @@ +require 'contest' +require 'tilt' + +begin + require 'wikicloth' + + class WikiClothTemplateTest < Test::Unit::TestCase + test "is registered for '.mediawiki' files" do + assert_equal Tilt::WikiClothTemplate, Tilt['test.mediawiki'] + end + + test "is registered for '.mw' files" do + assert_equal Tilt::WikiClothTemplate, Tilt['test.mw'] + end + + test "is registered for '.wiki' files" do + assert_equal Tilt::WikiClothTemplate, Tilt['test.wiki'] + end + + test "compiles and evaluates the template on #render" do + template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" } + assert_match /

.*Hello World!.*<\/h1>/, template.render + end + + test "can be rendered more than once" do + template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" } + 3.times { assert_match /

.*Hello World!.*<\/h1>/, template.render } + end + end +rescue LoadError => boom + warn "Tilt::WikiClothTemplate (disabled)\n" +end