Class: Femto::Base
- Inherits:
-
Object
- Object
- Femto::Base
- Defined in:
- lib/femto.rb
Defined Under Namespace
Classes: TemplateMissingException
Class Attribute Summary collapse
-
.content_type ⇒ Object
Returns the value of attribute content_type.
-
.env ⇒ Object
Returns the value of attribute env.
-
.layout(options = {}, &block) ⇒ Object
Returns the value of attribute layout.
-
.layout_block ⇒ Object
Returns the value of attribute layout_block.
-
.render(options) ⇒ Object
Returns the value of attribute render.
-
.request ⇒ Object
Returns the value of attribute request.
-
.response ⇒ Object
Returns the value of attribute response.
-
.routes ⇒ Object
Returns the value of attribute routes.
-
.template_dir ⇒ Object
Returns the value of attribute template_dir.
Class Method Summary collapse
- .builder ⇒ Object
- .call(env) ⇒ Object
- .call!(env) ⇒ Object
- .handle_request ⇒ Object
- .model(name, &block) ⇒ Object
- .render_template(template, &block) ⇒ Object
- .resolve_template(file) ⇒ Object
- .set_route(verb, path, options, block) ⇒ Object
- .stop ⇒ Object
Class Attribute Details
.content_type ⇒ Object
Returns the value of attribute content_type.
13 14 15 |
# File 'lib/femto.rb', line 13 def content_type @content_type end |
.env ⇒ Object
Returns the value of attribute env.
13 14 15 |
# File 'lib/femto.rb', line 13 def env @env end |
.layout(options = {}, &block) ⇒ Object
Returns the value of attribute layout.
13 14 15 |
# File 'lib/femto.rb', line 13 def layout @layout end |
.layout_block ⇒ Object
Returns the value of attribute layout_block.
13 14 15 |
# File 'lib/femto.rb', line 13 def layout_block @layout_block end |
.render(options) ⇒ Object
Returns the value of attribute render.
13 14 15 |
# File 'lib/femto.rb', line 13 def render @render end |
.request ⇒ Object
Returns the value of attribute request.
13 14 15 |
# File 'lib/femto.rb', line 13 def request @request end |
.response ⇒ Object
Returns the value of attribute response.
13 14 15 |
# File 'lib/femto.rb', line 13 def response @response end |
.routes ⇒ Object
Returns the value of attribute routes.
13 14 15 |
# File 'lib/femto.rb', line 13 def routes @routes end |
.template_dir ⇒ Object
Returns the value of attribute template_dir.
13 14 15 |
# File 'lib/femto.rb', line 13 def template_dir @template_dir end |
Class Method Details
.builder ⇒ Object
104 105 106 107 |
# File 'lib/femto.rb', line 104 def builder @builder = Rack::Builder.new unless @builder @builder end |
.call(env) ⇒ Object
109 110 111 |
# File 'lib/femto.rb', line 109 def call(env) dup.call! env end |
.call!(env) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/femto.rb', line 113 def call!(env) env['PATH_INFO'] = '/' if env['PATH_INFO'].empty? @request = Rack::Request.new env @response = Rack::Response.new @render = nil @content_type = nil @env = env handle_request @response.finish end |
.handle_request ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/femto.rb', line 38 def handle_request catch :stop do verb = request.request_method.downcase request_path = request.path_info routes = @routes[verb] if routes routes.each do |group| path = group[0] = group[1] block = group[2] if request_path == path instance_eval(&block) if [:template] render [:template] elsif [:view] render [:view] end if @layout and @content_type == 'text/html' if @layout_block @layout_block.call end @render = render_template(@layout) { @render } end if @render == nil raise TemplateMissingException.new end response.write @render response['Content-Type'] = content_type return end end end stop end end |
.model(name, &block) ⇒ Object
87 88 89 |
# File 'lib/femto.rb', line 87 def model(name, &block) Femto::Model.create_model name.to_s, &block end |
.render_template(template, &block) ⇒ Object
95 96 97 98 |
# File 'lib/femto.rb', line 95 def render_template(template, &block) @content_type = 'text/html' Tilt.new(template).render self, {}, &block end |
.resolve_template(file) ⇒ Object
91 92 93 |
# File 'lib/femto.rb', line 91 def resolve_template(file) Dir[File.join(@template_dir, file + '.*')][0] end |
.set_route(verb, path, options, block) ⇒ Object
32 33 34 35 36 |
# File 'lib/femto.rb', line 32 def set_route(verb, path, , block) @routes = {} unless @routes @routes[verb] = [] unless @routes[verb] @routes[verb] << [path, , block] end |
.stop ⇒ Object
100 101 102 |
# File 'lib/femto.rb', line 100 def stop throw :stop end |