-
-
Save ream88/1670699 to your computer and use it in GitHub Desktop.
Markdown, Excel template handler for Rails 3.2.
This file contains hidden or 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
class ActionView::Template | |
module Handlers | |
class Excel | |
def call(template) | |
%{ | |
Tempfile.open('writeexcel').tap do |tmp| | |
WriteExcel.new(tmp.path).tap do |workbook| | |
#{template.source} | |
end.close | |
end.tap(&:rewind).read | |
} | |
end | |
end | |
end | |
register_template_handler(:writeexcel, Handlers::Excel.new) | |
end |
This file contains hidden or 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
class ActionView::Template | |
module Handlers | |
class Markdown | |
def call(template) | |
"Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(#{template.source.inspect})" | |
end | |
end | |
end | |
register_template_handler(:md, Handlers::Markdown.new) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment