Created
June 19, 2015 22:27
-
-
Save rrotter/69d885eb45ffe2f0f4ff to your computer and use it in GitHub Desktop.
Add github-markdown support to Tilt (and thus Sinatra and others).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# set :gfm => true to enable GitHub Flavored Markdown mode | |
require 'tilt/template' | |
require 'github/markdown' | |
module Tilt | |
class GitHubTemplate < Template | |
self.default_mime_type = 'text/html' | |
def prepare | |
@engine = nil | |
if options[:gfm] | |
@output = GitHub::Markdown.render_gfm(data) | |
else | |
@output = GitHub::Markdown.render(data) | |
end | |
end | |
def evaluate(scope, locals, &block) | |
@output ||= @engine.to_html | |
end | |
def allows_script? | |
false | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'github/markdown' | |
require './github-markdown' | |
module Tilt | |
register_lazy :GitHubTemplate, './github-markdown', 'markdown', 'mkd', 'md' | |
end | |
#... | |
get '/readme' do | |
markdown :README | |
end | |
get '/readme/gfm' do | |
markdown :README, :gfm => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment