Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Kramdown support (thanks Postmodern)

  • Loading branch information...
commit d763bfad87bd98baaf80375e850c0c0a68d9678b 1 parent ddff065
@judofyr judofyr authored
Showing with 64 additions and 0 deletions.
  1. +1 −0  lib/tilt.rb
  2. +21 −0 lib/tilt/markdown.rb
  3. +42 −0 test/tilt_kramdown_test.rb
View
1  lib/tilt.rb
@@ -477,6 +477,7 @@ def precompiled(locals)
require 'tilt/markdown'
register BlueClothTemplate, 'markdown', 'mkd', 'md'
register MarukuTemplate, 'markdown', 'mkd', 'md'
+ register KramdownTemplate, 'markdown', 'mkd', 'md'
register RDiscountTemplate, 'markdown', 'mkd', 'md'
require 'tilt/textile'
View
21 lib/tilt/markdown.rb
@@ -78,5 +78,26 @@ def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
end
+
+ # Kramdown Markdown implementation. See:
+ # http://kramdown.rubyforge.org/
+ class KramdownTemplate < Template
+ def self.engine_initialized?
+ defined? ::Kramdown
+ end
+
+ def initialize_engine
+ require_template_library 'kramdown'
+ end
+
+ def prepare
+ @engine = Kramdown::Document.new(data, options)
+ @output = nil
+ end
+
+ def evaluate(scope, locals, &block)
+ @output ||= @engine.to_html
+ end
+ end
end
View
42 test/tilt_kramdown_test.rb
@@ -0,0 +1,42 @@
+require 'contest'
+require 'tilt'
+
+begin
+ require 'kramdown'
+
+ class MarukuTemplateTest < Test::Unit::TestCase
+ test "registered for '.md' files" do
+ assert Tilt.mappings['md'].include?(Tilt::KramdownTemplate)
+ end
+
+ test "registered for '.mkd' files" do
+ assert Tilt.mappings['mkd'].include?(Tilt::KramdownTemplate)
+ end
+
+ test "registered for '.markdown' files" do
+ assert Tilt.mappings['markdown'].include?(Tilt::KramdownTemplate)
+ end
+
+ test "registered above MarukuTemplate" do
+ %w[md mkd markdown].each do |ext|
+ mappings = Tilt.mappings[ext]
+ kram_idx = mappings.index(Tilt::KramdownTemplate)
+ maru_idx = mappings.index(Tilt::MarukuTemplate)
+ assert kram_idx < maru_idx,
+ "#{kram_idx} should be lower than #{maru_idx}"
+ end
+ end
+
+ test "preparing and evaluating templates on #render" do
+ template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
+ assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render
+ end
+
+ test "can be rendered more than once" do
+ template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
+ 3.times { assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render }
+ end
+ end
+rescue LoadError => boom
+ warn "Tilt::MarukuTemplate (disabled)\n"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.