Module YARD::Templates::Template
In: lib/yard/templates/template.rb

Methods

T   erb   erb_file_for   erb_with   file   include_extra   included   init   inspect   new   options=   run   sections   superb   yieldall  

Included Modules

ErbCache Helpers::BaseHelper Helpers::MethodHelper

Classes and Modules

Module YARD::Templates::Template::ClassMethods

Attributes

class  [RW] 
extra_includes  [RW]  Extra includes are mixins that are included after a template is created. These mixins can be registered by plugins to operate on templates and override behaviour.

Note that this array can be filled with modules or proc objects. If a proc object is given, the proc will be called with the {Template#options} hash containing relevant template information like the object, format, and more. The proc should return a module or nil if there is none.

@example Adding in extra mixins to include on a template

  Template.extra_includes << MyHelper

@example Conditionally including a mixin if the format is html

  Template.extra_includes << proc {|opts| MyHelper if opts.format == :html }

@return [Array<Module, Proc>] a list of modules to be automatically included

  into any new template module
options  [R] 
section  [RW] 

Public Class methods

Includes the {extra_includes} modules into the template object.

@param [Template] template the template object to mixin the extra includes. @param [SymbolHash] options the options hash containing all template information @return [void]

@!parse extend ClassMethods @private

Public Instance methods

Loads a template specified by path. If +:template+ or +:format+ is specified in the {options} hash, they are prepended and appended to the path respectively.

@param [Array<String, Symbol>] path the path of the template @return [Template] the loaded template module

@param [String, Symbol] section the section name @yield calls subsections to be rendered @return [String] the contents of the ERB rendered section

Returns the contents of a file. If allow_inherited is set to true, use +{{{super}}}+ inside the file contents to insert the contents of the file from an inherited template. For instance, if +templates/b+ inherits from +templates/a+ and file "test.css" exists in both directories, both file contents can be retrieved by having +templates/b/test.css+ look like:

  {{{__super__}}}
  ...
  body { css styles here }
  p.class { other styles }

@param [String] basename the name of the file @param [Boolean] allow_inherited whether inherited templates can

  be inserted with +{{{__super__}}}+

@return [String] the contents of a file identified by basename. All

  template paths (including any mixed in templates) are searched for
  the file

@see ClassMethods#find_file @see ClassMethods#find_nth_file

Initialization called on the template. Override this in a ‘setup.rb’ file in the template‘s path to implement a template

@example A default set of sections

  def init
    sections :section1, :section2, [:subsection1, :etc]
  end

@see sections

Runs a template on sects using extra options. This method should not be called directly. Instead, call the class method {ClassMethods#run}

@param [Hash, nil] opts any extra options to apply to sections @param [Section, Array] sects a section list of sections to render @param [Fixnum] start_at the index in the section list to start from @param [Boolean] break_first if true, renders only the first section @yield [opts] calls for the subsections to be rendered @yieldparam [Hash] opts any extra options to yield @return [String] the rendered sections joined together

Sets the sections (and subsections) to be rendered for the template

@example Sets a set of erb sections

  sections :a, :b, :c # searches for a.erb, b.erb, c.erb

@example Sets a set of method and erb sections

  sections :a, :b, :c # a is a method, the rest are erb files

@example Sections with subsections

  sections :header, [:name, :children]
  # the above will call header.erb and only renders the subsections
  # if they are yielded by the template (see #yieldall)

@param [Array<Symbol, String, Template, Array>] args the sections

  to use to render the template. For symbols and strings, the
  section will be executed as a method (if one exists), or rendered
  from the file "name.erb" where name is the section name. For
  templates, they will have {Template::ClassMethods#run} called on them.
  Any subsections can be yielded to using yield or {#yieldall}

Calls the ERB file from the last inherited template with {section}.erb

@param [Symbol, String] section if provided, uses a specific section name @return [String] the rendered ERB file in any of the inherited template

  paths.

Yields all subsections with any extra options

@param [Hash] opts extra options to be applied to subsections

Protected Instance methods

[Validate]