Class: LiquidXlsx::Template
- Inherits:
-
Object
- Object
- LiquidXlsx::Template
- Defined in:
- lib/liquid_xlsx/template.rb
Overview
Main template class for rendering .xlsx files.
Instance Method Summary collapse
-
#initialize(template_path, options = {}) ⇒ Template
constructor
A new instance of Template.
-
#render(data) ⇒ String
Render template and return binary content.
-
#render_to_file(data, output_path) ⇒ Object
Render template and save to file.
Constructor Details
#initialize(template_path, options = {}) ⇒ Template
Returns a new instance of Template.
8 9 10 11 |
# File 'lib/liquid_xlsx/template.rb', line 8 def initialize(template_path, = {}) @template_path = template_path @options = end |
Instance Method Details
#render(data) ⇒ String
Render template and return binary content.
31 32 33 34 35 36 37 38 39 |
# File 'lib/liquid_xlsx/template.rb', line 31 def render(data) package = render_package(data) package.to_binary rescue LiquidXlsx::Error raise rescue Zip::Error, Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::EISDIR => e raise OutputWriteError, "Failed to generate binary output: #{e.class}: #{e.}" end |
#render_to_file(data, output_path) ⇒ Object
Render template and save to file.
17 18 19 20 21 22 23 24 25 |
# File 'lib/liquid_xlsx/template.rb', line 17 def render_to_file(data, output_path) package = render_package(data) package.write(output_path) rescue LiquidXlsx::Error raise rescue Zip::Error, Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::EISDIR => e raise OutputWriteError, "Failed to write output '#{output_path}': #{e.class}: #{e.}" end |