pax_global_header 0000666 0000000 0000000 00000000064 12556401215 0014513 g ustar 00root root 0000000 0000000 52 comment=b7f7c973d24a1c64618acc68171dd35d576b487b markerb-1.1.0/ 0000775 0000000 0000000 00000000000 12556401215 0013135 5 ustar 00root root 0000000 0000000 markerb-1.1.0/.gitignore 0000664 0000000 0000000 00000000020 12556401215 0015115 0 ustar 00root root 0000000 0000000 .bundle test/tmp markerb-1.1.0/.travis.yml 0000664 0000000 0000000 00000001124 12556401215 0015244 0 ustar 00root root 0000000 0000000 language: ruby before_install: - gem install bundler -v '>= 1.5.1' rvm: - 1.9.3 - 2.0.0 - 2.1 - 2.2 gemfile: - Gemfile - gemfiles/Gemfile-rails.3.2.x - gemfiles/Gemfile-rails.4.0.x - gemfiles/Gemfile-rails.4.1.x matrix: exclude: - rvm: 2.2 gemfile: gemfiles/Gemfile-rails.3.2.x notifications: email: false campfire: on_success: change on_failure: always rooms: - secure: "CDywaygYdWUAzxz08vXrUIOwRnuW/0B8A4VArgp+1z21fi1rWWCKrV6oqQW72Kbv4KkldkWLMMNBS7RY/aPehVWb/4xwQ91wF9vFTUljjn/fuwqN335ozHXFQOVWKCYVIukcRIbAsZvwgPbB/hBKIDasad+ucyangbWcvhBXreo=" markerb-1.1.0/CHANGELOG.md 0000664 0000000 0000000 00000000760 12556401215 0014751 0 ustar 00root root 0000000 0000000 ## 1.1.0 ### enhancements * Add support for Rails 4.2 * Rails 4.2 generates a generic layout for mailers, and so do Markerb now. * Support Kramdown as a different option to parse markdown, which has better JRuby support. Now you need to add either `redcarpet` or `kramdown` to your Gemfile, as `markerb` does not have `redcarpet` as a dependency anymore. ## 1.0.2 ### enhancements * Add support for Rails 4.0/4.1 * Drop support for Rails 3.0/3.1 and Ruby 1.8, keep support for Rails 3.2 markerb-1.1.0/Gemfile 0000664 0000000 0000000 00000000100 12556401215 0014417 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org' gemspec gem 'rails', '~> 4.2.0' markerb-1.1.0/Gemfile.lock 0000664 0000000 0000000 00000005106 12556401215 0015361 0 ustar 00root root 0000000 0000000 PATH remote: . specs: markerb (1.1.0) GEM remote: https://rubygems.org/ specs: actionmailer (4.2.3) actionpack (= 4.2.3) actionview (= 4.2.3) activejob (= 4.2.3) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) actionpack (4.2.3) actionview (= 4.2.3) activesupport (= 4.2.3) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) actionview (4.2.3) activesupport (= 4.2.3) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) activejob (4.2.3) activesupport (= 4.2.3) globalid (>= 0.3.0) activemodel (4.2.3) activesupport (= 4.2.3) builder (~> 3.1) activerecord (4.2.3) activemodel (= 4.2.3) activesupport (= 4.2.3) arel (~> 6.0) activesupport (4.2.3) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.2) builder (3.2.2) erubis (2.7.0) globalid (0.3.5) activesupport (>= 4.1.0) i18n (0.7.0) json (1.8.3) kramdown (1.8.0) loofah (2.0.2) nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) mime-types (2.6.1) mini_portile (0.6.2) minitest (5.7.0) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) rails (4.2.3) actionmailer (= 4.2.3) actionpack (= 4.2.3) actionview (= 4.2.3) activejob (= 4.2.3) activemodel (= 4.2.3) activerecord (= 4.2.3) activesupport (= 4.2.3) bundler (>= 1.3.0, < 2.0) railties (= 4.2.3) sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) rails-dom-testing (1.0.6) activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.2) loofah (~> 2.0) railties (4.2.3) actionpack (= 4.2.3) activesupport (= 4.2.3) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) redcarpet (3.3.2) sprockets (3.2.0) rack (~> 1.0) sprockets-rails (2.3.2) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) thor (0.19.1) thread_safe (0.3.5) tzinfo (1.2.2) thread_safe (~> 0.1) PLATFORMS ruby DEPENDENCIES kramdown markerb! rails (~> 4.2.0) redcarpet (>= 2.0) BUNDLED WITH 1.10.6 markerb-1.1.0/MIT-LICENSE 0000664 0000000 0000000 00000002105 12556401215 0014567 0 ustar 00root root 0000000 0000000 Copyright 2011-2015 Plataformatec (http://blog.plataformatec.com.br) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. markerb-1.1.0/README.md 0000664 0000000 0000000 00000003613 12556401215 0014417 0 ustar 00root root 0000000 0000000 # Markerb [](http://travis-ci.org/plataformatec/markerb) **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. The usage is quite simple. Assuming you have a notifier as below: ```ruby class Notifier < ActionMailer::Base def contact(recipient) @recipient = recipient mail(:to => @recipient, :from => "john.doe@example.com") do |format| format.text format.html end end end ``` If you create a template at `app/views/notifier/contact.markerb`: ```erb Multipart templates **rocks**, right <%= @recipient %>?! ``` 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: * 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; * The order of the parts matter. It is important for e-mail clients that you call `format.text` before you call `format.html`; * Notice you can normally use ERb inside the template. Enjoy! ## Installation Add it to your Gemfile, with either the `redcarpet` or `kramdown` parser: ```ruby gem 'markerb' gem 'redcarpet', '>= 2.0' # gem 'kramdown' ``` Run the following command to install it: ```console bundle install ``` ## Bug reports If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fixing the possible bug. We also encourage you to help even more by forking and sending us a pull request. https://github.com/plataformatec/markerb/issues ## Maintainers * José Valim (https://github.com/josevalim) ## License MIT License. Copyright 2011-2015 Plataformatec. http://plataformatec.com.br markerb-1.1.0/Rakefile 0000664 0000000 0000000 00000001077 12556401215 0014607 0 ustar 00root root 0000000 0000000 require 'bundler' Bundler::GemHelper.install_tasks require 'rake/testtask' require 'rdoc/task' desc 'Default: run unit tests.' task :default => :test desc 'Test the simple_form plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.libs << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the markerb plugin.' RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = 'Markerb' rdoc.options << '--line-numbers' rdoc.rdoc_files.include('README.md') rdoc.rdoc_files.include('lib/**/*.rb') end markerb-1.1.0/gemfiles/ 0000775 0000000 0000000 00000000000 12556401215 0014730 5 ustar 00root root 0000000 0000000 markerb-1.1.0/gemfiles/Gemfile-rails.3.2.x 0000664 0000000 0000000 00000000113 12556401215 0020075 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org' gemspec path: '..' gem 'rails', '~> 3.2.0' markerb-1.1.0/gemfiles/Gemfile-rails.4.0.x 0000664 0000000 0000000 00000000113 12556401215 0020074 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org' gemspec path: '..' gem 'rails', '~> 4.0.0' markerb-1.1.0/gemfiles/Gemfile-rails.4.1.x 0000664 0000000 0000000 00000000113 12556401215 0020075 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org' gemspec path: '..' gem 'rails', '~> 4.1.0' markerb-1.1.0/lib/ 0000775 0000000 0000000 00000000000 12556401215 0013703 5 ustar 00root root 0000000 0000000 markerb-1.1.0/lib/generators/ 0000775 0000000 0000000 00000000000 12556401215 0016054 5 ustar 00root root 0000000 0000000 markerb-1.1.0/lib/generators/markerb/ 0000775 0000000 0000000 00000000000 12556401215 0017477 5 ustar 00root root 0000000 0000000 markerb-1.1.0/lib/generators/markerb/mailer/ 0000775 0000000 0000000 00000000000 12556401215 0020750 5 ustar 00root root 0000000 0000000 markerb-1.1.0/lib/generators/markerb/mailer/mailer_generator.rb 0000664 0000000 0000000 00000000633 12556401215 0024616 0 ustar 00root root 0000000 0000000 require "rails/generators/erb/mailer/mailer_generator" module Markerb module Generators class MailerGenerator < Erb::Generators::MailerGenerator source_root File.expand_path("../templates", __FILE__) protected def format nil # Our templates have no format end def formats [format] end def handler :markerb end end end end markerb-1.1.0/lib/generators/markerb/mailer/templates/ 0000775 0000000 0000000 00000000000 12556401215 0022746 5 ustar 00root root 0000000 0000000 markerb-1.1.0/lib/generators/markerb/mailer/templates/layout.markerb 0000664 0000000 0000000 00000000016 12556401215 0025625 0 ustar 00root root 0000000 0000000 <%%= yield %> markerb-1.1.0/lib/generators/markerb/mailer/templates/view.markerb 0000664 0000000 0000000 00000000126 12556401215 0025264 0 ustar 00root root 0000000 0000000 <%= class_name %>#<%= @action %> <%%= @greeting %>, find me in app/views/<%= @path %> markerb-1.1.0/lib/markerb.rb 0000664 0000000 0000000 00000001103 12556401215 0015646 0 ustar 00root root 0000000 0000000 require "action_view" require "action_view/template" require "markerb/markdown" require "markerb/railtie" module Markerb class Handler def erb_handler @erb_handler ||= ActionView::Template.registered_template_handler(:erb) end def call(template) compiled_source = erb_handler.call(template) if template.formats.include?(:html) "Markerb::Markdown.to_html(begin;#{compiled_source};end).html_safe" else compiled_source end end end end ActionView::Template.register_template_handler :markerb, Markerb::Handler.new markerb-1.1.0/lib/markerb/ 0000775 0000000 0000000 00000000000 12556401215 0015326 5 ustar 00root root 0000000 0000000 markerb-1.1.0/lib/markerb/markdown.rb 0000664 0000000 0000000 00000001134 12556401215 0017474 0 ustar 00root root 0000000 0000000 module Markerb mattr_accessor :processing_options, :renderer @@processing_options = {} class Markdown def self.to_html(compiled_source) if defined?(Redcarpet) Markerb.renderer ||= Redcarpet::Render::HTML Redcarpet::Markdown.new(Markerb.renderer, Markerb.processing_options).render(compiled_source) elsif defined?(Kramdown) Kramdown::Document.new(compiled_source, Markerb.processing_options).to_html else raise StandardError, "Markdown processor unavailable, please add either Redcarpet or Kramdown to your project" end end end end markerb-1.1.0/lib/markerb/railtie.rb 0000664 0000000 0000000 00000000226 12556401215 0017304 0 ustar 00root root 0000000 0000000 module Markerb class Railtie < ::Rails::Railtie config.markerb = Markerb config.app_generators.mailer :template_engine => :markerb end end markerb-1.1.0/lib/markerb/version.rb 0000664 0000000 0000000 00000000047 12556401215 0017341 0 ustar 00root root 0000000 0000000 module Markerb VERSION = "1.1.0" end markerb-1.1.0/markerb.gemspec 0000664 0000000 0000000 00000001405 12556401215 0016125 0 ustar 00root root 0000000 0000000 # -*- encoding: utf-8 -*- $:.push File.expand_path('../lib', __FILE__) require 'markerb/version' Gem::Specification.new do |s| s.name = 'markerb' s.version = Markerb::VERSION.dup s.platform = Gem::Platform::RUBY s.summary = 'Multipart templates made easy with Markdown + ERb' s.email = 'contact@plataformatec.com.br' s.homepage = 'http://github.com/plataformatec/markerb' s.description = 'Multipart templates made easy with Markdown + ERb' s.authors = ['José Valim'] s.license = 'MIT' s.files = Dir['MIT-LICENSE', 'README.md', 'lib/**/*'] s.test_files = Dir['test/**/*.rb'] s.require_paths = ['lib'] s.add_development_dependency 'redcarpet', '>= 2.0' s.add_development_dependency 'kramdown' end markerb-1.1.0/test/ 0000775 0000000 0000000 00000000000 12556401215 0014114 5 ustar 00root root 0000000 0000000 markerb-1.1.0/test/generator_test.rb 0000664 0000000 0000000 00000001007 12556401215 0017464 0 ustar 00root root 0000000 0000000 require "test_helper" require "generators/markerb/mailer/mailer_generator" class GeneratorTest < Rails::Generators::TestCase tests Markerb::Generators::MailerGenerator destination File.expand_path("../tmp", __FILE__) setup :prepare_destination test "assert all views are properly created with given name" do run_generator %w(notifier foo bar baz) assert_file "app/views/notifier/foo.markerb" assert_file "app/views/notifier/bar.markerb" assert_file "app/views/notifier/baz.markerb" end end markerb-1.1.0/test/markdown_test.rb 0000664 0000000 0000000 00000002007 12556401215 0017321 0 ustar 00root root 0000000 0000000 require "test_helper" class MarkdownTest < ActiveSupport::TestCase setup do @original_redcarpet = Redcarpet @original_kramdown = Kramdown end teardown do Object.const_set(:Redcarpet, @original_redcarpet) unless defined?(Redcarpet) Object.const_set(:Kramdown, @original_kramdown) unless defined?(Kramdown) end test 'with Redcarpet markdown processor' do Object.send(:remove_const, :Kramdown) assert_equal "
Dual templates rocks!
", Markerb::Markdown.to_html("Dual templates **rocks**!").strip end test 'with Kramdown markdown processor' do Object.send(:remove_const, :Redcarpet) assert_equal "Dual templates rocks!
", Markerb::Markdown.to_html("Dual templates **rocks**!").strip end test 'when there is no known markdown processor available' do Object.send(:remove_const, :Redcarpet) Object.send(:remove_const, :Kramdown) assert_raise(StandardError) { Markerb::Markdown.to_html("Dual templates **rocks**!") } end end markerb-1.1.0/test/markerb_test.rb 0000664 0000000 0000000 00000006676 12556401215 0017142 0 ustar 00root root 0000000 0000000 require "test_helper" class Notifier < ActionMailer::Base self.view_paths = File.expand_path("../views", __FILE__) layout false def contact(recipient, format_type) @recipient = recipient mail(:to => @recipient, :from => "john.doe@example.com") do |format| format.send(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 user(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| format.text { render 'contact' } format.html { render 'contact' } end end end class TestRenderer < Redcarpet::Render::HTML attr_accessor :show_text def initialize(render_options = {}) @show_text = render_options.delete(:show_text) super(render_options) end def normal_text(text) show_text ? "TEST #{text}" : "TEST" end end 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 assert_equal "Dual templates **rocks**!", email.body.encoded.strip end test "html should be sent as html" do email = Notifier.contact("you@example.com", :html) assert_equal "text/html", email.mime_type assert_equal "Dual templates rocks!
", email.body.encoded.strip end test 'dealing with multipart e-mails' do email = Notifier.multiple_format_contact("you@example.com") assert_equal 2, email.parts.size assert_equal "multipart/alternative", email.mime_type assert_equal "text/plain", email.parts[0].mime_type assert_equal "Dual templates **rocks**!", email.parts[0].body.encoded.strip assert_equal "text/html", email.parts[1].mime_type assert_equal "Dual templates rocks!
", email.parts[1].body.encoded.strip end test "with a custom renderer" do Markerb.renderer = TestRenderer email = Notifier.contact("you@example.com", :html) assert_equal "text/html", email.mime_type assert_equal "TESTTESTTEST
", email.body.encoded.strip end test "with a custom renderer and options" do Markerb.renderer = TestRenderer.new(:show_text => true) email = Notifier.contact("you@example.com", :html) assert_equal "text/html", email.mime_type assert_equal "TEST Dual templates TEST rocksTEST !
", 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 'Hello from http://www.fcstpauli.com
', email.body.encoded.strip end test 'with partial' do email = Notifier.user(:html) assert_equal "text/html", email.mime_type assert_equal 'woot! Partial
', email.body.encoded.strip end end markerb-1.1.0/test/test_helper.rb 0000664 0000000 0000000 00000001127 12556401215 0016760 0 ustar 00root root 0000000 0000000 require "rubygems" require "bundler" Bundler.setup require "minitest/autorun" require "active_support/test_case" require "action_mailer" require "rails/railtie" require "rails/generators" require "rails/generators/test_case" require "redcarpet" require "kramdown" $:.unshift File.expand_path("../../lib", __FILE__) require "markerb" ActiveSupport::TestCase.test_order = :sorted if ActiveSupport::TestCase.respond_to? :test_order= # Avoid annoying warning from I18n. I18n.enforce_available_locales = false ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true markerb-1.1.0/test/views/ 0000775 0000000 0000000 00000000000 12556401215 0015251 5 ustar 00root root 0000000 0000000 markerb-1.1.0/test/views/notifier/ 0000775 0000000 0000000 00000000000 12556401215 0017070 5 ustar 00root root 0000000 0000000 markerb-1.1.0/test/views/notifier/_user_info.markerb 0000664 0000000 0000000 00000000022 12556401215 0022557 0 ustar 00root root 0000000 0000000 woot! **Partial** markerb-1.1.0/test/views/notifier/contact.markerb 0000664 0000000 0000000 00000000031 12556401215 0022062 0 ustar 00root root 0000000 0000000 Dual templates **rocks**! markerb-1.1.0/test/views/notifier/link.markerb 0000664 0000000 0000000 00000000043 12556401215 0021367 0 ustar 00root root 0000000 0000000 Hello from http://www.fcstpauli.com markerb-1.1.0/test/views/notifier/user.markerb 0000664 0000000 0000000 00000000046 12556401215 0021413 0 ustar 00root root 0000000 0000000 <%= render :partial => 'user_info' %>