aboutsummaryrefslogtreecommitdiffstats
path: root/lib/attachment_to_html/view.rb
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-04-14 17:14:01 +0100
committerGareth Rees <gareth@mysociety.org>2014-04-14 17:14:01 +0100
commit0c54aa3bc1bda24fa6cca97e52753a5ea07e7638 (patch)
tree0b3dc1c6aae0e277e51c1e43c8519f21e36401cd /lib/attachment_to_html/view.rb
parentfb0742f39fc9f5ba9e45ef08a4e4312ea10660f1 (diff)
parent9f283e2e48e859d1ba6a31baa783feb177cccb17 (diff)
Merge branch 'issues/337-attachment-title' into rails-3-develop
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