aboutsummaryrefslogtreecommitdiffstats
path: root/lib/attachment_to_html
diff options
context:
space:
mode:
Diffstat (limited to 'lib/attachment_to_html')
-rw-r--r--lib/attachment_to_html/attachment_to_html.rb6
-rw-r--r--lib/attachment_to_html/template.html.erb3
-rw-r--r--lib/attachment_to_html/view.rb14
3 files changed, 21 insertions, 2 deletions
diff --git a/lib/attachment_to_html/attachment_to_html.rb b/lib/attachment_to_html/attachment_to_html.rb
index ca899221b..2f7c08264 100644
--- a/lib/attachment_to_html/attachment_to_html.rb
+++ b/lib/attachment_to_html/attachment_to_html.rb
@@ -17,7 +17,11 @@ module AttachmentToHTML
view = View.new(adapter)
view.wrapper = 'wrapper_google_embed' if adapter.is_a?(Adapters::GoogleDocsViewer)
- view.render
+ view.render do
+ opts.fetch(:content_for, []).each do |k,v|
+ inject_content(k) { v }
+ end
+ end
end
private
diff --git a/lib/attachment_to_html/template.html.erb b/lib/attachment_to_html/template.html.erb
index 9d3068ce2..38286a5f9 100644
--- a/lib/attachment_to_html/template.html.erb
+++ b/lib/attachment_to_html/template.html.erb
@@ -2,12 +2,15 @@
<html>
<head>
<title><%= title %></title>
+ <%= content_for(:head_suffix) %>
</head>
<body>
+ <%= content_for(:body_prefix) %>
<div id="<%= wrapper %>">
<div id="view-html-content">
<%= body %>
</div>
</div>
+ <%= content_for(:body_suffix) %>
</body>
</html>
diff --git a/lib/attachment_to_html/view.rb b/lib/attachment_to_html/view.rb
index 5cdd3823b..e6991d44e 100644
--- a/lib/attachment_to_html/view.rb
+++ b/lib/attachment_to_html/view.rb
@@ -19,9 +19,21 @@ module AttachmentToHTML
super(File.read(template))
end
- def render
+ 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