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

Defined in:
lib/yard/templates/template.rb

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

- (Object) full_path

Returns the value of attribute full_path



25
26
27
# File 'lib/yard/templates/template.rb', line 25

def full_path
  @full_path
end

- (Object) path

Returns the value of attribute path



25
26
27
# File 'lib/yard/templates/template.rb', line 25

def path
  @path
end

Instance Method Details

- (String) find_file(basename)

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.

Parameters:

  • (String) basename — 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:

  • find_nth_file


51
52
53
# File 'lib/yard/templates/template.rb', line 51

def find_file(basename)
  find_nth_file(basename)
end

- (String) find_nth_file(basename, index = 1)

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

Parameters:

  • (String) basename — the filename to search for
  • (Fixnum) index (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


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/yard/templates/template.rb', line 62

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

- (Object) full_paths



27
28
29
30
31
32
# File 'lib/yard/templates/template.rb', line 27

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

- (ClassMethods) initialize(path, full_paths)

A new instance of ClassMethods



34
35
36
37
38
39
40
41
# File 'lib/yard/templates/template.rb', line 34

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

- (Boolean) is_a?(klass)

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/yard/templates/template.rb', line 75

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

- (Object) new(*args)

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



81
82
83
84
85
86
# File 'lib/yard/templates/template.rb', line 81

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

- (Object) run(*args)



88
89
90
# File 'lib/yard/templates/template.rb', line 88

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

- (Object) T(*path)



92
93
94
# File 'lib/yard/templates/template.rb', line 92

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