Class: Decisive::TemplateHandler

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

Class Method Summary collapse

Class Method Details

.call(template, source = template.source) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/decisive/template_handler.rb', line 13

def self.call template, source=template.source
  "    extend Decisive::DSL; context = (\#{source})\n\n    response.headers[\"Content-Transfer-Encoding\"] = \"binary\"\n    response.headers[\"Content-Disposition\"] = %(attachment; filename=\"\\\#{context.filename}\")\n\n    if context.csv?\n      response.headers[\"Content-Type\"] = \"text/csv\"\n\n      if @stream\n        begin\n          context.each do |row|\n            response.stream.write row.to_csv(force_quotes: true)\n          end\n        ensure\n          response.stream.close\n        end\n        \"\"\n      else\n        context.to_csv(force_quotes: true)\n      end\n\n    else\n      response.headers[\"Content-Type\"] = \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\"\n      context.to_xls\n    end\n  RUBY\nend\n"

.registerObject



9
10
11
# File 'lib/decisive/template_handler.rb', line 9

def self.register
  ActionView::Template.register_template_handler 'decisive', self
end