pax_global_header00006660000000000000000000000064121516032520014507gustar00rootroot0000000000000052 comment=8fcaac9b902937572456cda67e61b9fd6cc6594c ruby-markerb-1.0.1/000077500000000000000000000000001215160325200141105ustar00rootroot00000000000000ruby-markerb-1.0.1/.gitignore000066400000000000000000000000201215160325200160700ustar00rootroot00000000000000.bundle test/tmpruby-markerb-1.0.1/Gemfile000066400000000000000000000000741215160325200154040ustar00rootroot00000000000000source "http://rubygems.org" gem "rails", "~> 3.0" gemspec ruby-markerb-1.0.1/Gemfile.lock000066400000000000000000000037341215160325200163410ustar00rootroot00000000000000PATH remote: . specs: markerb (1.0.1) redcarpet (>= 2.0) GEM remote: http://rubygems.org/ specs: actionmailer (3.2.11) actionpack (= 3.2.11) mail (~> 2.4.4) actionpack (3.2.11) activemodel (= 3.2.11) activesupport (= 3.2.11) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) rack (~> 1.4.0) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) activemodel (3.2.11) activesupport (= 3.2.11) builder (~> 3.0.0) activerecord (3.2.11) activemodel (= 3.2.11) activesupport (= 3.2.11) arel (~> 3.0.2) tzinfo (~> 0.3.29) activeresource (3.2.11) activemodel (= 3.2.11) activesupport (= 3.2.11) activesupport (3.2.11) i18n (~> 0.6) multi_json (~> 1.0) arel (3.0.2) builder (3.0.4) erubis (2.7.0) hike (1.2.1) i18n (0.6.1) journey (1.0.4) json (1.7.6) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) multi_json (1.5.0) polyglot (0.3.3) rack (1.4.4) rack-cache (1.2) rack (>= 0.4) rack-ssl (1.3.2) rack rack-test (0.6.2) rack (>= 1.0) rails (3.2.11) actionmailer (= 3.2.11) actionpack (= 3.2.11) activerecord (= 3.2.11) activeresource (= 3.2.11) activesupport (= 3.2.11) bundler (~> 1.0) railties (= 3.2.11) railties (3.2.11) actionpack (= 3.2.11) activesupport (= 3.2.11) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.3) rdoc (3.12) json (~> 1.4) redcarpet (2.2.2) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) thor (0.16.0) tilt (1.3.3) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) PLATFORMS ruby DEPENDENCIES markerb! rails (~> 3.0) ruby-markerb-1.0.1/MIT-LICENSE000066400000000000000000000020711215160325200155440ustar00rootroot00000000000000Copyright 2011 PlataformaTec (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. ruby-markerb-1.0.1/README.md000066400000000000000000000030461215160325200153720ustar00rootroot00000000000000# 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! ## 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 2012 Plataforma Tecnologia. http://blog.plataformatec.com.br ruby-markerb-1.0.1/Rakefile000066400000000000000000000010771215160325200155620ustar00rootroot00000000000000require '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 ruby-markerb-1.0.1/lib/000077500000000000000000000000001215160325200146565ustar00rootroot00000000000000ruby-markerb-1.0.1/lib/generators/000077500000000000000000000000001215160325200170275ustar00rootroot00000000000000ruby-markerb-1.0.1/lib/generators/markerb/000077500000000000000000000000001215160325200204525ustar00rootroot00000000000000ruby-markerb-1.0.1/lib/generators/markerb/mailer/000077500000000000000000000000001215160325200217235ustar00rootroot00000000000000ruby-markerb-1.0.1/lib/generators/markerb/mailer/mailer_generator.rb000066400000000000000000000005541215160325200255730ustar00rootroot00000000000000require "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 handler :markerb end end end endruby-markerb-1.0.1/lib/generators/markerb/mailer/templates/000077500000000000000000000000001215160325200237215ustar00rootroot00000000000000ruby-markerb-1.0.1/lib/generators/markerb/mailer/templates/view.markerb000066400000000000000000000001261215160325200262370ustar00rootroot00000000000000<%= class_name %>#<%= @action %> <%%= @greeting %>, find me in app/views/<%= @path %>ruby-markerb-1.0.1/lib/markerb.rb000066400000000000000000000013151215160325200166260ustar00rootroot00000000000000require "action_view/template" require "redcarpet" require "markerb/railtie" module Markerb mattr_accessor :processing_options, :renderer @@processing_options = {} @@renderer = Redcarpet::Render::HTML 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) "Redcarpet::Markdown.new(Markerb.renderer, Markerb.processing_options).render(begin;#{compiled_source};end).html_safe" else compiled_source end end end end ActionView::Template.register_template_handler :markerb, Markerb::Handler.new ruby-markerb-1.0.1/lib/markerb/000077500000000000000000000000001215160325200163015ustar00rootroot00000000000000ruby-markerb-1.0.1/lib/markerb/railtie.rb000066400000000000000000000002261215160325200202570ustar00rootroot00000000000000module Markerb class Railtie < ::Rails::Railtie config.markerb = Markerb config.app_generators.mailer :template_engine => :markerb end endruby-markerb-1.0.1/lib/markerb/version.rb000066400000000000000000000000471215160325200203140ustar00rootroot00000000000000module Markerb VERSION = "1.0.1" end ruby-markerb-1.0.1/markerb.gemspec000066400000000000000000000014351215160325200171030ustar00rootroot00000000000000# -*- 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.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.add_dependency "redcarpet", ">= 2.0" end ruby-markerb-1.0.1/metadata.yml000066400000000000000000000042521215160325200164160ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: markerb version: !ruby/object:Gem::Version prerelease: version: 1.0.1 platform: ruby authors: - José Valim autorequire: bindir: bin cert_chain: [] date: 2013-01-17 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency type: :runtime prerelease: false name: redcarpet version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '2.0' requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '2.0' description: Multipart templates made easy with Markdown + ERb email: contact@plataformatec.com.br executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - Gemfile - Gemfile.lock - MIT-LICENSE - README.md - Rakefile - lib/generators/markerb/mailer/mailer_generator.rb - lib/generators/markerb/mailer/templates/view.markerb - lib/markerb.rb - lib/markerb/railtie.rb - lib/markerb/version.rb - markerb.gemspec - test/generator_test.rb - test/markerb_test.rb - test/test_helper.rb - test/views/notifier/_user_info.markerb - test/views/notifier/contact.markerb - test/views/notifier/link.markerb - test/views/notifier/user.markerb homepage: http://github.com/plataformatec/markerb licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version segments: - 0 hash: 4054513018052400510 version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version segments: - 0 hash: 4054513018052400510 version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.24 signing_key: specification_version: 3 summary: Multipart templates made easy with Markdown + ERb test_files: - test/generator_test.rb - test/markerb_test.rb - test/test_helper.rb - test/views/notifier/_user_info.markerb - test/views/notifier/contact.markerb - test/views/notifier/link.markerb - test/views/notifier/user.markerb ruby-markerb-1.0.1/test/000077500000000000000000000000001215160325200150675ustar00rootroot00000000000000ruby-markerb-1.0.1/test/generator_test.rb000066400000000000000000000010061215160325200204360ustar00rootroot00000000000000require "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 endruby-markerb-1.0.1/test/markerb_test.rb000066400000000000000000000066761215160325200201150ustar00rootroot00000000000000require "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 ruby-markerb-1.0.1/test/test_helper.rb000066400000000000000000000005731215160325200177370ustar00rootroot00000000000000require "rubygems" require "bundler" Bundler.setup require "test/unit" require "active_support/test_case" require "action_mailer" require "rails/railtie" require "rails/generators" require "rails/generators/test_case" $:.unshift File.expand_path("../../lib", __FILE__) require "markerb" ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ruby-markerb-1.0.1/test/views/000077500000000000000000000000001215160325200162245ustar00rootroot00000000000000ruby-markerb-1.0.1/test/views/notifier/000077500000000000000000000000001215160325200200435ustar00rootroot00000000000000ruby-markerb-1.0.1/test/views/notifier/_user_info.markerb000066400000000000000000000000221215160325200235320ustar00rootroot00000000000000woot! **Partial** ruby-markerb-1.0.1/test/views/notifier/contact.markerb000066400000000000000000000000311215160325200230350ustar00rootroot00000000000000Dual templates **rocks**!ruby-markerb-1.0.1/test/views/notifier/link.markerb000066400000000000000000000000431215160325200223420ustar00rootroot00000000000000Hello from http://www.fcstpauli.comruby-markerb-1.0.1/test/views/notifier/user.markerb000066400000000000000000000000461215160325200223660ustar00rootroot00000000000000<%= render :partial => 'user_info' %>