Module: YARD::Templates::Template::ClassMethods
- Included in:
- YARD::Templates::Template
- Defined in:
- lib/yard/templates/template.rb
Instance Attribute Summary collapse
-
#full_path ⇒ Object
Returns the value of attribute full_path.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#find_file(basename) ⇒ String
Searches for a file identified by
basename
in the template’s path as well as any mixed in template paths. -
#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. -
#full_paths ⇒ Array<String>
A list of full paths.
- #initialize(path, full_paths) ⇒ Object
- #is_a?(klass) ⇒ Boolean
-
#new(*args) ⇒ Object
Creates a new template object to be rendered with #run.
-
#reset_full_paths ⇒ Object
Resets cache for #full_paths.
- #run(*args) ⇒ Object
-
#S(*args) ⇒ Object
Alias for creating a Section with arguments.
-
#T(*path) ⇒ Object
Alias for creating Engine.template.
Instance Attribute Details
#full_path ⇒ Object
Returns the value of attribute full_path.
60 61 62 |
# File 'lib/yard/templates/template.rb', line 60 def full_path @full_path end |
#path ⇒ Object
Returns the value of attribute path.
60 61 62 |
# File 'lib/yard/templates/template.rb', line 60 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.
98 99 100 |
# File 'lib/yard/templates/template.rb', line 98 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.
109 110 111 112 113 114 115 116 117 118 119 120 |
# 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 ⇒ Array<String>
This method caches path results. Paths should not be modified after this method is called; call #reset_full_paths to reset cache.
Returns a list of full paths.
65 66 67 68 69 70 71 72 73 74 |
# 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 |
#initialize(path, full_paths) ⇒ Object
81 82 83 84 85 86 87 88 |
# 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 |
#is_a?(klass) ⇒ Boolean
122 123 124 125 |
# File 'lib/yard/templates/template.rb', line 122 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
128 129 130 131 132 133 |
# 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 ⇒ Object
Resets cache for #full_paths
77 78 79 |
# File 'lib/yard/templates/template.rb', line 77 def reset_full_paths @cached_included_modules = nil end |
#run(*args) ⇒ Object
135 136 137 |
# File 'lib/yard/templates/template.rb', line 135 def run(*args) new(*args).run end |
#S(*args) ⇒ Object
Alias for creating a Section with arguments
149 150 151 |
# File 'lib/yard/templates/template.rb', line 149 def S(*args) Section.new(*args) end |
#T(*path) ⇒ Object
Alias for creating Engine.template.
142 143 144 |
# File 'lib/yard/templates/template.rb', line 142 def T(*path) Engine.template(*path) end |