Class: Yuzu::Core::Template

Inherits:
Object show all
Includes:
Helpers
Defined in:
lib/yuzu/core/template.rb

Direct Known Subclasses

HamlTemplate

Constant Summary collapse

@@template_dir =

TODO Make this part of a module-level config.

Path.new("_templates")

Instance Method Summary collapse

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

#contentsObject



37
38
39
# File 'lib/yuzu/core/template.rb', line 37

def contents
  @contents ||= get_contents
end

#exists?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/yuzu/core/template.rb', line 20

def exists?
  path.exists?
end

#fallback_exists?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/yuzu/core/template.rb', line 33

def fallback_exists?
  fallback_path.exists?
end

#fallback_pathObject



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_contentsObject



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

#pathObject



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