Class: Rhales::TiltTemplate
- Inherits:
-
Tilt::Template
- Object
- Tilt::Template
- Rhales::TiltTemplate
- Defined in:
- lib/rhales/tilt.rb
Overview
Tilt integration for Rhales templates
This allows Rhales to be used with any framework that supports Tilt, including Roda’s render plugin, Sinatra, and others.
Usage in Roda:
require 'rhales/tilt'
plugin :render, engine: 'rhales'
Usage in Sinatra:
require 'rhales/tilt'
set :template_engine, :rhales
Instance Method Summary collapse
-
#evaluate(scope, locals = {}) ⇒ String
Render the template with given scope and locals.
-
#prepare ⇒ Object
Parse template during initialization.
Instance Method Details
#evaluate(scope, locals = {}) ⇒ String
Render the template with given scope and locals
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rhales/tilt.rb', line 36 def evaluate(scope, locals = {}, &) # Build template props from locals and scope props = build_props(scope, locals, &) # Create Rhales context adapters from scope rhales_context = build_rhales_context(scope, props) # Get template name from file path template_name = derive_template_name # Render the template rhales_context.render(template_name) end |
#prepare ⇒ Object
Parse template during initialization
25 26 27 28 |
# File 'lib/rhales/tilt.rb', line 25 def prepare # Store the template content - parsing happens during render @template_content = data end |