module Roda::RodaPlugins::HashBranchViewSubdir::ClassMethods

  1. lib/roda/plugins/hash_branch_view_subdir.rb

Methods

Public Instance

  1. freeze
  2. hash_branch
  3. inherited

Public Instance methods

freeze()

Freeze the hash_branch_view_subdir metadata when freezing the app.

[show source]
   # File lib/roda/plugins/hash_branch_view_subdir.rb
37 def freeze
38   opts[:hash_branch_view_subdir_methods].freeze.each_value(&:freeze)
39   super
40 end
hash_branch(namespace='', segment, &block)

Automatically append a view subdirectory for a successful hash_branch route, by modifying the generated method to append the view subdirectory before dispatching to the original block.

[show source]
   # File lib/roda/plugins/hash_branch_view_subdir.rb
55 def hash_branch(namespace='', segment, &block)
56   meths = opts[:hash_branch_view_subdir_methods][namespace] ||= {}
57 
58   if block
59     meth = meths[segment] = define_roda_method(meths[segment] || "_hash_branch_view_subdir_#{namespace}_#{segment}", 1, &convert_route_block(block))
60     super do |*_|
61       append_view_subdir(segment)
62       send(meth, @_request)
63     end
64   else
65     if meth = meths.delete(segment)
66       remove_method(meth)
67     end
68     super
69   end
70 end
inherited(subclass)

Duplicate hash_branch_view_subdir metadata in subclass.

[show source]
   # File lib/roda/plugins/hash_branch_view_subdir.rb
43 def inherited(subclass)
44   super
45 
46   h = subclass.opts[:hash_branch_view_subdir_methods]
47   opts[:hash_branch_view_subdir_methods].each do |namespace, routes|
48     h[namespace] = routes.dup
49   end
50 end