module YARD::Templates::Template::ClassMethods
def S(*args)
- Since: - 0.6.0
Other tags:
- See: Section#initialize -
def S(*args) Section.new(*args) end
def T(*path)
def T(*path) Engine.template(*path) end
def find_file(basename)
- See: find_nth_file -
Returns:
-
(String)- the full path of a file on disk with filename
Parameters:
-
basename(String) -- the filename to search for
def find_file(basename) find_nth_file(basename) end
def find_nth_file(basename, index = 1)
-
(String)- the full path of the nth file on disk with
Parameters:
-
index(Fixnum) -- the nth existing file to return -
basename(String) -- the filename to search for
def find_nth_file(basename, index = 1) n = 1 full_paths.each do |path| file = File.join(path, basename) if File.file?(file) return file if index == n n += 1 end end nil end
def full_paths
- Note: - This method caches path results. Paths should not be modified
Returns:
-
(Array- a list of full paths)
def full_paths reset_full_paths unless defined? @cached_included_modules return @full_paths if included_modules == @cached_included_modules @cached_included_modules = included_modules @full_paths = included_modules.inject([full_path]) do |paths, mod| paths |= mod.full_paths if mod.respond_to?(:full_paths) paths end end
def include_inherited(full_paths)
def include_inherited(full_paths) full_paths.reverse.each do |full_path| include Engine.template!(path, full_path) end end
def include_parent
def include_parent pc = path.to_s.split('/') if pc.size > 1 pc.pop pc = pc.join('/') begin include Engine.template(pc) rescue ArgumentError include Engine.template!(pc, full_path.gsub(%r{/[^/]+$}, '')) end end end
def initialize(path, full_paths)
def initialize(path, full_paths) full_path = full_paths.shift self.path = path self.full_path = full_path include_inherited(full_paths) include_parent load_setup_rb end
def is_a?(klass)
def is_a?(klass) return true if klass == Template super(klass) end
def load_setup_rb
def load_setup_rb setup_file = File.join(full_path, 'setup.rb') if File.file? setup_file setup_code = File.read(setup_file) setup_code.taint if setup_code.respond_to?(:taint) module_eval(setup_code, setup_file, 1) end end
def new(*args)
def new(*args) obj = Object.new.extend(self) obj.class = self obj.send(:initialize, *args) obj end
def reset_full_paths
def reset_full_paths @cached_included_modules = nil end
def run(*args)
def run(*args) new(*args).run end