class Roda::RodaPlugins::HashRoutes::DSL

  1. lib/roda/plugins/hash_routes.rb
Superclass: Object

Internal class handling the internals of the hash_routes class method blocks.

Methods

Public Class

  1. new

Public Instance

  1. dispatch_from
  2. is
  3. on
  4. view
  5. views

Public Class methods

new(roda, namespace)
[show source]
    # File lib/roda/plugins/hash_routes.rb
183 def initialize(roda, namespace)
184   @roda = roda
185   @namespace = namespace
186 end

Public Instance methods

dispatch_from(namespace='', branch, &block)

Setup the given branch in the given namespace to dispatch to routes in this namespace. If a block is given, call the block with the request before dispatching to routes in this namespace.

[show source]
    # File lib/roda/plugins/hash_routes.rb
191 def dispatch_from(namespace='', branch, &block)
192   ns = @namespace
193   if block
194     meth_hash = @roda.opts[:hash_routes_methods]
195     key = [:dispatch_from, namespace, branch].freeze
196     meth = meth_hash[key] = @roda.define_roda_method(meth_hash[key] || "hash_routes_dispatch_from_#{namespace}_#{branch}", 1, &block)
197     @roda.hash_branch(namespace, branch) do |r|
198       send(meth, r)
199       r.hash_routes(ns)
200     end
201   else
202     @roda.hash_branch(namespace, branch) do |r|
203       r.hash_routes(ns)
204     end
205   end
206 end
is(path, &block)

Use the segment to setup a path in the current namespace. If path is given as a string, it is prefixed with a slash. If path is true, the empty string is used as the path.

[show source]
    # File lib/roda/plugins/hash_routes.rb
216 def is(path, &block)
217   path = path == true ? "" : "/#{path}"
218   @roda.hash_path(@namespace, path, &block)
219 end
on(segment, &block)

Use the segment to setup a branch in the current namespace.

[show source]
    # File lib/roda/plugins/hash_routes.rb
209 def on(segment, &block)
210   @roda.hash_branch(@namespace, segment, &block)
211 end
view(path, template)

Use the segment to setup a path in the current namespace that will render the view with the given name if the GET method is used, and will return a 404 if another request method is used. If path is given as a string, it is prefixed with a slash. If path is true, the empty string is used as the path.

[show source]
    # File lib/roda/plugins/hash_routes.rb
226 def view(path, template)
227   path = path == true ? "" : "/#{path}"
228   @roda.hash_path(@namespace, path) do |r|
229     r.get do
230       view(template)
231     end
232   end
233 end
views(templates)

For each template in the array of templates, setup a path in the current namespace for the template using the same name as the template.

[show source]
    # File lib/roda/plugins/hash_routes.rb
238 def views(templates)
239   templates.each do |template|
240     view(template, template)
241   end
242 end