Class: JsFromRoutes::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/js_from_routes/generator.rb

Overview

Internal: Represents a compiled template that can write itself to a file.

Instance Method Summary collapse

Constructor Details

#initialize(template_path) ⇒ Template

Returns a new instance of Template.



98
99
100
101
# File 'lib/js_from_routes/generator.rb', line 98

def initialize(template_path)
  # NOTE: The compiled ERB template, used to generate JS code.
  @compiled_template = Erubi::Engine.new(File.read(template_path), filename: template_path).src
end

Instance Method Details

#write_if_changed(object) ⇒ Object

Public: Checks if the cache is fresh, or renders the template with the specified variables, and writes the updated result to a file.



105
106
107
# File 'lib/js_from_routes/generator.rb', line 105

def write_if_changed(object)
  write_file_if_changed(object.filename, object.cache_key) { render_template(object) }
end