pax_global_header00006660000000000000000000000064125564012150014513gustar00rootroot0000000000000052 comment=b7f7c973d24a1c64618acc68171dd35d576b487b markerb-1.1.0/000077500000000000000000000000001255640121500131355ustar00rootroot00000000000000markerb-1.1.0/.gitignore000066400000000000000000000000201255640121500151150ustar00rootroot00000000000000.bundle test/tmpmarkerb-1.1.0/.travis.yml000066400000000000000000000011241255640121500152440ustar00rootroot00000000000000language: 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.md000066400000000000000000000007601255640121500147510ustar00rootroot00000000000000## 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/Gemfile000066400000000000000000000001001255640121500144170ustar00rootroot00000000000000source 'https://rubygems.org' gemspec gem 'rails', '~> 4.2.0' markerb-1.1.0/Gemfile.lock000066400000000000000000000051061255640121500153610ustar00rootroot00000000000000PATH 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-LICENSE000066400000000000000000000021051255640121500145670ustar00rootroot00000000000000Copyright 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.md000066400000000000000000000036131255640121500144170ustar00rootroot00000000000000# Markerb [![Build Status](https://api.travis-ci.org/plataformatec/markerb.png?branch=master)](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/Rakefile000066400000000000000000000010771255640121500146070ustar00rootroot00000000000000require '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/000077500000000000000000000000001255640121500147305ustar00rootroot00000000000000markerb-1.1.0/gemfiles/Gemfile-rails.3.2.x000066400000000000000000000001131255640121500200750ustar00rootroot00000000000000source 'https://rubygems.org' gemspec path: '..' gem 'rails', '~> 3.2.0' markerb-1.1.0/gemfiles/Gemfile-rails.4.0.x000066400000000000000000000001131255640121500200740ustar00rootroot00000000000000source 'https://rubygems.org' gemspec path: '..' gem 'rails', '~> 4.0.0' markerb-1.1.0/gemfiles/Gemfile-rails.4.1.x000066400000000000000000000001131255640121500200750ustar00rootroot00000000000000source 'https://rubygems.org' gemspec path: '..' gem 'rails', '~> 4.1.0' markerb-1.1.0/lib/000077500000000000000000000000001255640121500137035ustar00rootroot00000000000000markerb-1.1.0/lib/generators/000077500000000000000000000000001255640121500160545ustar00rootroot00000000000000markerb-1.1.0/lib/generators/markerb/000077500000000000000000000000001255640121500174775ustar00rootroot00000000000000markerb-1.1.0/lib/generators/markerb/mailer/000077500000000000000000000000001255640121500207505ustar00rootroot00000000000000markerb-1.1.0/lib/generators/markerb/mailer/mailer_generator.rb000066400000000000000000000006331255640121500246160ustar00rootroot00000000000000require "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/000077500000000000000000000000001255640121500227465ustar00rootroot00000000000000markerb-1.1.0/lib/generators/markerb/mailer/templates/layout.markerb000066400000000000000000000000161255640121500256250ustar00rootroot00000000000000<%%= yield %> markerb-1.1.0/lib/generators/markerb/mailer/templates/view.markerb000066400000000000000000000001261255640121500252640ustar00rootroot00000000000000<%= class_name %>#<%= @action %> <%%= @greeting %>, find me in app/views/<%= @path %>markerb-1.1.0/lib/markerb.rb000066400000000000000000000011031255640121500156460ustar00rootroot00000000000000require "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/000077500000000000000000000000001255640121500153265ustar00rootroot00000000000000markerb-1.1.0/lib/markerb/markdown.rb000066400000000000000000000011341255640121500174740ustar00rootroot00000000000000module 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.rb000066400000000000000000000002261255640121500173040ustar00rootroot00000000000000module Markerb class Railtie < ::Rails::Railtie config.markerb = Markerb config.app_generators.mailer :template_engine => :markerb end endmarkerb-1.1.0/lib/markerb/version.rb000066400000000000000000000000471255640121500173410ustar00rootroot00000000000000module Markerb VERSION = "1.1.0" end markerb-1.1.0/markerb.gemspec000066400000000000000000000014051255640121500161250ustar00rootroot00000000000000# -*- 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/000077500000000000000000000000001255640121500141145ustar00rootroot00000000000000markerb-1.1.0/test/generator_test.rb000066400000000000000000000010071255640121500174640ustar00rootroot00000000000000require "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.rb000066400000000000000000000020071255640121500173210ustar00rootroot00000000000000require "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.rb000066400000000000000000000066761255640121500171420ustar00rootroot00000000000000require "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.rb000066400000000000000000000011271255640121500167600ustar00rootroot00000000000000require "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/000077500000000000000000000000001255640121500152515ustar00rootroot00000000000000markerb-1.1.0/test/views/notifier/000077500000000000000000000000001255640121500170705ustar00rootroot00000000000000markerb-1.1.0/test/views/notifier/_user_info.markerb000066400000000000000000000000221255640121500225570ustar00rootroot00000000000000woot! **Partial** markerb-1.1.0/test/views/notifier/contact.markerb000066400000000000000000000000311255640121500220620ustar00rootroot00000000000000Dual templates **rocks**!markerb-1.1.0/test/views/notifier/link.markerb000066400000000000000000000000431255640121500213670ustar00rootroot00000000000000Hello from http://www.fcstpauli.commarkerb-1.1.0/test/views/notifier/user.markerb000066400000000000000000000000461255640121500214130ustar00rootroot00000000000000<%= render :partial => 'user_info' %>