Skip to content

Loading…

Fix processing_options #7

Merged
merged 3 commits into from

2 participants

@colszowka

We were trying to use the processing_options to make Redcarpet automatically link URLs, but realized that they don't work anymore. I suspect this broke at some point when changing to Redcarpet.

Made the processing options work again, including a unit test for them (and resetting config in tests to defaults after each run)

@josevalim josevalim merged commit 85a74d7 into plataformatec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 2 deletions.
  1. +2 −2 lib/markerb.rb
  2. +23 −0 test/markerb_test.rb
  3. +1 −0 test/views/notifier/link.markerb
View
4 lib/markerb.rb
@@ -4,7 +4,7 @@
module Markerb
mattr_accessor :processing_options, :renderer
- @@processing_options = []
+ @@processing_options = {}
@@renderer = Redcarpet::Render::HTML
class Handler
@@ -15,7 +15,7 @@ def erb_handler
def call(template)
compiled_source = erb_handler.call(template)
if template.formats.include?(:html)
- "Redcarpet::Markdown.new(Markerb.renderer, *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
23 test/markerb_test.rb
@@ -12,6 +12,12 @@ def contact(recipient, format_type)
end
end
+ def link(format_type)
+ mail(:to => 'foo@bar.com', :from => "john.doe@example.com") do |format|
+ format.send(format_type)
+ end
+ end
+
def multiple_format_contact(recipient)
@recipient = recipient
mail(:to => @recipient, :from => "john.doe@example.com", :template => "contact") do |format|
@@ -35,6 +41,16 @@ def normal_text(text)
class MarkerbTest < ActiveSupport::TestCase
+ setup do
+ @original_renderer = Markerb.renderer
+ @original_processing_options = Markerb.processing_options
+ end
+
+ teardown do
+ Markerb.renderer = @original_renderer
+ Markerb.processing_options = @original_processing_options
+ end
+
test "plain text should be sent as a plain text" do
email = Notifier.contact("you@example.com", :text)
assert_equal "text/plain", email.mime_type
@@ -72,4 +88,11 @@ class MarkerbTest < ActiveSupport::TestCase
assert_equal "text/html", email.mime_type
assert_equal "<p>TEST Dual templates <strong>TEST rocks</strong>TEST !</p>", email.body.encoded.strip
end
+
+ test 'with custom markdown processing options' do
+ Markerb.processing_options = {:autolink => true}
+ email = Notifier.link(:html)
+ assert_equal "text/html", email.mime_type
+ assert_equal '<p>Hello from <a href="http://www.fcstpauli.com">http://www.fcstpauli.com</a></p>', email.body.encoded.strip
+ end
end
View
1 test/views/notifier/link.markerb
@@ -0,0 +1 @@
+Hello from http://www.fcstpauli.com
Something went wrong with that request. Please try again.