Class: Sbuilder::TemplateReader

Inherits:
Object
  • Object
show all
Includes:
Utils::MyLogger
Defined in:
lib/sbuilder/mustache/template_reader.rb

Direct Known Subclasses

TemplateContextReader

Constant Summary collapse

PROGNAME =

progname for logger use default class name

nil

Constants included from Utils::MyLogger

Utils::MyLogger::LOGFILE

Instance Attribute Summary collapse

Rules to identify template types collapse

public services collapse

Special template content collapse

Access template files collapse

Instance Method Summary collapse

Methods included from Utils::MyLogger

#getLogger, #logfile

Constructor Details

#initialize(controller, options = {}) ⇒ TemplateReader


Constructor



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sbuilder/mustache/template_reader.rb', line 32

def initialize( controller, options={} )
  @logger = getLogger( PROGNAME, options )
  @logger.info( "#{__method__} created, options='#{options}" )

  @controller = controller

  # use default templates - prefix with user specified templates
  # @template_paths = options[:default_templates] || []
  # # for mustache templates
  # if options[:templates] then
  #   @template_paths = options[:templates] + (options[:default_templates] || [] )
  # end
  @template_paths = controller.templateRenderDirectories
end

Instance Attribute Details

#controllerObject (readonly)

Sbuilder::Controller

set in init



26
27
28
# File 'lib/sbuilder/mustache/template_reader.rb', line 26

def controller
  @controller
end

#partials=(value) ⇒ Object (writeonly)

f: partial-name –> template string



22
23
24
# File 'lib/sbuilder/mustache/template_reader.rb', line 22

def partials=(value)
  @partials = value
end

#template_pathsObject (readonly)

instance



21
22
23
# File 'lib/sbuilder/mustache/template_reader.rb', line 21

def template_paths
  @template_paths
end

#templates=(value) ⇒ Object (writeonly)

f: template-name –> template string



23
24
25
# File 'lib/sbuilder/mustache/template_reader.rb', line 23

def templates=(value)
  @templates = value
end

Instance Method Details

#filtered_templateString

default template when filtered

Returns:

  • (String)

    emptpy string for filtered templtae



96
97
98
# File 'lib/sbuilder/mustache/template_reader.rb', line 96

def filtered_template
  ""
end

#get_template(name) ⇒ String

Check whether template ‘name’ should be be shown, next resolve location of a template file, and do ‘File.read’ on the file path

Returns:

  • (String)

    for template content



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sbuilder/mustache/template_reader.rb', line 74

def get_template( name )

  if !show_template( name )
    @logger.info( "#{__method__} filtered, name=#{name}" )
    return filtered_template
  end

  template_file = get_template_filepath( name )
  @logger.info( "#{__method__} read template_file=#{template_file}" )
  #File.read( template_file )
  template_read( template_file )

end

#get_template_filepath(name) ⇒ Object

Returns path to an existing template file name.

Returns:

  • path to an existing template file name



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/sbuilder/mustache/template_reader.rb', line 111

def get_template_filepath( name ) 

  @template_paths.each do |directory_or_gemname|
    
    template_path = get_template_filepath_resolve( directory_or_gemname, name ) 
    return template_path if template_path && File.exists?( template_path ) && File.file?( template_path )

  end # each 


  # could not find 
  
  raise <<-eos

      No such template '#{name}' found in directories: #{@template_paths.join(", ")}
    
    eos
  
end

#show_template(name) ⇒ Boolean

To override in sub-classes

Returns:

  • (Boolean)

    true - show allways



56
57
58
# File 'lib/sbuilder/mustache/template_reader.rb', line 56

def show_template( name )
  true
end