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



12
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 12

def self.call template, source=template.source
  "    extend Decisive::DSL\n    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 controller.is_a?(ActionController::Live)\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.ms-excel\"\n      context.to_xls\n    end\n  RUBY\nend\n"

.registerObject



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

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