Skip to content

Commit

Permalink
Add CommonMarker support
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Apr 7, 2016
1 parent 7e28a20 commit 7db3e37
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ group :secondary do
gem 'asciidoctor', '>= 0.1.0'
gem 'liquid'
gem 'maruku'
gem 'commonmarker'

if RUBY_VERSION > '1.9.3'
gem 'prawn', '>= 2.0.0'
Expand Down
21 changes: 21 additions & 0 deletions lib/tilt/commonmarker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'tilt/template'
require 'commonmarker'

module Tilt
class CommonMarkerTemplate < Template
self.default_mime_type = 'text/html'

def prepare
@engine = nil
@output = nil
end

def evaluate(scope, locals, &block)
CommonMarker.render_html(data, :default)
end

def allows_script?
false
end
end
end
20 changes: 20 additions & 0 deletions test/tilt_commonmarkertemplate_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'test_helper'
require 'tilt'

begin
require 'tilt/commonmarker'

class CommonMarkerTemplateTest < Minitest::Test
test "preparing and evaluating templates on #render" do
template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" }
assert_equal "<h1>Hello World!</h1>\n", template.render
end

test "can be rendered more than once" do
template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" }
3.times { assert_equal "<h1>Hello World!</h1>\n", template.render }
end
end
rescue LoadError => boom
warn "Tilt::CommonMarkerTemplate (disabled)"
end

0 comments on commit 7db3e37

Please sign in to comment.