markerb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ test/tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.7"
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ markerb (0.1.0)
5
+ redcarpet
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.7)
12
+ actionpack (= 3.0.7)
13
+ mail (~> 2.2.15)
14
+ actionpack (3.0.7)
15
+ activemodel (= 3.0.7)
16
+ activesupport (= 3.0.7)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.5.0)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.14)
22
+ rack-test (~> 0.5.7)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.7)
25
+ activesupport (= 3.0.7)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.5.0)
28
+ activerecord (3.0.7)
29
+ activemodel (= 3.0.7)
30
+ activesupport (= 3.0.7)
31
+ arel (~> 2.0.2)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.7)
34
+ activemodel (= 3.0.7)
35
+ activesupport (= 3.0.7)
36
+ activesupport (3.0.7)
37
+ arel (2.0.9)
38
+ builder (2.1.2)
39
+ erubis (2.6.6)
40
+ abstract (>= 1.0.0)
41
+ i18n (0.5.0)
42
+ mail (2.2.18)
43
+ activesupport (>= 2.3.6)
44
+ i18n (>= 0.4.0)
45
+ mime-types (~> 1.16)
46
+ treetop (~> 1.4.8)
47
+ mime-types (1.16)
48
+ polyglot (0.3.1)
49
+ rack (1.2.2)
50
+ rack-mount (0.6.14)
51
+ rack (>= 1.0.0)
52
+ rack-test (0.5.7)
53
+ rack (>= 1.0)
54
+ rails (3.0.7)
55
+ actionmailer (= 3.0.7)
56
+ actionpack (= 3.0.7)
57
+ activerecord (= 3.0.7)
58
+ activeresource (= 3.0.7)
59
+ activesupport (= 3.0.7)
60
+ bundler (~> 1.0)
61
+ railties (= 3.0.7)
62
+ railties (3.0.7)
63
+ actionpack (= 3.0.7)
64
+ activesupport (= 3.0.7)
65
+ rake (>= 0.8.7)
66
+ thor (~> 0.14.4)
67
+ rake (0.8.7)
68
+ redcarpet (1.11.2)
69
+ thor (0.14.6)
70
+ treetop (1.4.9)
71
+ polyglot (>= 0.3.1)
72
+ tzinfo (0.3.26)
73
+
74
+ PLATFORMS
75
+ ruby
76
+
77
+ DEPENDENCIES
78
+ markerb!
79
+ rails (= 3.0.7)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2010 PlataformaTec (blog.plataformatec.com.br)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,33 @@
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).
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = false
19
+ end
20
+
21
+ task :default => :test
22
+
23
+ Rake::RDocTask.new(:rdoc) do |rdoc|
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = 'Handlers'
26
+ rdoc.options << '--line-numbers' << '--inline-source'
27
+ rdoc.rdoc_files.include('README.rdoc')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
@@ -0,0 +1,19 @@
1
+ require "rails/generators/erb/mailer/mailer_generator"
2
+
3
+ module Markerb
4
+ module Generators
5
+ class MailerGenerator < Erb::Generators::MailerGenerator
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ protected
9
+
10
+ def format
11
+ nil # Our templates have no format
12
+ end
13
+
14
+ def handler
15
+ :markerb
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= @action %>
2
+
3
+ <%%= @greeting %>, find me in app/views/<%= @path %>
data/lib/markerb.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "action_view/template"
2
+ require "redcarpet"
3
+ require "markerb/railtie"
4
+
5
+ module Markerb
6
+ mattr_accessor :processing_options
7
+ @@processing_options = []
8
+
9
+ class Handler
10
+ def erb_handler
11
+ @erb_handler ||= ActionView::Template.registered_template_handler(:erb)
12
+ end
13
+
14
+ def call(template)
15
+ compiled_source = erb_handler.call(template)
16
+ if template.formats.include?(:html)
17
+ "Redcarpet.new(begin;#{compiled_source};end, *Markerb.processing_options).to_html"
18
+ else
19
+ compiled_source
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ ActionView::Template.register_template_handler :markerb, Markerb::Handler.new
@@ -0,0 +1,6 @@
1
+ module Markerb
2
+ class Railtie < ::Rails::Railtie
3
+ config.markerb = Markerb
4
+ config.app_generators.mailer :template_engine => :markerb
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Markerb
2
+ VERSION = "0.1.0"
3
+ end
data/markerb.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "markerb/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "markerb"
7
+ s.version = Markerb::VERSION.dup
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "Multipart templates made easy with Markdown + ERb"
10
+ s.email = "contact@plataformatec.com.br"
11
+ s.homepage = "http://github.com/plataformatec/markerb"
12
+ s.description = "Multipart templates made easy with Markdown + ERb"
13
+ s.authors = ['José Valim']
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "redcarpet"
21
+ end
@@ -0,0 +1,16 @@
1
+ require "test_helper"
2
+ require "generators/markerb/mailer/mailer_generator"
3
+
4
+ class GeneratorTest < Rails::Generators::TestCase
5
+ tests Markerb::Generators::MailerGenerator
6
+ destination File.expand_path("../tmp", __FILE__)
7
+ setup :prepare_destination
8
+
9
+ test "assert all views are properly created with given name" do
10
+ run_generator %w(notifier foo bar baz)
11
+
12
+ assert_file "app/views/notifier/foo.markerb"
13
+ assert_file "app/views/notifier/bar.markerb"
14
+ assert_file "app/views/notifier/baz.markerb"
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class Notifier < ActionMailer::Base
4
+ self.view_paths = File.expand_path("../views", __FILE__)
5
+
6
+ layout false
7
+
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
+ class MarkerbTest < ActiveSupport::TestCase
18
+ test 'dual template with .merb' do
19
+ email = Notifier.contact("you@example.com")
20
+ assert_equal 2, email.parts.size
21
+ assert_equal "multipart/alternative", email.mime_type
22
+ assert_equal "text/plain", email.parts[0].mime_type
23
+ assert_equal "Dual templates **rocks**!",
24
+ email.parts[0].body.encoded.strip
25
+ assert_equal "text/html", email.parts[1].mime_type
26
+ assert_equal "<p>Dual templates <strong>rocks</strong>!</p>",
27
+ email.parts[1].body.encoded.strip
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.setup
4
+
5
+ require "test/unit"
6
+ require "active_support/test_case"
7
+
8
+ require "action_mailer"
9
+ require "rails/railtie"
10
+ require "rails/generators"
11
+ require "rails/generators/test_case"
12
+
13
+ $:.unshift File.expand_path("../../lib", __FILE__)
14
+ require "markerb"
15
+
16
+ ActionMailer::Base.delivery_method = :test
17
+ ActionMailer::Base.perform_deliveries = true
@@ -0,0 +1 @@
1
+ Dual templates **rocks**!
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markerb
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - "Jos\xC3\xA9 Valim"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-26 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: redcarpet
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Multipart templates made easy with Markdown + ERb
36
+ email: contact@plataformatec.com.br
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - MIT-LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - lib/generators/markerb/mailer/mailer_generator.rb
51
+ - lib/generators/markerb/mailer/templates/view.markerb
52
+ - lib/markerb.rb
53
+ - lib/markerb/railtie.rb
54
+ - lib/markerb/version.rb
55
+ - markerb.gemspec
56
+ - test/generator_test.rb
57
+ - test/markerb_test.rb
58
+ - test/test_helper.rb
59
+ - test/views/notifier/contact.markerb
60
+ has_rdoc: true
61
+ homepage: http://github.com/plataformatec/markerb
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ 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
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.5.3
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Multipart templates made easy with Markdown + ERb
94
+ test_files:
95
+ - test/generator_test.rb
96
+ - test/markerb_test.rb
97
+ - test/test_helper.rb
98
+ - test/views/notifier/contact.markerb