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
 88 def initialize(*)
 89   super
 90   framework = self
 91 
 92   matchers = [:model, :action_type]
 93   if framework.prefix
 94     matchers.unshift(framework.prefix[1..-1])
 95   end
 96 
 97   @route_proc = lambda do 
 98     r = request
 99     path = if r.respond_to?(:matched_path)
100       r.matched_path
101     else
102       # :nocov:
103       r.env['SCRIPT_NAME']
104       # :nocov:
105     end
106     current_matchers = matchers + [lambda{@autoforme_action = framework.action_for(Request.new(self, path))}]
107 
108     r.on(*current_matchers) do
109       @autoforme_text = @autoforme_action.handle
110       if @autoforme_action.output_type == 'csv'
111         response['Content-Type'] = 'text/csv'
112         response['Content-Disposition'] = "attachment; filename=#{@autoforme_action.output_filename}"
113         @autoforme_text
114       elsif @autoforme_action.request.xhr?
115         @autoforme_text
116       else
117         opts = framework.opts[:view_options]
118         opts = opts ? opts.dup : {}
119         opts[:content] = @autoforme_text
120         view(opts)
121       end
122     end
123   end
124 end