Module: Rango::GV
- Defined in:
- lib/rango/gv.rb,
lib/rango/gv/router.rb,
lib/rango/gv/static.rb,
lib/rango/gv/scaffolding.rb
Defined Under Namespace
Modules: Scaffolding
Class Method Summary collapse
- .defer(&hook) ⇒ Object
-
.redirect(url, status = 301) ⇒ Object
Usher has support for redirect, but Rango doesn’t depend on any particular router and your router might not provide this functionality.
- .static(template, scope = Object.new, context = Hash.new, &hook) ⇒ Object
Class Method Details
.defer(&hook) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rango/gv/router.rb', line 18 def self.defer(&hook) Rango::Mini.app do |request, response| value = hook.call(request, response) if value.respond_to?(:call) return value.call(request.env) elsif value.is_a?(Array) && value.length.eql?(3) return value # if we use redirect else raise "Value returned from Rango::GV.defer has to be Rack response or Rack application. Returned value: #{value.inspect}" end end end |
.redirect(url, status = 301) ⇒ Object
Usher has support for redirect, but Rango doesn’t depend on any particular router and your router might not provide this functionality. In this case you can always use this generic view. get(“/index.php”).to(Rango::GV.redirect(“/”))
35 36 37 38 39 40 |
# File 'lib/rango/gv/router.rb', line 35 def self.redirect(url, status = 301) Rango::Mini.app do |request, response| response.redirect(url, status) return String.new end end |
.static(template, scope = Object.new, context = Hash.new, &hook) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rango/gv/static.rb', line 9 def self.static(template, scope = Object.new, context = Hash.new, &hook) Rango::Mini.app do |request, response| path = template || request.env["rango.router.params"][:template] path = hook.call(path) unless hook.nil? path = "#{path}.html" unless path.match(/\./) Rango.logger.debug("Rendering '#{path}'") # Rango::RenderMixin.scope context = context.call(request) if context.respond_to?(:call) # lambda { |request| {msg: request.message} } Rango::RenderMixin.render path, scope, context end end |