Class: Sbuilder::TemplateReader
- Inherits:
-
Object
- Object
- Sbuilder::TemplateReader
- Includes:
- Utils::MyLogger
- Defined in:
- lib/sbuilder/mustache/template_reader.rb
Direct Known Subclasses
Constant Summary collapse
- PROGNAME =
progname for logger use default class name
nil
Constants included from Utils::MyLogger
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
- Sbuilder::Controller
-
set in init.
-
#partials ⇒ Object
writeonly
f: partial-name –> template string.
-
#template_paths ⇒ Object
readonly
instance.
-
#templates ⇒ Object
writeonly
f: template-name –> template string.
Rules to identify template types collapse
-
#show_template(name) ⇒ Boolean
To override in sub-classes.
public services collapse
-
#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.
Special template content collapse
-
#filtered_template ⇒ String
default template when filtered.
Access template files collapse
-
#get_template_filepath(name) ⇒ Object
Path to an existing template file name.
Instance Method Summary collapse
-
#initialize(controller, options = {}) ⇒ TemplateReader
constructor
—————————————————————— Constructor.
Methods included from Utils::MyLogger
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, ={} ) @logger = getLogger( PROGNAME, ) @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
#controller ⇒ Object (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_paths ⇒ Object (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_template ⇒ String
default template when filtered
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
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.
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 "\n No such template '\#{name}' found in directories: \#{@template_paths.join(\", \")}\n \n eos\n \nend\n" |
#show_template(name) ⇒ Boolean
To override in sub-classes
56 57 58 |
# File 'lib/sbuilder/mustache/template_reader.rb', line 56 def show_template( name ) true end |