Skip to content

Instantly share code, notes, and snippets.

@ream88
Forked from stephencelis/redcarpet.rb
Created January 24, 2012 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ream88/1670699 to your computer and use it in GitHub Desktop.
Save ream88/1670699 to your computer and use it in GitHub Desktop.
Markdown, Excel template handler for Rails 3.2.
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
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