Class: SkeletonLoader::TemplateRenderer
- Inherits:
-
Object
- Object
- SkeletonLoader::TemplateRenderer
- Defined in:
- lib/skeleton_loader/template_renderer.rb
Overview
This class handles rendering templates for skeleton loaders. It retrieves template files and prepares them for display as placeholders.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(template_path, options = {}) ⇒ TemplateRenderer
constructor
A new instance of TemplateRenderer.
- #render ⇒ Object
Constructor Details
#initialize(template_path, options = {}) ⇒ TemplateRenderer
Returns a new instance of TemplateRenderer.
13 14 15 16 17 18 19 20 21 |
# File 'lib/skeleton_loader/template_renderer.rb', line 13 def initialize(template_path, = {}) @template_path = template_path @options = () # Dynamically set instance variables for template rendering @options.each do |key, value| instance_variable_set("@#{key}", value) end end |
Class Method Details
.render(template_path, options = {}) ⇒ Object
9 10 11 |
# File 'lib/skeleton_loader/template_renderer.rb', line 9 def self.render(template_path, = {}) new(template_path, ).render end |
Instance Method Details
#render ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/skeleton_loader/template_renderer.rb', line 23 def render template_content = File.read(@template_path) erb = ERB.new(template_content) erb.result(binding) rescue StandardError => e raise "Error rendering template at #{@template_path}: #{e.}" end |