Merb::Slices::ControllerMixin::MixinMethods::InstanceMethods

Public Instance Methods

slice() click to toggle source

Reference this controller’s slice module directly.

@return A slice module.

     # File lib/merb-slices/controller_mixin.rb, line 122
122:           def slice; self.class.slice; end
slice_url(*args) click to toggle source

Generate a url - takes the slice’s :path_prefix into account.

@param *args

  There are several possibilities regarding arguments:
  * when passing a Hash only, the :default route of the current 
    slice will be used
  * when a single Symbol is passed, it's used as the route name,
    while the slice itself will be the current one
  * when two Symbols are passed, the first will be the slice name,
    the second will be the route name
  * a Hash with additional params can optionally be passed

@return A uri based on the requested slice.

@example slice_url(:controller => ‘foo’, :action => ‘bar’) @example slice_url(:awesome, :format => ‘html’) @example slice_url(:forum, :posts, :format => ‘xml’)

     # File lib/merb-slices/controller_mixin.rb, line 141
141:           def slice_url(*args)
142:             opts = args.last.is_a?(Hash) ? args.pop : {}
143:             slice_name, route_name = if args[0].is_a?(Symbol) && args[1].is_a?(Symbol)
144:               [args.shift, args.shift] # other slice identifier, route name
145:             elsif args[0].is_a?(Symbol)
146:               [slice.identifier_sym, args.shift] # self, route name
147:             else
148:               [slice.identifier_sym, :default] # self, default route
149:             end
150:             
151:             routes = Merb::Slices.named_routes[slice_name]
152:             unless routes && route = routes[route_name]
153:               raise Merb::Router::GenerationError, "Named route not found: #{route_name}"
154:             end
155:             
156:             args.push(opts)
157:             route.generate(args, params)
158:           end

Private Instance Methods

_slice_template_location(context, type = nil, controller = controller_name) click to toggle source

This is called after the controller is instantiated to figure out where to for templates under the _template_root. This helps the controllers of a slice to locate templates without looking in a subdirectory with the name of the module. Instead it will just be app/views/controller/*

@param context<#> The controller context (the action or template name). @param type<#> The content type. Defaults to nil. @param controller<#> The name of the controller. Defaults to controller_name.

@return

  Indicating where to look for the template for the current controller,
  context, and content-type.
     # File lib/merb-slices/controller_mixin.rb, line 174
174:           def _slice_template_location(context, type = nil, controller = controller_name)
175:             if controller && controller.include?('/')
176:               # skip first segment if given (which is the module name)
177:               segments = controller.split('/')
178:               "#{segments[1,segments.length-1].join('/')}/#{context}.#{type}"
179:             else
180:               # default template location logic
181:               _template_location(context, type, controller)
182:             end
183:           end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.