markerb 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -3
- data/MIT-LICENSE +1 -1
- data/README.md +49 -0
- data/lib/markerb.rb +2 -2
- data/lib/markerb/version.rb +1 -1
- data/markerb.gemspec +2 -2
- data/test/markerb_test.rb +25 -5
- metadata +30 -53
- data/README.rdoc +0 -33
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
markerb (
|
5
|
-
redcarpet
|
4
|
+
markerb (1.0.0)
|
5
|
+
redcarpet (>= 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
rake (>= 0.8.7)
|
66
66
|
thor (~> 0.14.4)
|
67
67
|
rake (0.8.7)
|
68
|
-
redcarpet (1.
|
68
|
+
redcarpet (2.1.0)
|
69
69
|
thor (0.14.6)
|
70
70
|
treetop (1.4.9)
|
71
71
|
polyglot (>= 0.3.1)
|
data/MIT-LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Markerb
|
2
|
+
|
3
|
+
**Markerb** allows you to render multipart e-mails from a single template. The template is written in Markdown, which is delivered as a text part, but also rendered and delivered as an HTML part.
|
4
|
+
|
5
|
+
The usage is quite simple. Assuming you have a notifier as below:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class Notifier < ActionMailer::Base
|
9
|
+
def contact(recipient)
|
10
|
+
@recipient = recipient
|
11
|
+
mail(:to => @recipient, :from => "john.doe@example.com") do |format|
|
12
|
+
format.text
|
13
|
+
format.html
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
If you create a template at `app/views/notifier/contact.markerb`:
|
20
|
+
|
21
|
+
```erb
|
22
|
+
Multipart templates **rocks**, right <%= @recipient %>?!
|
23
|
+
```
|
24
|
+
|
25
|
+
It will generate two parts, one in text and another in html when delivered. Before we finish, here are a few things you might need to know:
|
26
|
+
|
27
|
+
* The `contact.markerb` template should not have a format in its name. Adding a format would make it unavailable to be rendered in different formats;
|
28
|
+
|
29
|
+
* The order of the parts matter. It is important for e-mail clients that you call `format.text` before you call `format.html`;
|
30
|
+
|
31
|
+
* Notice you can normally use ERb inside the template.
|
32
|
+
|
33
|
+
Enjoy!
|
34
|
+
|
35
|
+
## Bug reports
|
36
|
+
|
37
|
+
If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as
|
38
|
+
possible to help us fixing the possible bug. We also encourage you to help even more by forking and
|
39
|
+
sending us a pull request.
|
40
|
+
|
41
|
+
https://github.com/plataformatec/markerb/issues
|
42
|
+
|
43
|
+
## Maintainers
|
44
|
+
|
45
|
+
* José Valim (https://github.com/josevalim)
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
MIT License. Copyright 2012 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
data/lib/markerb.rb
CHANGED
@@ -14,7 +14,7 @@ module Markerb
|
|
14
14
|
def call(template)
|
15
15
|
compiled_source = erb_handler.call(template)
|
16
16
|
if template.formats.include?(:html)
|
17
|
-
"Redcarpet.new(begin;#{compiled_source};end
|
17
|
+
"Redcarpet::Markdown.new(Redcarpet::Render::HTML, *Markerb.processing_options).render(begin;#{compiled_source};end)"
|
18
18
|
else
|
19
19
|
compiled_source
|
20
20
|
end
|
@@ -22,4 +22,4 @@ module Markerb
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
ActionView::Template.register_template_handler :markerb, Markerb::Handler.new
|
25
|
+
ActionView::Template.register_template_handler :markerb, Markerb::Handler.new
|
data/lib/markerb/version.rb
CHANGED
data/markerb.gemspec
CHANGED
data/test/markerb_test.rb
CHANGED
@@ -5,18 +5,38 @@ class Notifier < ActionMailer::Base
|
|
5
5
|
|
6
6
|
layout false
|
7
7
|
|
8
|
-
def contact(recipient)
|
8
|
+
def contact(recipient, format_type)
|
9
9
|
@recipient = recipient
|
10
10
|
mail(:to => @recipient, :from => "john.doe@example.com") do |format|
|
11
|
-
format.
|
12
|
-
|
11
|
+
format.send(format_type)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def multiple_format_contact(recipient)
|
16
|
+
@recipient = recipient
|
17
|
+
mail(:to => @recipient, :from => "john.doe@example.com", :template => "contact") do |format|
|
18
|
+
format.text { render 'contact' }
|
19
|
+
format.html { render 'contact' }
|
13
20
|
end
|
14
21
|
end
|
15
22
|
end
|
16
23
|
|
17
24
|
class MarkerbTest < ActiveSupport::TestCase
|
18
|
-
|
19
|
-
|
25
|
+
|
26
|
+
test "plain text should be sent as a plain text" do
|
27
|
+
email = Notifier.contact("you@example.com", :text)
|
28
|
+
assert_equal "text/plain", email.mime_type
|
29
|
+
assert_equal "Dual templates **rocks**!", email.body.encoded.strip
|
30
|
+
end
|
31
|
+
|
32
|
+
test "html should be sent as html" do
|
33
|
+
email = Notifier.contact("you@example.com", :html)
|
34
|
+
assert_equal "text/html", email.mime_type
|
35
|
+
assert_equal "<p>Dual templates <strong>rocks</strong>!</p>", email.body.encoded.strip
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'dealing with multipart e-mails' do
|
39
|
+
email = Notifier.multiple_format_contact("you@example.com")
|
20
40
|
assert_equal 2, email.parts.size
|
21
41
|
assert_equal "multipart/alternative", email.mime_type
|
22
42
|
assert_equal "text/plain", email.parts[0].mime_type
|
metadata
CHANGED
@@ -1,51 +1,38 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: markerb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- José Valim
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-02-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: redcarpet
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2152594060 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.0'
|
33
22
|
type: :runtime
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152594060
|
35
25
|
description: Multipart templates made easy with Markdown + ERb
|
36
26
|
email: contact@plataformatec.com.br
|
37
27
|
executables: []
|
38
|
-
|
39
28
|
extensions: []
|
40
|
-
|
41
29
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
30
|
+
files:
|
44
31
|
- .gitignore
|
45
32
|
- Gemfile
|
46
33
|
- Gemfile.lock
|
47
34
|
- MIT-LICENSE
|
48
|
-
- README.
|
35
|
+
- README.md
|
49
36
|
- Rakefile
|
50
37
|
- lib/generators/markerb/mailer/mailer_generator.rb
|
51
38
|
- lib/generators/markerb/mailer/templates/view.markerb
|
@@ -57,41 +44,31 @@ files:
|
|
57
44
|
- test/markerb_test.rb
|
58
45
|
- test/test_helper.rb
|
59
46
|
- test/views/notifier/contact.markerb
|
60
|
-
has_rdoc: true
|
61
47
|
homepage: http://github.com/plataformatec/markerb
|
62
48
|
licenses: []
|
63
|
-
|
64
49
|
post_install_message:
|
65
50
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
51
|
+
require_paths:
|
68
52
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
54
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
60
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
87
65
|
requirements: []
|
88
|
-
|
89
66
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.8.15
|
91
68
|
signing_key:
|
92
69
|
specification_version: 3
|
93
70
|
summary: Multipart templates made easy with Markdown + ERb
|
94
|
-
test_files:
|
71
|
+
test_files:
|
95
72
|
- test/generator_test.rb
|
96
73
|
- test/markerb_test.rb
|
97
74
|
- test/test_helper.rb
|
data/README.rdoc
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
= Markerb
|
2
|
-
|
3
|
-
Markerb allows you to render multipart e-mails from a single template. The template is written in Markdown, which is delivered as a text part, but also rendered and delivered as an HTML part.
|
4
|
-
|
5
|
-
The usage is quite simple. Assuming you have a notifier as below:
|
6
|
-
|
7
|
-
class Notifier < ActionMailer::Base
|
8
|
-
def contact(recipient)
|
9
|
-
@recipient = recipient
|
10
|
-
mail(:to => @recipient, :from => "john.doe@example.com") do |format|
|
11
|
-
format.text
|
12
|
-
format.html
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
If you create a template at +app/views/notifier/contact.markerb+:
|
18
|
-
|
19
|
-
Multipart templates **rocks**, right <%= @recipient %>?!
|
20
|
-
|
21
|
-
It will generate two parts, one in text and another in html when delivered. Before you go, here are a few things you might need to know:
|
22
|
-
|
23
|
-
* The "contact.markerb" template should not have a format in its name. Adding a format would make it unavailable to be rendered in different formats;
|
24
|
-
|
25
|
-
* The order of the parts matter. It is important you call +format.text+ before you call +format.html+;
|
26
|
-
|
27
|
-
* Notice you can normally use ERb inside the template.
|
28
|
-
|
29
|
-
Enjoy!
|
30
|
-
|
31
|
-
== Copyright and License
|
32
|
-
|
33
|
-
Created by the fine folks at PlataformaTec under the MIT-LICENSE (please check MIT-LICENSE file for more info).
|