Class: Decisive::TemplateHandler

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

Class Method Summary collapse

Class Method Details

.call(template) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/decisive/template_handler.rb', line 11

def self.call template
  "    extend Decisive::DSL\n    context = (\#{template.source})\n\n    response.headers[\"Content-Type\"] = \"text/csv\"\n    response.headers[\"Content-Transfer-Encoding\"] = \"binary\"\n    response.headers[\"Content-Disposition\"] = %(attachment; filename=\"\\\#{context.filename}\")\n\n    if controller.respond_to?(:new_controller_thread) # has AC::Live mixed in\n      begin\n        context.each do |row|\n          response.stream.write row.to_csv(force_quotes: true)\n        end\n        raise if Rails.env.test? # WTF WTF without this the stream isn't closed in test mode??? WTF WTF\n      ensure\n        response.stream.close\n      end\n      \"\"\n    else\n      context.to_csv(force_quotes: true)\n    end\n  RUBY\nend\n"

.registerObject



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

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