Class: Yuzu::Core::Template
- Includes:
- Helpers
- Defined in:
- lib/yuzu/core/template.rb
Direct Known Subclasses
Constant Summary collapse
Instance Method Summary collapse
- #contents ⇒ Object
- #exists? ⇒ Boolean
- #fallback_exists? ⇒ Boolean
- #fallback_path ⇒ Object
- #get_contents ⇒ Object
- #get_template_contents(file_path) ⇒ Object
-
#initialize(template_name) ⇒ Template
constructor
template_name – String.
- #path ⇒ Object
- #render(website_file, data = {}) ⇒ Object
Constructor Details
#initialize(template_name) ⇒ Template
template_name – String. The filename of the template, e.g. _gallery.haml
12 13 14 |
# File 'lib/yuzu/core/template.rb', line 12 def initialize(template_name) @template_name = template_name end |
Instance Method Details
#contents ⇒ Object
37 38 39 |
# File 'lib/yuzu/core/template.rb', line 37 def contents @contents ||= get_contents end |
#exists? ⇒ Boolean
20 21 22 |
# File 'lib/yuzu/core/template.rb', line 20 def exists? path.exists? end |
#fallback_exists? ⇒ Boolean
33 34 35 |
# File 'lib/yuzu/core/template.rb', line 33 def fallback_exists? fallback_path.exists? end |
#fallback_path ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/yuzu/core/template.rb', line 24 def fallback_path # TODO Configure fallbacks in a more general way. if @template_name[0].chr == "_" @@template_dir + "_block.haml" else @@template_dir + "generic.haml" end end |
#get_contents ⇒ Object
41 42 43 44 |
# File 'lib/yuzu/core/template.rb', line 41 def get_contents tr = get_template_contents(path) tr.nil? ? get_template_contents(fallback_path) : tr end |
#get_template_contents(file_path) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/yuzu/core/template.rb', line 46 def get_template_contents(file_path) if file_path.exists? f = File.open(file_path.absolute, 'r') contents = f.read f.close contents else $stderr.puts "WARNING: Couldn't find template #{file_path}" nil end end |
#path ⇒ Object
16 17 18 |
# File 'lib/yuzu/core/template.rb', line 16 def path @@template_dir + @template_name end |
#render(website_file, data = {}) ⇒ Object
58 59 60 |
# File 'lib/yuzu/core/template.rb', line 58 def render(website_file, data={}) "" end |