aboutsummaryrefslogtreecommitdiffstats
path: root/lib/attachment_to_html/view.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2014-05-15 16:09:29 +0100
committerLouise Crow <louise.crow@gmail.com>2014-05-15 16:09:29 +0100
commit26348ce676f7ebbabcc535b2ecf00f99f8fe85c0 (patch)
tree6034dd656a0f9af152f24d6c491b5e61a7190a7d /lib/attachment_to_html/view.rb
parent851ef575cf3c55a3bb194381497b958c2a3ebf1a (diff)
parentb3fa23047bf96bd6a08273c9491ac1ee3b4a3f80 (diff)
Merge branch 'release/0.18' into wdtk
Diffstat (limited to 'lib/attachment_to_html/view.rb')
-rw-r--r--lib/attachment_to_html/view.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/attachment_to_html/view.rb b/lib/attachment_to_html/view.rb
new file mode 100644
index 000000000..e6991d44e
--- /dev/null
+++ b/lib/attachment_to_html/view.rb
@@ -0,0 +1,39 @@
+module AttachmentToHTML
+ class View < ERB
+
+ def self.template
+ @template || "#{ File.dirname(__FILE__) }/template.html.erb"
+ end
+
+ def self.template=(path)
+ @template = path
+ end
+
+ attr_accessor :title, :body, :template, :wrapper
+
+ def initialize(adapter, opts = {})
+ self.title = adapter.title
+ self.body = adapter.body
+ self.template = opts.fetch(:template, self.class.template)
+ self.wrapper = opts.fetch(:wrapper, 'wrapper')
+ super(File.read(template))
+ end
+
+ def render(&block)
+ instance_eval(&block) if block_given?
+ result(binding)
+ end
+
+ def content_for(area)
+ send(area) if respond_to?(area)
+ end
+
+ private
+
+ def inject_content(area, &block)
+ instance_variable_set("@#{ area }".to_sym, block.call)
+ self.class.send(:attr_accessor, area)
+ end
+
+ end
+end