Method: Roda::RodaPlugins::HashBranchViewSubdir::ClassMethods#hash_branch

Defined in:
lib/roda/plugins/hash_branch_view_subdir.rb

#hash_branch(namespace = '', segment, &block) ⇒ Object

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.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/roda/plugins/hash_branch_view_subdir.rb', line 55

def hash_branch(namespace='', segment, &block)
  meths = opts[:hash_branch_view_subdir_methods][namespace] ||= {}

  if block
    meth = meths[segment] = define_roda_method(meths[segment] || "_hash_branch_view_subdir_#{namespace}_#{segment}", 1, &convert_route_block(block))
    super do |*_|
      append_view_subdir(segment)
      send(meth, @_request)
    end
  else
    if meth = meths.delete(segment)
      remove_method(meth)
    end
    super
  end
end