Class: WorkbookRails::TemplateHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/workbook_rails/template_handler.rb

Class Method Summary collapse

Class Method Details

.call(template) ⇒ Object


17
18
19
20
21
# File 'lib/workbook_rails/template_handler.rb', line 17

def self.call(template)
  "workbook = Workbook::Book.new;\n" +
  template.source +
  ";\nWorkbookRails::TemplateHandler.workbook_to_string(workbook, lookup_context.rendered_format);"
end

.workbook_to_string(workbook, format) ⇒ Object


6
7
8
9
10
11
12
13
14
15
# File 'lib/workbook_rails/template_handler.rb', line 6

def self.workbook_to_string(workbook, format)
  case format
  when :csv then workbook.sheet.table.to_csv
  when :xlsx then workbook.stream_xlsx
  when :xls then
    io = StringIO.new
    workbook.to_xls.write(io)
    io.string
  end
end