Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support custom renderer and render options

Make Markerb more flexible by taking advantage of Redcarpet's support
for custom renderers and render options.
  • Loading branch information...
commit 6b4371308d2f89b3fbdfac1ef3605e314a2ab211 1 parent 157e527
@stevenh512 stevenh512 authored
Showing with 29 additions and 2 deletions.
  1. +3 −2 lib/markerb.rb
  2. +26 −0 test/markerb_test.rb
View
5 lib/markerb.rb
@@ -3,8 +3,9 @@
require "markerb/railtie"
module Markerb
- mattr_accessor :processing_options
+ mattr_accessor :processing_options, :renderer
@@processing_options = []
+ @@renderer = Redcarpet::Render::HTML
class Handler
def erb_handler
@@ -14,7 +15,7 @@ def erb_handler
def call(template)
compiled_source = erb_handler.call(template)
if template.formats.include?(:html)
- "Redcarpet::Markdown.new(Redcarpet::Render::HTML, *Markerb.processing_options).render(begin;#{compiled_source};end)"
+ "Redcarpet::Markdown.new(Markerb.renderer, *Markerb.processing_options).render(begin;#{compiled_source};end)"
else
compiled_source
end
View
26 test/markerb_test.rb
@@ -21,6 +21,18 @@ def multiple_format_contact(recipient)
end
end
+class TestRenderer < Redcarpet::Render::HTML
+ attr_accessor :show_text
+ def initialize(render_options = {})
+ @show_text = render_options.delete(:show_text)
+ super(render_options)
+ end
+
+ def normal_text(text)
+ show_text ? "TEST #{text}" : "TEST"
+ end
+end
+
class MarkerbTest < ActiveSupport::TestCase
test "plain text should be sent as a plain text" do
@@ -46,4 +58,18 @@ class MarkerbTest < ActiveSupport::TestCase
assert_equal "<p>Dual templates <strong>rocks</strong>!</p>",
email.parts[1].body.encoded.strip
end
+
+ test "with a custom renderer" do
+ Markerb.renderer = TestRenderer
+ email = Notifier.contact("you@example.com", :html)
+ assert_equal "text/html", email.mime_type
+ assert_equal "<p>TEST<strong>TEST</strong>TEST</p>", email.body.encoded.strip
+ end
+
+ test "with a custom renderer and options" do
+ Markerb.renderer = TestRenderer.new(:show_text => true)
+ email = Notifier.contact("you@example.com", :html)
+ assert_equal "text/html", email.mime_type
+ assert_equal "<p>TEST Dual templates <strong>TEST rocks</strong>TEST !</p>", email.body.encoded.strip
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.