maildown 2.0.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,6 @@ class LayoutsTest < ActionMailer::TestCase
17
17
  end
18
18
 
19
19
  def test_layout_renders_fine
20
- Maildown.enable_layouts = true
21
20
  email = UserWithLayoutMailer.welcome.deliver_now
22
21
  assert !ActionMailer::Base.deliveries.empty?
23
22
  # Test the body of the sent email contains what we expect it to
@@ -29,7 +28,5 @@ class LayoutsTest < ActionMailer::TestCase
29
28
 
30
29
  body_contents = /TEXT## Welcome!/
31
30
  assert_match body_contents, email.text_part.body.to_s
32
- ensure
33
- Maildown.enable_layouts = false
34
31
  end
35
32
  end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class TemplateHandlerTest < ActionDispatch::IntegrationTest
4
+ def test_strip_whitespace_templates
5
+ Maildown.allow_indentation = true
6
+ email = UserNoLayoutMailer.leading_whitespace.deliver_now
7
+
8
+ assert_equal 2, email.parts.size
9
+ assert_equal "multipart/alternative", email.mime_type
10
+
11
+ assert_equal "text/plain", email.text_part.mime_type
12
+ assert_equal "## Leading\n", email.text_part.body.to_s
13
+
14
+ assert_equal "text/html", email.html_part.mime_type
15
+ assert_equal %Q{<h2 id="leading">Leading</h2>\n}, email.html_part.body.to_s
16
+ ensure
17
+ Maildown.allow_indentation = false
18
+ end
19
+
20
+ test "dont whitespace templates" do
21
+ Maildown.allow_indentation = false
22
+ email = UserNoLayoutMailer.leading_whitespace_again.deliver_now
23
+
24
+ assert_equal 2, email.parts.size
25
+ assert_equal "multipart/alternative", email.mime_type
26
+
27
+ assert_equal "text/plain", email.text_part.mime_type
28
+ assert_equal " ## Leading again\n", email.text_part.body.to_s
29
+
30
+ assert_equal "text/html", email.html_part.mime_type
31
+ assert_equal "<pre><code> ## Leading again\n</code></pre>\n", email.html_part.body.to_s
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class TemplateHandlerTest < ActionDispatch::IntegrationTest
4
+ test ".md template handler" do
5
+ get "/handlers/plain_markdown"
6
+ expected = "<p>Hello</p>"
7
+ assert_match expected, response.body
8
+ end
9
+
10
+ test "dual templates" do
11
+ email = UserNoLayoutMailer.contact.deliver_now
12
+
13
+ assert_equal 2, email.parts.size
14
+ assert_equal "multipart/alternative", email.mime_type
15
+
16
+ assert_equal "text/plain", email.text_part.mime_type
17
+ assert_match "Dual templates **rock**!", email.text_part.body.to_s
18
+
19
+ assert_equal "text/html", email.html_part.mime_type
20
+ assert_match "<p>Dual templates <strong>rock</strong>!</p>", email.html_part.body.to_s
21
+ end
22
+ end
data/test/test_helper.rb CHANGED
@@ -14,61 +14,3 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
14
  # if ActiveSupport::TestCase.method_defined?(:fixture_path=)
15
15
  # ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
16
16
  # end
17
-
18
-
19
- def default_body
20
- "Hi,\n\n##\n\n\nName:\n test_to_yaml_with_time_with_zone_should_not_raise_exception\nLocation:\n https://github.com/rails/rails/blob/master/test/cases/yaml_serialization_test.rb/#L7\nName:\n test_roundtrip\nLocation:\n https://github.com/rails/rails/blob/master/test/cases/yaml_serialization_test.rb/#L20\nName:\n test_roundtrip_serialized_column\nLocation:\n https://github.com/rails/rails/blob/master/test/cases/yaml_serialization_test.rb/#L27\nName:\n test_encode_with_coder\nLocation:\n https://github.com/rails/rails/blob/master/test/cases/yaml_serialization_test.rb/#L32\nName:\n test_psych_roundtrip\nLocation:\n https://github.com/rails/rails/blob/master/test/cases/yaml_serialization_test.rb/#L39\nName:\n test_psych_roundtrip_new_object\nLocation:\n https://github.com/rails/rails/blob/master/test/cases/yaml_serialization_test.rb/#L46\n\n--\n@schneems\n"
21
- end
22
-
23
- def orig_text_response
24
- {
25
- :body => default_body,
26
- :content_type => "text/plain"
27
- }.dup
28
- end
29
-
30
- def orig_html_response
31
- {
32
- :body => default_body,
33
- :content_type => "text/html"
34
- }.dup
35
- end
36
-
37
- def md_response
38
- {
39
- :body => default_body,
40
- :content_type => "text/md"
41
- }.dup
42
- end
43
-
44
- def full_responses
45
- [orig_text_response, orig_html_response, md_response].dup
46
- end
47
-
48
- def parsed_html_response
49
- {
50
- body: Kramdown::Document.new(orig_text_response[:body]).to_html,
51
- content_type: "text/html"
52
- }
53
- end
54
-
55
- def string_to_response_array(string)
56
- [
57
- {
58
- body: string,
59
- content_type: "text/plain"
60
- }.dup,
61
- {
62
- body: string,
63
- content_type: "text/html"
64
- }.dup,
65
- {
66
- body: string,
67
- content_type: "text/md"
68
- }.dup,
69
- ]
70
- end
71
-
72
- def parses_responses
73
- [orig_text_response, parsed_html_response]
74
- end
@@ -2,19 +2,13 @@ require 'test_helper'
2
2
 
3
3
  class ExtActionMailerTest < ActiveSupport::TestCase
4
4
 
5
- test "correctly registered md mime type" do
6
- assert_equal Mime[:md], Mime::Type.lookup("text/md")
7
- assert_equal "text/md", Mime[:md].to_s
8
- end
9
-
10
- test "default types on action mailer base" do
11
- actual = ActionMailer::Base.view_context_class.default_formats
12
- assert_equal actual.include?(:md), true, "Expected #{actual.inspect} to include :md but it did not"
13
- end
14
-
15
5
  test "monkeypatch location" do
16
- monkeypatch = ActionMailer::Base.instance_method(:collect_responses)
6
+ monkeypatch = ActionMailer::Base.instance_method(:each_template)
17
7
  path = monkeypatch.source_location.first
18
8
  assert_match "maildown/ext/action_mailer.rb", path
9
+
10
+ monkeypatch = ActionView::OptimizedFileSystemResolver.instance_method(:extract_handler_and_format_and_variant)
11
+ path = monkeypatch.source_location.first
12
+ assert_match "maildown/ext/action_view.rb", path
19
13
  end
20
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maildown
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - schneems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-07 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -92,24 +92,29 @@ files:
92
92
  - Rakefile
93
93
  - lib/maildown.rb
94
94
  - lib/maildown/ext/action_mailer.rb
95
+ - lib/maildown/ext/action_view.rb
96
+ - lib/maildown/handlers/markdown.rb
95
97
  - lib/maildown/markdown_engine.rb
96
- - lib/maildown/md.rb
97
98
  - lib/maildown/version.rb
98
- - lib/tasks/maildown_tasks.rake
99
99
  - test/dummy/README.rdoc
100
100
  - test/dummy/Rakefile
101
101
  - test/dummy/app/assets/javascripts/application.js
102
102
  - test/dummy/app/assets/stylesheets/application.css
103
103
  - test/dummy/app/controllers/application_controller.rb
104
+ - test/dummy/app/controllers/handlers_controller.rb
104
105
  - test/dummy/app/helpers/application_helper.rb
105
106
  - test/dummy/app/mailers/application_mailer.rb
106
107
  - test/dummy/app/mailers/user_no_layout_mailer.rb
107
108
  - test/dummy/app/mailers/user_with_layout_mailer.rb
109
+ - test/dummy/app/views/handlers/plain_markdown.html.md
108
110
  - test/dummy/app/views/layouts/application.html.erb
109
111
  - test/dummy/app/views/layouts/mail_layout.html.erb
110
112
  - test/dummy/app/views/layouts/mail_layout.text.erb
111
- - test/dummy/app/views/user_no_layout_mailer/welcome.md.erb
112
- - test/dummy/app/views/user_with_layout_mailer/welcome.md.erb
113
+ - test/dummy/app/views/user_no_layout_mailer/contact.md.erb
114
+ - test/dummy/app/views/user_no_layout_mailer/leading_whitespace.md+erb
115
+ - test/dummy/app/views/user_no_layout_mailer/leading_whitespace_again.md+erb
116
+ - test/dummy/app/views/user_no_layout_mailer/welcome.md+erb
117
+ - test/dummy/app/views/user_with_layout_mailer/welcome.md+erb
113
118
  - test/dummy/bin/bundle
114
119
  - test/dummy/bin/rails
115
120
  - test/dummy/bin/rake
@@ -141,9 +146,10 @@ files:
141
146
  - test/dummy/test/mailers/user_no_layout_mailer_test.rb
142
147
  - test/dummy/test/mailers/user_with_layout_mailer_test.rb
143
148
  - test/integration/layouts_test.rb
149
+ - test/integration/strip_leading_whitespace_test.rb
150
+ - test/integration/template_handler_test.rb
144
151
  - test/test_helper.rb
145
152
  - test/unit/ext_action_mailer_test.rb
146
- - test/unit/maildown_test.rb
147
153
  - test/unit/markdown_engine_test.rb
148
154
  homepage: https://www.github.com/schneems/maildown
149
155
  licenses:
@@ -165,23 +171,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
171
  version: '0'
166
172
  requirements: []
167
173
  rubyforge_project:
168
- rubygems_version: 2.7.3
174
+ rubygems_version: 2.7.6
169
175
  signing_key:
170
176
  specification_version: 4
171
177
  summary: Markdown in your mailbox
172
178
  test_files:
173
179
  - test/unit/ext_action_mailer_test.rb
174
- - test/unit/maildown_test.rb
175
180
  - test/unit/markdown_engine_test.rb
176
181
  - test/dummy/app/mailers/user_with_layout_mailer.rb
177
182
  - test/dummy/app/mailers/user_no_layout_mailer.rb
178
183
  - test/dummy/app/mailers/application_mailer.rb
179
184
  - test/dummy/app/controllers/application_controller.rb
180
- - test/dummy/app/views/user_with_layout_mailer/welcome.md.erb
181
- - test/dummy/app/views/user_no_layout_mailer/welcome.md.erb
185
+ - test/dummy/app/controllers/handlers_controller.rb
186
+ - test/dummy/app/views/user_with_layout_mailer/welcome.md+erb
187
+ - test/dummy/app/views/user_no_layout_mailer/leading_whitespace_again.md+erb
188
+ - test/dummy/app/views/user_no_layout_mailer/contact.md.erb
189
+ - test/dummy/app/views/user_no_layout_mailer/welcome.md+erb
190
+ - test/dummy/app/views/user_no_layout_mailer/leading_whitespace.md+erb
182
191
  - test/dummy/app/views/layouts/mail_layout.html.erb
183
192
  - test/dummy/app/views/layouts/mail_layout.text.erb
184
193
  - test/dummy/app/views/layouts/application.html.erb
194
+ - test/dummy/app/views/handlers/plain_markdown.html.md
185
195
  - test/dummy/app/assets/javascripts/application.js
186
196
  - test/dummy/app/assets/stylesheets/application.css
187
197
  - test/dummy/app/helpers/application_helper.rb
@@ -217,5 +227,7 @@ test_files:
217
227
  - test/dummy/log/test.log
218
228
  - test/dummy/log/development.log
219
229
  - test/dummy/README.rdoc
230
+ - test/integration/strip_leading_whitespace_test.rb
231
+ - test/integration/template_handler_test.rb
220
232
  - test/integration/layouts_test.rb
221
233
  - test/test_helper.rb
data/lib/maildown/md.rb DELETED
@@ -1,38 +0,0 @@
1
- module Maildown
2
- class Md
3
- attr_accessor :string
4
-
5
- # responses is an array of hashes containing a body: and :content_type
6
- def initialize(responses)
7
- @responses = responses.reject {|r| r[:content_type] == Mime[:html].to_s || r[:content_type] == Mime[:text].to_s }
8
- md_response = responses.detect {|r| r[:content_type] == Mime[:md].to_s }
9
- if md_response.present?
10
- @string = md_response[:body]
11
- # Match beginning whitespace but not newline http://rubular.com/r/uCXQ58OOC8
12
- @string.gsub!(/^[^\S\n]+/, ''.freeze) if Maildown.allow_indentation
13
-
14
- @responses.delete(md_response)
15
- end
16
- end
17
-
18
- def to_text
19
- Maildown::MarkdownEngine.to_text(string)
20
- end
21
-
22
- def to_html
23
- Maildown::MarkdownEngine.to_html(string)
24
- end
25
-
26
- def to_responses
27
- [
28
- { body: to_text, content_type: "text/plain"},
29
- { body: to_html, content_type: "text/html"}
30
- ].concat(@responses)
31
- end
32
-
33
-
34
- def contains_md?
35
- string.present?
36
- end
37
- end
38
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :maildown do
3
- # # Task goes here
4
- # end
@@ -1,55 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MaildownTest < ActiveSupport::TestCase
4
- test "parse md response" do
5
- md = ::Maildown::Md.new(full_responses)
6
- assert md.contains_md?
7
- assert_equal parses_responses, md.to_responses
8
- end
9
-
10
-
11
- test "allow indentation strips leading whitespace" do
12
- begin
13
- Maildown.allow_indentation = true
14
-
15
- string = "foo"
16
-
17
- md = ::Maildown::Md.new(string_to_response_array("\n #{string}"))
18
- assert md.contains_md?
19
-
20
- expected = [{
21
- body: "\n#{string}",
22
- content_type: "text/plain"
23
- },
24
- {
25
- body: "\n<p>#{string}</p>\n",
26
- content_type: "text/html"
27
- }]
28
- assert_equal expected, md.to_responses
29
- ensure
30
- Maildown.allow_indentation = false
31
- end
32
- end
33
-
34
- test "whitespace is not stripped by default" do
35
- string = "foo"
36
-
37
- md = ::Maildown::Md.new(string_to_response_array(" #{string}"))
38
- assert md.contains_md?
39
-
40
- expected = [{
41
- body: " #{string}",
42
- content_type: "text/plain"
43
- },
44
- {
45
- body: "<pre><code>foo\n</code></pre>\n",
46
- content_type: "text/html"
47
- }]
48
- assert_equal expected, md.to_responses
49
- end
50
-
51
- test "no md in response" do
52
- md = ::Maildown::Md.new([])
53
- refute md.contains_md?
54
- end
55
- end