class Roda::RodaPlugins::HashRoutes::DSL
Internal class handling the internals of the hash_routes
class method blocks.
def dispatch_from(namespace='', branch, &block)
namespace. If a block is given, call the block with the request before
Setup the given branch in the given namespace to dispatch to routes in this
def dispatch_from(namespace='', branch, &block) ns = @namespace if block meth_hash = @roda.opts[:hash_routes_methods] key = [:dispatch_from, namespace, branch].freeze meth = meth_hash[key] = @roda.define_roda_method(meth_hash[key] || "hash_routes_dispatch_from_#{namespace}_#{branch}", 1, &block) @roda.hash_branch(namespace, branch) do |r| send(meth, r) r.hash_routes(ns) end else @roda.hash_branch(namespace, branch) do |r| r.hash_routes(ns) end end end
def initialize(roda, namespace)
def initialize(roda, namespace) @roda = roda @namespace = namespace end
def is(path, &block)
If path is given as a string, it is prefixed with a slash.
Use the segment to setup a path in the current namespace.
def is(path, &block) path = path == true ? "" : "/#{path}" @roda.hash_path(@namespace, path, &block) end
def on(segment, &block)
def on(segment, &block) @roda.hash_branch(@namespace, segment, &block) end
def verb(verb, path, &block)
Setup a path in the current namespace for the given request method verb.
def verb(verb, path, &block) path = path == true ? "" : "/#{path}" meth_hash = @roda.opts[:hash_routes_methods] key = [@namespace, path].freeze meth = meth_hash[key] = @roda.define_roda_method(meth_hash[key] || "hash_routes_#{@namespace}_#{path}", 0, &block) @roda.hash_path(@namespace, path) do |r| r.send(verb) do send(meth) end end end
def view(path, template)
If path is given as a string, it is prefixed with a slash.
used, and will return a 404 if another request method is used.
will render the view with the given name if the GET method is
Use the segment to setup a path in the current namespace that
def view(path, template) path = path == true ? "" : "/#{path}" @roda.hash_path(@namespace, path) do |r| r.get do view(template) end end end
def views(templates)
the current namespace for the template using the same name
For each template in the array of templates, setup a path in
def views(templates) templates.each do |template| view(template, template) end end