Created
July 20, 2011 11:43
-
-
Save jamesbebbington/1094811 to your computer and use it in GitHub Desktop.
Rails 3 Textile Template Handler with ERB
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
# config/initializers/template_handlers.rb | |
require 'action_view/template/handlers/textile' | |
ActionView::Template.register_template_handler :textile, ActionView::Template::Handlers::Textile.new |
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
# lib/action_view/template/handlers/textile.rb | |
# N.B. For info on rails 3 template handlers see http://pragprog.com/book/jvrails/crafting-rails-applications | |
require 'redcloth' | |
module ActionView::Template::Handlers | |
class Textile | |
class_attribute :default_format | |
self.default_format = Mime::HTML | |
def erb_handler | |
@@erb_handler ||= ActionView::Template.registered_template_handler(:erb) | |
end | |
def call(template) | |
compiled_source = erb_handler.call(template) | |
"RedCloth.new(begin;#{compiled_source};end).to_html.html_safe" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this. It was just the thing I needed to get me started on my own template handlers.