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
"treader"
Constants included from Utils::MyLogger
Instance Attribute Summary collapse
-
#partials ⇒ Object
writeonly
f: partial-name –> template string.
-
#template_paths ⇒ Object
readonly
instance.
-
#templates ⇒ Object
writeonly
f: template-name –> template string.
Instance Method Summary collapse
-
#filtered_template ⇒ String
default template when filtered.
-
#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.
-
#get_template_filepath(name) ⇒ Object
return path to an existing template file name.
-
#initialize(controller, options = {}) ⇒ TemplateReader
constructor
—————————————————————— Constructor.
-
#show_template(name) ⇒ Boolean
To override in sub-classes.
-
#template_read(path) ⇒ String
For template content.
Methods included from Utils::MyLogger
Constructor Details
#initialize(controller, options = {}) ⇒ TemplateReader
Constructor
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sbuilder/mustache/template_reader.rb', line 28 def initialize( controller, ={} ) @logger = getLogger( PROGNAME, ) @logger.info( "#{__method__} created, options='#{options}" ) # use default templates - prefix with user specified templates @template_paths = [:default_templates] # for mustache templates if [:templates] then @template_paths = [:templates] + ([:default_templates] || [] ) end # # init partial cache # @partials = {} end |
Instance Attribute Details
#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
65 66 67 |
# File 'lib/sbuilder/mustache/template_reader.rb', line 65 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
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/sbuilder/mustache/template_reader.rb', line 85 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
return path to an existing template file name
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/sbuilder/mustache/template_reader.rb', line 110 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 ) 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
72 73 74 |
# File 'lib/sbuilder/mustache/template_reader.rb', line 72 def show_template( name ) true end |
#template_read(path) ⇒ String
Returns for template content.
101 102 103 |
# File 'lib/sbuilder/mustache/template_reader.rb', line 101 def template_read( path ) File.read( path ) end |