lib/yard/templates/engine.rb in yard-0.5.8 vs lib/yard/templates/engine.rb in yard-0.6.0
- old
+ new
@@ -1,7 +1,15 @@
+require 'ostruct'
+
module YARD
module Templates
+ # This module manages all creation, handling and rendering of {Engine::Template}
+ # objects.
+ #
+ # * To create a template object at a path, use {template}.
+ # * To render a template, call {render}.
+ # * To register a template path in the lookup paths, call {register_template_path}.
module Engine
class << self
# @return [Array<String>] the list of registered template paths
attr_accessor :template_paths
@@ -18,10 +26,12 @@
# 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).
#
# @param [Array<String, Symbol>] path a list of path components
+ # @raise [ArgumentError] if the path does not exist within one of the
+ # {template_paths} on disk.
# @return [Template] the module representing the template
def template(*path)
from_template = nil
from_template = path.shift if path.first.is_a?(Template)
path = path.join('/')
@@ -41,11 +51,11 @@
# @return [Template] the template module representing the +path+
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
+ begin; return const_get(name); rescue NameError; end
mod = const_set(name, Module.new)
mod.send(:include, Template)
mod.send(:initialize, path, full_paths)
mod
@@ -118,9 +128,10 @@
# @option options [Symbol] :format (:text) the default format
# @option options [Symbol] :type (nil) the :object's type, if provided
# @option options [Symbol] :template (:default) the default template
# @return [void]
def set_default_options(options = {})
+ options[:__globals] ||= OpenStruct.new
options[:format] ||= :text
options[:type] ||= options[:object].type if options[:object]
options[:template] ||= :default
end