module Maildown::Handlers::Markdown
The handler is what allows Rails to render markdown
See docs/rails_template_handler.pdf for detailed tutorial on using a template handler with Rails.
The TLDR; is you define a handler that responds to `call` and then you register it against an file extension with `ActionView::Template.register_template_handler`
At runtime if Rails finds a template with the same file extension that was registered it will use you handler and pass the template into `call` to render the template
Public Class Methods
call(template, source = nil)
click to toggle source
Expected return value is valid ruby code wrapped in a string.
This handler takes care of both text and html email templates by inspectig the available `“formats”` and rendering the markdown to HTML if one of the formats is `:html`.
# File lib/maildown/handlers/markdown.rb, line 27 def self.call(template, source = nil) # The interface of template handlers changed in Rails 6.0 and the # source is passed as an argument. This check is here for compatibility # with Rails 5.0+. source ||= template.source # Match beginning whitespace but not newline # http://rubular.com/r/uCXQ58OOC8 source.gsub!(/^[^\S\n]+/, ''.freeze) if Maildown.allow_indentation if Maildown.rails_6? compiled_source = erb_handler.call(template, source) is_html = (template.format != :text) else compiled_source = erb_handler.call(template) is_html = template.formats.include?(:html) end if is_html "Maildown::MarkdownEngine.to_html(begin;#{compiled_source}; end)" else "Maildown::MarkdownEngine.to_text(begin;#{compiled_source}; end)" end end
erb_handler()
click to toggle source
# File lib/maildown/handlers/markdown.rb, line 18 def self.erb_handler @erb_handler ||= ActionView::Template.registered_template_handler(:erb) end