module YARD::Templates::Template::ClassMethods

Attributes

full_path[RW]
path[RW]

Public Class Methods

new(path, full_paths) click to toggle source
# File lib/yard/templates/template.rb, line 81
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

Public Instance Methods

S(*args) click to toggle source

Alias for creating a {Section} with arguments @see Section#initialize @since 0.6.0

# File lib/yard/templates/template.rb, line 149
def S(*args)
  Section.new(*args)
end
T(*path) click to toggle source

Alias for creating {Engine.template}.

# File lib/yard/templates/template.rb, line 142
def T(*path)
  Engine.template(*path)
end
find_file(basename) click to toggle source

Searches for a file identified by basename in the template’s path as well as any mixed in template paths. Equivalent to calling {ClassMethods#find_nth_file} with index of 1.

@param [String] basename the filename to search for @return [String] the full path of a file on disk with filename

+basename+ in one of the template's paths.

@see find_nth_file

# File lib/yard/templates/template.rb, line 98
def find_file(basename)
  find_nth_file(basename)
end
find_nth_file(basename, index = 1) click to toggle source

Searches for the nth file (where n = index) identified by basename in the template’s path and any mixed in template paths.

@param [String] basename the filename to search for @param [Fixnum] index the nth existing file to return @return [String] the full path of the nth file on disk with

filename +basename+ in one of the template paths
# File lib/yard/templates/template.rb, line 109
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
full_paths() click to toggle source

@return [Array<String>] a list of full paths @note This method caches path results. Paths should not be modified

after this method is called; call {#reset_full_paths} to reset cache.
# File lib/yard/templates/template.rb, line 65
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
is_a?(klass) click to toggle source
Calls superclass method
# File lib/yard/templates/template.rb, line 122
def is_a?(klass)
  return true if klass == Template
  super(klass)
end
new(*args) click to toggle source

Creates a new template object to be rendered with {Template#run}

# File lib/yard/templates/template.rb, line 128
def new(*args)
  obj = Object.new.extend(self)
  obj.class = self
  obj.send(:initialize, *args)
  obj
end
reset_full_paths() click to toggle source

Resets cache for {#full_paths}

# File lib/yard/templates/template.rb, line 77
def reset_full_paths
  @cached_included_modules = nil
end
run(*args) click to toggle source
# File lib/yard/templates/template.rb, line 135
def run(*args)
  new(*args).run
end

Private Instance Methods

include_inherited(full_paths) click to toggle source
# File lib/yard/templates/template.rb, line 170
def include_inherited(full_paths)
  full_paths.reverse.each do |full_path|
    include Engine.template!(path, full_path)
  end
end
include_parent() click to toggle source

rubocop:enable Style/MethodName

# File lib/yard/templates/template.rb, line 157
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
load_setup_rb() click to toggle source
# File lib/yard/templates/template.rb, line 176
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