Module: YARD::Templates::Template::ClassMethods

Included in:
YARD::Templates::Template
Defined in:
lib/yard/templates/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#full_pathObject

Returns the value of attribute full_path.



59
60
61
# File 'lib/yard/templates/template.rb', line 59

def full_path
  @full_path
end

#pathObject

Returns the value of attribute path.



59
60
61
# File 'lib/yard/templates/template.rb', line 59

def path
  @path
end

Instance Method Details

#find_file(basename) ⇒ String

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

Parameters:

  • basename (String)

    the filename to search for

Returns:

  • (String)

    the full path of a file on disk with filename basename in one of the template’s paths.

See Also:



85
86
87
# File 'lib/yard/templates/template.rb', line 85

def find_file(basename)
  find_nth_file(basename)
end

#find_nth_file(basename, index = 1) ⇒ String

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

Parameters:

  • basename (String)

    the filename to search for

  • index (Fixnum) (defaults to: 1)

    the nth existing file to return

Returns:

  • (String)

    the full path of the nth file on disk with filename basename in one of the template paths



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/yard/templates/template.rb', line 96

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_pathsObject



61
62
63
64
65
66
# File 'lib/yard/templates/template.rb', line 61

def full_paths
  included_modules.inject([full_path]) do |paths, mod|
    paths |= mod.full_paths if mod.respond_to?(:full_paths)
    paths
  end
end

#initialize(path, full_paths) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/yard/templates/template.rb', line 68

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

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/yard/templates/template.rb', line 109

def is_a?(klass)
  return true if klass == Template
  super(klass)
end

#new(*args) ⇒ Object

Creates a new template object to be rendered with YARD::Templates::Template#run



115
116
117
118
119
120
# File 'lib/yard/templates/template.rb', line 115

def new(*args)
  obj = Object.new.extend(self)
  obj.class = self
  obj.send(:initialize, *args)
  obj
end

#run(*args) ⇒ Object



122
123
124
# File 'lib/yard/templates/template.rb', line 122

def run(*args)
  new(*args).run
end

#S(*args) ⇒ Object

Alias for creating a Section with arguments

See Also:

Since:

  • 0.6.0



133
134
135
# File 'lib/yard/templates/template.rb', line 133

def S(*args)
  Section.new(*args)
end

#T(*path) ⇒ Object



126
127
128
# File 'lib/yard/templates/template.rb', line 126

def T(*path)
  Engine.template(*path)
end