Module: Maveric::Class
- Defined in:
- lib/maveric.rb
Overview
Methods provided to construct a maveric
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Default headers for Maveric instantiation.
- #mount ⇒ Object
-
#routes ⇒ Object
readonly
Default headers for Maveric instantiation.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_templates(directory = 'templates/*') ⇒ Object
Scours through ‘./templates’, unless provided an alternate directory, and adds templates and a method to maveric::Views.
-
#call(env) ⇒ Object
Instantiates a maveric with the provided environment, then calls maveric#response.
- #inspect ⇒ Object
- #route(d, *a) ⇒ Object
- #routing(mountpoint, routes) ⇒ Object
Instance Attribute Details
#headers ⇒ Object (readonly)
Default headers for Maveric instantiation.
106 107 108 |
# File 'lib/maveric.rb', line 106 def headers @headers end |
#mount ⇒ Object
154 155 156 |
# File 'lib/maveric.rb', line 154 def mount @mount || self.name.downcase.gsub(/^|::/, '/') end |
#routes ⇒ Object (readonly)
Default headers for Maveric instantiation.
106 107 108 |
# File 'lib/maveric.rb', line 106 def routes @routes end |
Class Method Details
.extend_object(obj) ⇒ Object
158 159 160 161 162 |
# File 'lib/maveric.rb', line 158 def self.extend_object obj obj.instance_variable_set '@routes', [] obj.instance_variable_set '@headers', Rack::Utils::HeaderHash.new super end |
Instance Method Details
#add_templates(directory = 'templates/*') ⇒ Object
Scours through ‘./templates’, unless provided an alternate directory, and adds templates and a method to maveric::Views. Currently handles haml and erb files.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/maveric.rb', line 112 def add_templates directory='templates/*' Dir.glob directory do |file| p file next unless File.readable? file and tmpl = File.read(file) next unless extn = File.extname(file) and not extn.empty? next unless name = File.basename(file, extn) and not name.empty? view = case extn when '.haml' require 'haml' rescue next puts "Defining HAML template view " + name.inspect haml = Haml::Engine.new tmpl proc{|content| haml.render self, :content => content } when '.erb' require 'erb' rescue next puts "Defining ERB template view " + name.inspect erb = ERB.new tmpl erb.filename = file proc{|content| erb.result(binding) } else puts "Defining sprintf template view " + name.inspect proc{|content| sprintf self, content } end self::Views::TEMPLATES[name] = view self::Views.__send__ :define_method, name, &view end end |
#call(env) ⇒ Object
Instantiates a maveric with the provided environment, then calls maveric#response
141 142 143 |
# File 'lib/maveric.rb', line 141 def call env new(env).response end |
#inspect ⇒ Object
164 165 166 |
# File 'lib/maveric.rb', line 164 def inspect "#{self.name}:'#{mount}':#{routes.inspect}" end |
#route(d, *a) ⇒ Object
150 151 152 |
# File 'lib/maveric.rb', line 150 def route d, *a a.flatten.each{|r| @routes << [r, d] } end |
#routing(mountpoint, routes) ⇒ Object
145 146 147 148 |
# File 'lib/maveric.rb', line 145 def routing mountpoint, routes @mount = mountpoint routes.each{|d,a| route d, *a } end |