pax_global_header 0000666 0000000 0000000 00000000064 12151603252 0014507 g ustar 00root root 0000000 0000000 52 comment=8fcaac9b902937572456cda67e61b9fd6cc6594c ruby-markerb-1.0.1/ 0000775 0000000 0000000 00000000000 12151603252 0014110 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/.gitignore 0000664 0000000 0000000 00000000020 12151603252 0016070 0 ustar 00root root 0000000 0000000 .bundle test/tmp ruby-markerb-1.0.1/Gemfile 0000664 0000000 0000000 00000000074 12151603252 0015404 0 ustar 00root root 0000000 0000000 source "http://rubygems.org" gem "rails", "~> 3.0" gemspec ruby-markerb-1.0.1/Gemfile.lock 0000664 0000000 0000000 00000003734 12151603252 0016341 0 ustar 00root root 0000000 0000000 PATH 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-LICENSE 0000664 0000000 0000000 00000002071 12151603252 0015544 0 ustar 00root root 0000000 0000000 Copyright 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.md 0000664 0000000 0000000 00000003046 12151603252 0015372 0 ustar 00root root 0000000 0000000 # 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/Rakefile 0000664 0000000 0000000 00000001077 12151603252 0015562 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 ruby-markerb-1.0.1/lib/ 0000775 0000000 0000000 00000000000 12151603252 0014656 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/lib/generators/ 0000775 0000000 0000000 00000000000 12151603252 0017027 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/lib/generators/markerb/ 0000775 0000000 0000000 00000000000 12151603252 0020452 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/lib/generators/markerb/mailer/ 0000775 0000000 0000000 00000000000 12151603252 0021723 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/lib/generators/markerb/mailer/mailer_generator.rb 0000664 0000000 0000000 00000000554 12151603252 0025573 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 handler :markerb end end end end ruby-markerb-1.0.1/lib/generators/markerb/mailer/templates/ 0000775 0000000 0000000 00000000000 12151603252 0023721 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/lib/generators/markerb/mailer/templates/view.markerb 0000664 0000000 0000000 00000000126 12151603252 0026237 0 ustar 00root root 0000000 0000000 <%= class_name %>#<%= @action %> <%%= @greeting %>, find me in app/views/<%= @path %> ruby-markerb-1.0.1/lib/markerb.rb 0000664 0000000 0000000 00000001315 12151603252 0016626 0 ustar 00root root 0000000 0000000 require "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/ 0000775 0000000 0000000 00000000000 12151603252 0016301 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/lib/markerb/railtie.rb 0000664 0000000 0000000 00000000226 12151603252 0020257 0 ustar 00root root 0000000 0000000 module Markerb class Railtie < ::Rails::Railtie config.markerb = Markerb config.app_generators.mailer :template_engine => :markerb end end ruby-markerb-1.0.1/lib/markerb/version.rb 0000664 0000000 0000000 00000000047 12151603252 0020314 0 ustar 00root root 0000000 0000000 module Markerb VERSION = "1.0.1" end ruby-markerb-1.0.1/markerb.gemspec 0000664 0000000 0000000 00000001435 12151603252 0017103 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.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.yml 0000664 0000000 0000000 00000004252 12151603252 0016416 0 ustar 00root root 0000000 0000000 --- !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/ 0000775 0000000 0000000 00000000000 12151603252 0015067 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/test/generator_test.rb 0000664 0000000 0000000 00000001006 12151603252 0020436 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 ruby-markerb-1.0.1/test/markerb_test.rb 0000664 0000000 0000000 00000006676 12151603252 0020115 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 ruby-markerb-1.0.1/test/test_helper.rb 0000664 0000000 0000000 00000000573 12151603252 0017737 0 ustar 00root root 0000000 0000000 require "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/ 0000775 0000000 0000000 00000000000 12151603252 0016224 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/test/views/notifier/ 0000775 0000000 0000000 00000000000 12151603252 0020043 5 ustar 00root root 0000000 0000000 ruby-markerb-1.0.1/test/views/notifier/_user_info.markerb 0000664 0000000 0000000 00000000022 12151603252 0023532 0 ustar 00root root 0000000 0000000 woot! **Partial** ruby-markerb-1.0.1/test/views/notifier/contact.markerb 0000664 0000000 0000000 00000000031 12151603252 0023035 0 ustar 00root root 0000000 0000000 Dual templates **rocks**! ruby-markerb-1.0.1/test/views/notifier/link.markerb 0000664 0000000 0000000 00000000043 12151603252 0022342 0 ustar 00root root 0000000 0000000 Hello from http://www.fcstpauli.com ruby-markerb-1.0.1/test/views/notifier/user.markerb 0000664 0000000 0000000 00000000046 12151603252 0022366 0 ustar 00root root 0000000 0000000 <%= render :partial => 'user_info' %>