class AutoForme::Frameworks::Roda

  1. lib/autoforme/frameworks/roda.rb
Superclass: Framework

Methods

Public Class

  1. new

Public Instance

  1. route_proc

Attributes

Public Class methods

new (*)

Return a proc that should be instance_execed in the Roda routing and and handles the route if it recognizes it, otherwise doing nothing.

[show source]
    # File lib/autoforme/frameworks/roda.rb
 80 def initialize(*)
 81   super
 82   framework = self
 83 
 84   matchers = [:model, :action_type]
 85   if framework.prefix
 86     matchers.unshift(framework.prefix[1..-1])
 87   end
 88 
 89   @route_proc = lambda do 
 90     r = request
 91     path = if r.respond_to?(:matched_path)
 92       r.matched_path
 93     else
 94       # :nocov:
 95       r.env['SCRIPT_NAME']
 96       # :nocov:
 97     end
 98     current_matchers = matchers + [lambda{@autoforme_action = framework.action_for(Request.new(self, path))}]
 99 
100     r.on(*current_matchers) do
101       @autoforme_text = @autoforme_action.handle
102       if @autoforme_action.output_type == 'csv'
103         response['Content-Type'] = 'text/csv'
104         response['Content-Disposition'] = "attachment; filename=#{@autoforme_action.output_filename}"
105         @autoforme_text
106       elsif @autoforme_action.request.xhr?
107         @autoforme_text
108       else
109         view(:content=>@autoforme_text)
110       end
111     end
112   end
113 end