Module: Conduit::Core::Render
- Defined in:
- lib/conduit/core/render.rb
Defined Under Namespace
Classes: ViewPathNotDefined
Class Method Summary collapse
-
.included(base) ⇒ Object
Create instance variables, any of these can be overriden within the including class.
Instance Method Summary collapse
-
#render(file, layout: true) ⇒ Object
Render a template file.
-
#render_template(file) ⇒ Object
Render a template file.
-
#render_with_layout(file) ⇒ Object
Render the file with a layout.
Class Method Details
.included(base) ⇒ Object
Create instance variables, any of these can be overriden within the including class.
view_path: Location where the view files are stored view_context: Object that contains the variables used in the template
20 21 22 |
# File 'lib/conduit/core/render.rb', line 20 def self.included(base) attr_accessor :view_path, :view_context end |
Instance Method Details
#render(file, layout: true) ⇒ Object
Render a template file
e.g. Without layout
> render :purchase, layout: false
e.g. With layout
> render :purchase
32 33 34 35 |
# File 'lib/conduit/core/render.rb', line 32 def render(file, layout: true) raise ViewPathNotDefined, '' unless view_path layout ? render_with_layout(file) : render_template(file) end |
#render_template(file) ⇒ Object
Render a template file
e.g. Without layout
> render_template(:template)
e.g. With layout
> render_template(:layout) do
> render_template(:template)
> end
47 48 49 50 51 52 |
# File 'lib/conduit/core/render.rb', line 47 def render_template(file) path = File.join(view_path, "#{file}.erb") Tilt::ERBTemplate.new(path).render(view_context) do yield if block_given? end end |
#render_with_layout(file) ⇒ Object
Render the file with a layout
e.g.
> render_layout(:template)
59 60 61 62 63 |
# File 'lib/conduit/core/render.rb', line 59 def render_with_layout(file) render_template(:layout) do render_template(file) end end |