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
19 20 21 |
# File 'lib/conduit/core/render.rb', line 19 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
31 32 33 34 |
# File 'lib/conduit/core/render.rb', line 31 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
46 47 48 49 50 51 |
# File 'lib/conduit/core/render.rb', line 46 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)
58 59 60 61 62 |
# File 'lib/conduit/core/render.rb', line 58 def render_with_layout(file) render_template(:layout) do render_template(file) end end |