Module: YARD::Templates::Engine
- Defined in:
- lib/yard/templates/engine.rb
Class Attribute Summary
- + (Array<String>) template_paths The list of registered template paths.
Class Method Summary
- + (void) generate(objects, options = {}) Passes a set of objects to the :fulldoc template for full documentation generation.
- + (void) register_template_path(path) Registers a new template path in template_paths.
- + (String) render(options = {}) Renders a template on a code object using a set of default (overridable) options.
- + (Template) template(*path) Creates a template module representing the path.
- + (Template) template!(path, full_paths = nil) Forces creation of a template at path within a full_path.
- + (Object) with_serializer(object, serializer, &block) { ... } Serializes the results of a block with a serializer object.
Class Attribute Details
Class Method Details
+ (void) generate(objects, options = {})
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.
90 91 92 93 94 |
# File 'lib/yard/templates/engine.rb', line 90 def generate(objects, = {}) () [:objects] = objects template([:template], :fulldoc, [:format]).run() end |
+ (void) register_template_path(path)
This method returns an undefined value.
Registers a new template path in template_paths
12 13 14 |
# File 'lib/yard/templates/engine.rb', line 12 def register_template_path(path) template_paths.push path end |
+ (String) render(options = {})
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.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/yard/templates/engine.rb', line 71 def render( = {}) () mod = template([:template], [:type], [:format]) if [:serialize] != false with_serializer([:object], [:serializer]) { mod.run() } else mod.run() end end |
+ (Template) template(*path)
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).
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/yard/templates/engine.rb', line 24 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) template!(path, full_paths = nil)
Forces creation of a template at path within a full_path.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/yard/templates/engine.rb', line 42 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) return const_get(name) rescue NameError mod = const_set(name, Module.new) mod.send(:include, Template) mod.send(:initialize, path, full_paths) mod end |
+ (Object) with_serializer(object, serializer, &block) { ... }
Serializes the results of a block with a serializer object.
103 104 105 106 107 108 109 110 111 |
# File 'lib/yard/templates/engine.rb', line 103 def with_serializer(object, serializer, &block) serializer.before_serialize if serializer output = yield if serializer serializer.serialize(object, output) serializer.after_serialize(output) end output end |