Module: YARD::Templates::Engine
- Defined in:
- lib/yard/templates/engine.rb
Overview
This module manages all creation, handling and rendering of Template objects.
-
To create a template object at a path, use Engine.template.
-
To render a template, call Engine.render.
-
To register a template path in the lookup paths, call Engine.register_template_path.
Class Attribute Summary collapse
-
.template_paths ⇒ Array<String>
The list of registered template paths.
Class Method Summary collapse
-
.generate(objects, options = {}) ⇒ void
Passes a set of objects to the
:fulldoc
template for full documentation generation. -
.register_template_path(path) ⇒ void
Registers a new template path in Engine.template_paths.
-
.render(options = {}) ⇒ String
Renders a template on a code object using a set of default (overridable) options.
-
.template(*path) ⇒ Template
Creates a template module representing the path.
-
.template!(path, full_paths = nil) ⇒ Template
Forces creation of a template at
path
within afull_path
. -
.with_serializer(object, serializer) { ... } ⇒ Object
Serializes the results of a block with a
serializer
object.
Class Attribute Details
Class Method Details
.generate(objects, options = {}) ⇒ void
This method returns an undefined value.
Passes a set of objects to the :fulldoc
template for full documentation generation. This is called by CLI::Yardoc to most commonly perform HTML documentation generation.
100 101 102 103 104 105 |
# File 'lib/yard/templates/engine.rb', line 100 def generate(objects, = {}) = () .objects = objects .object = Registry.root template(.template, :fulldoc, .format).run() end |
.register_template_path(path) ⇒ void
This method returns an undefined value.
Registers a new template path in template_paths
20 21 22 |
# File 'lib/yard/templates/engine.rb', line 20 def register_template_path(path) template_paths.push(path) unless template_paths.include?(path) end |
.render(options = {}) ⇒ String
Renders a template on a code object using a set of default (overridable) options. Either the :object
or :type
keys must be provided.
If a :serializer
key is provided and :serialize
is not set to false, the rendered contents will be serialized through the Serializers::Base object. See with_serializer.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/yard/templates/engine.rb', line 81 def render( = {}) = () mod = template(.template, .type, .format) if .serializer && .serialize != false with_serializer(.object, .serializer) { mod.run() } else mod.run() end end |
.template(*path) ⇒ Template
Creates a template module representing the path. Searches on disk for the first directory named path
(joined by ‘/’) within the template paths and builds a template module for. All other matching directories in other template paths will be included in the generated module as mixins (for overriding).
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/yard/templates/engine.rb', line 34 def template(*path) from_template = nil from_template = path.shift if path.first.is_a?(Template) path = path.join('/') full_paths = find_template_paths(from_template, path) path = File.cleanpath(path).gsub('../', '') raise ArgumentError, "No such template for #{path}" if full_paths.empty? mod = template!(path, full_paths) mod end |
.template!(path, full_paths = nil) ⇒ Template
Forces creation of a template at path
within a full_path
.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/yard/templates/engine.rb', line 52 def template!(path, full_paths = nil) full_paths ||= [path] full_paths = [full_paths] unless full_paths.is_a?(Array) name = template_module_name(full_paths.first) begin; return const_get(name); rescue NameError; nil end mod = const_set(name, Module.new) mod.send(:include, Template) mod.send(:initialize, path, full_paths) mod end |
.with_serializer(object, serializer) { ... } ⇒ Object
Serializes the results of a block with a serializer
object.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/yard/templates/engine.rb', line 114 def with_serializer(object, serializer) output = nil filename = serializer.serialized_path(object) if serializer.respond_to?(:basepath) filename = File.join(serializer.basepath, filename) end log.capture("Generating #{filename}", nil) do serializer.before_serialize if serializer output = yield if serializer serializer.serialize(object, output) serializer.after_serialize(output) end end output end |