Module: Ronin::Templates::Template
Overview
Instance Method Summary collapse
-
#enter_template(sub_path) {|path| ... } ⇒ Object
protected
Finds the template, pushing the directory that the template resides within to #template_dirs, calls the given block and then pops the directory off of #template_dirs.
-
#find_template(sub_path) ⇒ String?
protected
Finds the template within the #template_dir or uses
DataPaths::Finders#find_data_file
to search through alldata/
directories for the template. -
#read_template(template_path) {|template| ... } ⇒ Object
protected
Finds and reads the contents of a template.
-
#template_dir ⇒ String?
protected
The first path in #template_dirs, that will be used to search for other templates in.
-
#template_dirs ⇒ Array
protected
A stack of directories to search for other templates within.
Instance Method Details
#enter_template(sub_path) {|path| ... } ⇒ Object (protected)
Finds the template, pushing the directory that the template resides within to #template_dirs, calls the given block and then pops the directory off of #template_dirs.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ronin/templates/template.rb', line 118 def enter_template(sub_path) sub_path = sub_path.to_s unless (path = find_template(sub_path)) raise(RuntimeError,"could not find template #{sub_path.dump}") end template_dirs.unshift(File.dirname(path)) result = yield(path) template_dirs.shift return result end |
#find_template(sub_path) ⇒ String? (protected)
Finds the template within the #template_dir or uses
DataPaths::Finders#find_data_file
to search through all
data/
directories for the template.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ronin/templates/template.rb', line 77 def find_template(sub_path) sub_path = sub_path.to_s if template_dir path = File.(File.join(template_dir,sub_path)) return path if File.file?(path) end return find_data_file(sub_path) end |
#read_template(template_path) {|template| ... } ⇒ Object (protected)
Finds and reads the contents of a template.
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ronin/templates/template.rb', line 156 def read_template(template_path) enter_template(template_path) do |path| contents = File.read(path) if block_given? yield(contents) else contents end end end |
#template_dir ⇒ String? (protected)
The first path in #template_dirs, that will be used to search for other templates in.
56 57 58 |
# File 'lib/ronin/templates/template.rb', line 56 def template_dir template_dirs.first end |
#template_dirs ⇒ Array (protected)
A stack of directories to search for other templates within.
42 43 44 |
# File 'lib/ronin/templates/template.rb', line 42 def template_dirs @template_dirs ||= [] end |