diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-05-15 17:01:22 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-05-15 17:01:22 +0100 |
commit | bb5f95040d377d86629012347343fbf2c7dda016 (patch) | |
tree | be696ec2615b098db34449a982fcb09a68c9c49b /lib/attachment_to_html/view.rb | |
parent | 6d215fba5cc709c43f12f86da39a643e4be5922b (diff) | |
parent | 21027d0d1197e7ac447296ab68a25159860888b2 (diff) |
Merge remote-tracking branch 'origin/release/0.18'0.18
Diffstat (limited to 'lib/attachment_to_html/view.rb')
-rw-r--r-- | lib/attachment_to_html/view.rb | 39 |
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 |