Class: Prmd::Template Private

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

Class Method Details

.clear_cachevoid

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

Parameters:

  • path (String)
  • base (String)

Returns:

  • (Erubis::Eruby)

    eruby template



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.

Parameters:

  • filename (String)

Returns:

  • (Object)

    data



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.

Parameters:

  • path (String)
  • base (String)

Returns:

  • (Erubis::Eruby)

    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

Parameters:

  • path (String)
  • base (String)

Returns:

  • (String)

    result from template render



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_dirnameString

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.

Returns:

  • (String)

    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.

Parameters:

  • args (String)

Returns:

  • (String)

    path in prmd’s template directory



19
20
21
# File 'lib/prmd/template.rb', line 19

def self.template_path(*args)
  File.expand_path(File.join(*args), template_dirname)
end