Class: Mack::Rendering::Type::Partial
- Defined in:
- lib/mack/rendering/type/partial.rb
Overview
Used to render partials. Partials are small reusable templates. They have to start with an _.
Example:
<%= render(:partial, "users/form") %> # => /users/_form.html.erb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#allow_layout? ⇒ Boolean
No layouts should be used with this Mack::Rendering::Type.
-
#render ⇒ Object
See Mack::Rendering::Type::FileBase render_file for more information.
Methods inherited from FileBase
Methods inherited from Base
#capture, #controller_view_path, #find_engine, #find_file, #initialize, #method_missing
Constructor Details
This class inherits a constructor from Mack::Rendering::Type::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mack::Rendering::Type::Base
Instance Method Details
#allow_layout? ⇒ Boolean
No layouts should be used with this Mack::Rendering::Type
34 35 36 |
# File 'lib/mack/rendering/type/partial.rb', line 34 def allow_layout? false end |
#render ⇒ Object
See Mack::Rendering::Type::FileBase render_file for more information.
The path to the file is built like such:
app/views/#{controller name}/#{partial name with prefixed _}.#{format (html, xml, js, etc...)}.#{extension defined in the engine}
Example:
app/views/users/_form.html.erb
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mack/rendering/type/partial.rb', line 17 def render partial = self._render_value.to_s parts = partial.split("/") if parts.size == 1 # it's local to this controller partial = "_" << partial partial = File.join(self.controller_view_path, partial) else # it's elsewhere parts[parts.size - 1] = "_" << parts.last partial = Mack::Paths.views(parts) end partial = "#{partial}.#{self.[:format]}" render_file(partial, :partial) end |