Class: Htmltoword::Renderer
- Inherits:
-
Object
- Object
- Htmltoword::Renderer
- Defined in:
- lib/htmltoword/renderer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(context, filename, options) ⇒ Renderer
constructor
A new instance of Renderer.
- #send_file ⇒ Object
Constructor Details
#initialize(context, filename, options) ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 13 14 15 16 17 |
# File 'lib/htmltoword/renderer.rb', line 9 def initialize(context, filename, ) @word_template = [:word_template].presence @disposition = .fetch(:disposition, 'attachment') @use_extras = .fetch(:extras, false) @file_name = file_name(filename, ) @context = context define_template(filename, ) @content = [:content] || @context.render_to_string() end |
Class Method Details
.send_file(context, filename, options = {}) ⇒ Object
4 5 6 |
# File 'lib/htmltoword/renderer.rb', line 4 def send_file(context, filename, = {}) new(context, filename, ).send_file end |
Instance Method Details
#send_file ⇒ Object
19 20 21 22 |
# File 'lib/htmltoword/renderer.rb', line 19 def send_file document = Htmltoword::Document.create(@content, @word_template, @use_extras) @context.send_data(document, filename: @file_name, type: Mime::DOCX, disposition: @disposition) end |