Skip to content

Instantly share code, notes, and snippets.

@jamesbebbington
Created July 20, 2011 11:43
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 jamesbebbington/1094811 to your computer and use it in GitHub Desktop.
Save jamesbebbington/1094811 to your computer and use it in GitHub Desktop.
Rails 3 Textile Template Handler with ERB
# config/initializers/template_handlers.rb
require 'action_view/template/handlers/textile'
ActionView::Template.register_template_handler :textile, ActionView::Template::Handlers::Textile.new
# 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
@wadewest
Copy link

Thank you for this. It was just the thing I needed to get me started on my own template handlers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment