Class: Htmltoword::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/htmltoword/renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

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, options)
  @word_template = options[:word_template].presence
  @disposition = options.fetch(:disposition, 'attachment')
  @use_extras = options.fetch(:extras, false)
  @file_name = file_name(filename, options)
  @context = context
  define_template(filename, options)
  @content = options[:content] || @context.render_to_string(options)
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, options = {})
  new(context, filename, options).send_file
end

Instance Method Details

#send_fileObject



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