Class: Prmd::Template Private
- Inherits:
-
Object
- Object
- Prmd::Template
- Defined in:
- lib/prmd/template.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Template management
Class Method Summary collapse
-
.clear_cache ⇒ void
private
Clear internal template cache.
-
.load(path, base) ⇒ Erubis::Eruby
private
Attempts to load a template from the given path and base, if the template was previously loaded, the cached template is returned instead.
-
.load_json(filename) ⇒ Object
private
Load a JSON file from prmd’s templates directory.
-
.load_template(path, base) ⇒ Erubis::Eruby
private
Eruby template.
-
.render(path, base, *args, &block) ⇒ String
private
Render a template given args or block.
-
.template_dirname ⇒ String
private
Location of the prmd templates directory.
-
.template_path(*args) ⇒ String
private
Path in prmd’s template directory.
Class Method Details
.clear_cache ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Clear internal template cache
26 27 28 |
# File 'lib/prmd/template.rb', line 26 def self.clear_cache @cache.clear end |
.load(path, base) ⇒ Erubis::Eruby
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Attempts to load a template from the given path and base, if the template was previously loaded, the cached template is returned instead
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/prmd/template.rb', line 36 def self.load(path, base) @cache[[path, base]] ||= begin fallback = template_path resolved = File.join(base, path) unless File.exist?(resolved) resolved = File.join(fallback, path) end Erubis::Eruby.new(File.read(resolved), filename: resolved) end end |
.load_json(filename) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load a JSON file from prmd’s templates directory. These files are not cached and are intended to be loaded on demand.
72 73 74 |
# File 'lib/prmd/template.rb', line 72 def self.load_json(filename) JSON.parse(File.read(template_path(filename))) end |
.load_template(path, base) ⇒ Erubis::Eruby
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns eruby template.
53 54 55 |
# File 'lib/prmd/template.rb', line 53 def self.load_template(path, base) load(path, base) end |
.render(path, base, *args, &block) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render a template given args or block. args and block are passed to the template
63 64 65 |
# File 'lib/prmd/template.rb', line 63 def self.render(path, base, *args, &block) load_template(path, base).result(*args, &block) end |
.template_dirname ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns location of the prmd templates directory.
13 14 15 |
# File 'lib/prmd/template.rb', line 13 def self.template_dirname File.join(File.dirname(__FILE__), 'templates') end |
.template_path(*args) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns path in prmd’s template directory.
19 20 21 |
# File 'lib/prmd/template.rb', line 19 def self.template_path(*args) File.(File.join(*args), template_dirname) end |