Module Merb::Slices::ControllerMixin::ClassMethods
In: merb-slices/lib/merb-slices/controller_mixin.rb

Methods

Public Instance methods

Setup a controller to reference a slice and its template roots

This method is available to any class inheriting from Merb::AbstractController; it enabled correct location of templates, as well as access to the slice module.

@param slice_module<to_s> The slice module to use; defaults to current module. @param options<Hash>

  Optional parameters to set which component path is used (defaults to :view) and
  the :path option lets you specify a subdirectory of that component path.
  When :layout is set, then this is used instead of the config's :layout setting.

@example controller_for_slice # uses current module @example controller_for_slice SliceMod # defaults to :view templates and no subdirectory @example controller_for_slice :templates_for => :mailer, :path => ‘views’ # for Merb::Mailer @example controller_for_slice SliceMod, :templates_for => :mailer, :path => ‘views’ # for Merb::Mailer

[Source]

    # File merb-slices/lib/merb-slices/controller_mixin.rb, line 63
63:         def controller_for_slice(slice_module = nil, options = {})
64:           options, slice_module = slice_module.merge(options), nil if slice_module.is_a?(Hash)
65:           slice_module ||= self.name.split('::').first
66:           options[:templates_for] = :view unless options.key?(:templates_for)
67:           if slice_mod = Merb::Slices[slice_module.to_s]
68:             # Include the instance methods
69:             unless self.kind_of?(Merb::Slices::ControllerMixin::MixinMethods)
70:               self.send(:extend, Merb::Slices::ControllerMixin::MixinMethods)
71:             end
72:             # Reference this controller's slice module
73:             self.class_inheritable_accessor :slice, :instance_writer => false
74:             self.slice = slice_mod
75:             # Setup template roots
76:             if options[:templates_for]
77:               self._template_root  = join_template_path(slice_mod.dir_for(options[:templates_for]), options[:path])
78:               self._template_roots = []
79:               # app-level app/views directory for shared and fallback views, layouts and partials
80:               self._template_roots << [join_template_path(Merb.dir_for(options[:templates_for]), options[:path]), :_template_location] if Merb.dir_for(options[:templates_for])
81:               # slice-level app/views for the standard supplied views
82:               self._template_roots << [self._template_root, :_slice_template_location] 
83:               # app-level slices/<slice>/app/views for specific overrides
84:               self._template_roots << [join_template_path(slice_mod.app_dir_for(options[:templates_for]), options[:path]), :_slice_template_location]
85:               # additional template roots for specific overrides (optional)
86:               self._template_roots += Array(options[:template_roots]) if options[:template_roots]
87:             end
88:             # Set the layout for this slice controller
89:             layout_for_slice(options[:layout])
90:           end
91:         end

Private Instance methods

[Source]

    # File merb-slices/lib/merb-slices/controller_mixin.rb, line 95
95:         def join_template_path(*segments)
96:           File.join(*segments.compact)
97:         end

[Validate]