Class: AutoForme::Frameworks::Sinatra

Inherits:
AutoForme::Framework show all
Defined in:
lib/autoforme/frameworks/sinatra.rb

Defined Under Namespace

Classes: Request

Instance Attribute Summary

Attributes inherited from AutoForme::Framework

#controller, #model_classes, #models, #opts, #prefix

Instance Method Summary collapse

Methods inherited from AutoForme::Framework

#action_for, #association_links_for, #autocomplete_options_for, #columns_for, #display_name_for, #filter_for, for, #form_attributes_for, #form_options_for, #inline_mtm_associations_for, #lazy_load_association_links?, #limit_for, #model, #mtm_associations_for, #order_for, #page_footer_for, #page_header_for, #redirect_for, setup, #supported_actions_for, #table_class_for

Methods included from OptsAttributes

#opts_attribute

Constructor Details

#initializeSinatra

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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/autoforme/frameworks/sinatra.rb', line 37

def initialize(*)
  super
  framework = self
  block = lambda do
    if @autoforme_action = framework.action_for(Request.new(self))
      @autoforme_text = @autoforme_action.handle
      opts = {}
      opts[:layout] = false if @autoforme_action.request.xhr?
      erb "<%= @autoforme_text %>", opts
    else
      pass
    end
  end

  prefix = Regexp.escape(framework.prefix) if framework.prefix
  @controller.get %r{\A#{prefix}/(\w+)/(\w+)(?:/(\w+))?\z}, &block
  @controller.post %r{\A#{prefix}/(\w+)/(\w+)(?:/(\w+))?\z}, &block
end