Classes and Modules
Public Class methods
new(*)
Add get and post routes when creating the framework. These routes can potentially match other routes, but in that case use pass to try the next route.
[show source]
# File lib/autoforme/frameworks/sinatra.rb 43 def initialize(*) 44 super 45 framework = self 46 block = lambda do 47 if @autoforme_action = framework.action_for(Request.new(self)) 48 @autoforme_text = @autoforme_action.handle 49 50 if @autoforme_action.output_type == 'csv' 51 response['Content-Type'] = 'text/csv' 52 response['Content-Disposition'] = "attachment; filename=#{@autoforme_action.output_filename}" 53 @autoforme_text 54 elsif @autoforme_action.request.xhr? 55 @autoforme_text 56 else 57 opts = framework.opts[:view_options] 58 erb("<%= @autoforme_text %>".dup, opts ? opts.dup : {}) 59 end 60 else 61 pass 62 end 63 end 64 65 prefix = Regexp.escape(framework.prefix) if framework.prefix 66 # :nocov: 67 if ::Sinatra::VERSION < '2' 68 prefix = "\\A#{prefix}" 69 suffix = "\\z" 70 end 71 # :nocov: 72 regexp = %r{#{prefix}/([\w:]+)/(\w+)(?:/([:\w-]+))?#{suffix}} 73 @controller.get regexp, &block 74 @controller.post regexp, &block 75 end