Class: SkeletonLoader::TemplateRenderer

Inherits:
Object
  • Object
show all
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

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, options = {})
  @template_path = template_path
  @options = merge_options(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, options = {})
  new(template_path, options).render
end

Instance Method Details

#renderObject



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.message}"
end