Module: TemplateRenderer
- Included in:
- Generator
- Defined in:
- lib/generators/template_renderer.rb,
lib/generators/template_renderer/partial_cache.rb,
lib/generators/template_renderer/template_error.rb,
lib/generators/template_renderer/partial_resolver.rb
Overview
Template rendering module for Ruby Raider generators
Provides a clean partial() helper for including ERB templates with:
-
Automatic caching of compiled ERB objects (10x performance improvement)
-
Context-aware path resolution (relative to caller, then all source_paths)
-
Helpful error messages when partials are missing
-
Flexible whitespace handling (trim_mode, strip options)
Usage in templates:
<%= partial('screenshot') %> # Default: trim_mode: '-', no strip
<%= partial('screenshot', strip: true) %> # With .strip!
<%= partial('screenshot', trim: false) %> # No trim_mode
<%= partial('driver_config', trim_mode: '<>') %> # Custom trim_mode
The partial() method automatically has access to all generator instance variables and methods (cucumber?, mobile?, selenium?, etc.) through binding.
Defined Under Namespace
Modules: ClassMethods Classes: PartialCache, PartialResolver, TemplateError, TemplateNotFoundError, TemplateRenderError
Class Method Summary collapse
-
.included(base) ⇒ Object
Module hook for including in classes.
Instance Method Summary collapse
-
#partial(name, options = {}) ⇒ String
Render a partial template with caching and smart path resolution.
Class Method Details
.included(base) ⇒ Object
Module hook for including in classes
67 68 69 |
# File 'lib/generators/template_renderer.rb', line 67 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#partial(name, options = {}) ⇒ String
Render a partial template with caching and smart path resolution
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/generators/template_renderer.rb', line 48 def partial(name, = {}) # Default options = { trim_mode: '-', strip: false, trim: true }.merge() # Handle trim: false by setting trim_mode to nil [:trim_mode] = nil if [:trim] == false # Render the partial through the cache result = self.class.template_renderer.render_partial(name, binding, ) # Apply strip if requested [:strip] ? result.strip : result end |