markerb 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markerb (0.1.0)
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.11.2)
68
+ redcarpet (2.1.0)
69
69
  thor (0.14.6)
70
70
  treetop (1.4.9)
71
71
  polyglot (>= 0.3.1)
@@ -1,4 +1,4 @@
1
- Copyright 2010 PlataformaTec (blog.plataformatec.com.br)
1
+ Copyright 2011 PlataformaTec (blog.plataformatec.com.br)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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
@@ -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, *Markerb.processing_options).to_html"
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
@@ -1,3 +1,3 @@
1
1
  module Markerb
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency "redcarpet"
21
- end
20
+ s.add_dependency "redcarpet", ">= 2.0"
21
+ end
@@ -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.text
12
- format.html
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
- test 'dual template with .merb' do
19
- email = Notifier.contact("you@example.com")
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
- hash: 27
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
- - "Jos\xC3\xA9 Valim"
7
+ authors:
8
+ - José Valim
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-26 00:00:00 +02:00
19
- default_executable:
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
- prerelease: false
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
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
33
22
  type: :runtime
34
- version_requirements: *id001
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.rdoc
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
- hash: 3
75
- segments:
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
- hash: 3
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.5.3
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
@@ -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).