Module: Web::SimpleDispatcher

Defined in:
lib/web/simpledispatcher.rb

Overview

Web::SimpleDispatcher provides a simple framework for organizing Web applications, combining them with forms and handling forms.

The following is an example form template ‘/myappdir/html/templates/my_app.html

<html>
  <body>
    <narf:form name="my_form" method="post">
      <narf:text name="field1">
      <narf:textarea name="field2">
    </narf:form>
  </body>
</html>

Patrick notes: simple dispatcher might not be simple. view as promising alpha

Defined Under Namespace

Modules: TemplateClassMixin, TemplateMixin Classes: Link, Template

Class Method Summary collapse

Class Method Details

.class_from_template(template) ⇒ Object



118
119
120
# File 'lib/web/simpledispatcher.rb', line 118

def class_from_template template
    template.gsub(/(^|_)([a-z])/) { |m| m.gsub('_','').upcase }   
end

.handle_request(options) ⇒ Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/web/simpledispatcher.rb', line 143

def handle_request options
           unless formclass = template_from_path_info
 options[:default].redirect_to Web.query
 return
    end

           aTemplate = formclass.new(Web.query)

           formclass.handle aTemplate
end

.template_from_class(aClass) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/web/simpledispatcher.rb', line 122

def template_from_class aClass
    first = true
    aClass.name.gsub(/([A-Z])/) do |m| 
 value = m.downcase
 if first
      first = false
      value
 else
      "_" + value
 end
    end
end

.template_from_path_infoObject



135
136
137
138
139
140
141
# File 'lib/web/simpledispatcher.rb', line 135

def template_from_path_info
  if (Web.get_cgi.path_info != "/")
    if (m = /\/?(.+)\/?/.match(Web.get_cgi.path_info))
      eval(class_from_template(m[1]))
    end
  end
end

.trace_dispatcher(text) ⇒ Object

:nodoc: all



20
21
22
23
24
# File 'lib/web/simpledispatcher.rb', line 20

def SimpleDispatcher.trace_dispatcher text
    if $ADD_TEST_OUTPUT
      Kernel.puts text
    end
end