Permalink
Browse files

Simple implementation of multipart rendering (#4)

  • Loading branch information...
inescoelho committed Aug 10, 2015
1 parent 8e0c837 commit b38d71adc675b582d6c6cc77a731a031ed9a61e5
View
@@ -3,6 +3,7 @@
require 'lotus/mailer/version'
require 'lotus/mailer/configuration'
require 'lotus/mailer/dsl'
require 'lotus/mailer/rendering'
module Lotus
module Mailer
@@ -210,6 +211,7 @@ def self.included(base)
base.class_eval do
extend Dsl.dup
extend Rendering.dup
include Utils::ClassAttribute
class_attribute :configuration
View
@@ -244,7 +244,6 @@ def subject (value = nil)
end
end
protected
# Loading mechanism hook.
@@ -0,0 +1,19 @@
module Lotus
module Mailer
# Render mechanism
#
# @since 0.1.0
module Rendering
# Render a single template with the specified format.
#
# @return [String] the output of the rendering process.
#
# @since 0.1.0
def render(format)
@templates[format].render
end
end
end
end
@@ -47,10 +47,10 @@ def template
TemplateFinder.new(@mailer.class, @options).find
end
# def scope
# Scope.new(@mailer, @options[:locals])
# end
def scope
Scope.new(@mailer, @options[:locals])
end
end
end
end
end
end
@@ -35,19 +35,19 @@ def format
# @since 0.1.0
#
# @see Lotus::Mailer::Scope
def render(scope, &blk)
@_template.render(scope, {}, &blk)
def render
@_template.render
end
# Get the path to the template
#
#
# @return [String] the pathname
#
# @since 0.1.0
def file
@_template.file
end
end
end
end
@@ -0,0 +1 @@
<h1>Banana</h1>
View
@@ -9,17 +9,17 @@
describe '#template' do
describe 'set_the_correct_templates' do
it 'has_the_template_in_the_hash' do
template_test = InvoiceMailer.templates[:html]
template_test.file.must_equal("#{ InvoiceMailer.root }/invoice.html.erb")
templateTest = InvoiceMailer.templates[:html]
templateTest.file.must_equal("#{ InvoiceMailer.root }/invoice.html.erb")
end
end
end
describe '#templates' do
describe 'finds_all_the_templates_with_the_same_name' do
it 'has_the_template_in_the_hash' do
template_test = LazyMailer.templates[:html]
template_test.file.must_equal("#{ LazyMailer.root }/lazy_mailer.html.erb")
templateTest = LazyMailer.templates[:html]
templateTest.file.must_equal("#{ LazyMailer.root }/lazy_mailer.html.erb")
end
end
end
View
@@ -0,0 +1,10 @@
require 'test_helper'
require 'lotus/mailer'
describe Lotus::Mailer do
describe 'render' do
it 'renders a single template with a given format' do
InvoiceMailer.render(:html).must_include %(<h1>Banana</h1>)
end
end
end

0 comments on commit b38d71a

Please sign in to comment.