### Home Classes Methods

### In Files

- lib/yard/templates/template.rb

### Namespace

- MODULE YARD::Templates::Template::ClassMethods

### Methods

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

### Included Modules

- YARD::Templates::ErbCache
- YARD::Templates::Helpers::BaseHelper
- YARD::Templates::Helpers::MethodHelper

### Files

- LICENSE.txt
- MIT.txt

### Class/Module Index

Quicksearch

- YARD
- YARD::CLI
- YARD::CLI::Command
- YARD::CLI::CommandParser
- YARD::CLI::Config
- YARD::CLI::Diff
- YARD::CLI::Gems
- YARD::CLI::Graph
- YARD::CLI::GraphOptions
- YARD::CLI::Help
- YARD::CLI::I18n
- YARD::CLI::List
- YARD::CLI::Server
- YARD::CLI::Stats
- YARD::CLI::YRI
- YARD::CLI::Yardoc
- YARD::CLI::YardocOptions
- YARD::CodeObjects
- YARD::CodeObjects::Base
- YARD::CodeObjects::ClassObject
- YARD::CodeObjects::ClassVariableObject
- YARD::CodeObjects::CodeObjectList
- YARD::CodeObjects::ConstantObject
- YARD::CodeObjects::ExtendedMethodObject
- YARD::CodeObjects::ExtraFileObject
- YARD::CodeObjects::MacroObject
- YARD::CodeObjects::MethodObject
- YARD::CodeObjects::ModuleObject
- YARD::CodeObjects::NamespaceObject
- YARD::CodeObjects::Proxy
- YARD::CodeObjects::ProxyMethodError
- YARD::CodeObjects::RootObject
- YARD::Config
- YARD::Docstring
- YARD::DocstringParser
- YARD::Handlers
- YARD::Handlers::Base
- YARD::Handlers::C
- YARD::Handlers::C::AliasHandler
- YARD::Handlers::C::AttributeHandler
- YARD::Handlers::C::Base
- YARD::Handlers::C::ClassHandler
- YARD::Handlers::C::ConstantHandler
- YARD::Handlers::C::HandlerMethods
- YARD::Handlers::C::InitHandler
- YARD::Handlers::C::MethodHandler
- YARD::Handlers::C::MixinHandler
- YARD::Handlers::C::ModuleHandler
- YARD::Handlers::C::OverrideCommentHandler
- YARD::Handlers::C::PathHandler
- YARD::Handlers::C::StructHandler
- YARD::Handlers::C::SymbolHandler
- YARD::Handlers::NamespaceMissingError
- YARD::Handlers::Processor
- YARD::Handlers::Ruby
- YARD::Handlers::Ruby::AliasHandler
- YARD::Handlers::Ruby::AttributeHandler
- YARD::Handlers::Ruby::Base
- YARD::Handlers::Ruby::ClassConditionHandler
- YARD::Handlers::Ruby::ClassHandler
- YARD::Handlers::Ruby::ClassVariableHandler
- YARD::Handlers::Ruby::CommentHandler
- YARD::Handlers::Ruby::ConstantHandler
- YARD::Handlers::Ruby::DSLHandler
- YARD::Handlers::Ruby::DSLHandlerMethods
- YARD::Handlers::Ruby::ExceptionHandler
- YARD::Handlers::Ruby::ExtendHandler
- YARD::Handlers::Ruby::HandlesExtension
- YARD::Handlers::Ruby::Legacy
- YARD::Handlers::Ruby::Legacy::AliasHandler
- YARD::Handlers::Ruby::Legacy::AttributeHandler
- YARD::Handlers::Ruby::Legacy::Base
- YARD::Handlers::Ruby::Legacy::ClassConditionHandler
- YARD::Handlers::Ruby::Legacy::ClassHandler
- YARD::Handlers::Ruby::Legacy::ClassVariableHandler
- YARD::Handlers::Ruby::Legacy::CommentHandler
- YARD::Handlers::Ruby::Legacy::ConstantHandler
- YARD::Handlers::Ruby::Legacy::DSLHandler
- YARD::Handlers::Ruby::Legacy::ExceptionHandler
- YARD::Handlers::Ruby::Legacy::ExtendHandler
- YARD::Handlers::Ruby::Legacy::MethodHandler
- YARD::Handlers::Ruby::Legacy::MixinHandler
- YARD::Handlers::Ruby::Legacy::ModuleFunctionHandler
- YARD::Handlers::Ruby::Legacy::ModuleHandler
- YARD::Handlers::Ruby::Legacy::PrivateConstantHandler
- YARD::Handlers::Ruby::Legacy::VisibilityHandler
- YARD::Handlers::Ruby::Legacy::YieldHandler
- YARD::Handlers::Ruby::MethodCallWrapper
- YARD::Handlers::Ruby::MethodConditionHandler
- YARD::Handlers::Ruby::MethodHandler
- YARD::Handlers::Ruby::MixinHandler
- YARD::Handlers::Ruby::ModuleFunctionHandler
- YARD::Handlers::Ruby::ModuleHandler
- YARD::Handlers::Ruby::PrivateConstantHandler
- YARD::Handlers::Ruby::StructHandlerMethods
- YARD::Handlers::Ruby::TestNodeWrapper
- YARD::Handlers::Ruby::VisibilityHandler
- YARD::Handlers::Ruby::YieldHandler
- YARD::I18n
- YARD::I18n::Locale
- YARD::I18n::Message
- YARD::I18n::Messages
- YARD::I18n::PotGenerator
- YARD::I18n::Text
- YARD::Logger
- YARD::Options
- YARD::Parser
- YARD::Parser::Base
- YARD::Parser::C
- YARD::Parser::C::BodyStatement
- YARD::Parser::C::CParser
- YARD::Parser::C::Comment
- YARD::Parser::C::CommentParser
- YARD::Parser::C::Statement
- YARD::Parser::C::ToplevelStatement
- YARD::Parser::OrderedParser
- YARD::Parser::ParserSyntaxError
- YARD::Parser::Ruby
- YARD::Parser::Ruby::AstNode
- YARD::Parser::Ruby::ClassNode
- YARD::Parser::Ruby::CommentNode
- YARD::Parser::Ruby::ConditionalNode
- YARD::Parser::Ruby::KeywordNode
- YARD::Parser::Ruby::Legacy
- YARD::Parser::Ruby::Legacy::RubyLex
- YARD::Parser::Ruby::Legacy::RubyLex::BufferedReader
- YARD::Parser::Ruby::Legacy::RubyParser
- YARD::Parser::Ruby::Legacy::RubyToken
- YARD::Parser::Ruby::Legacy::RubyToken::TkBlockContents
- YARD::Parser::Ruby::Legacy::RubyToken::TkError
- YARD::Parser::Ruby::Legacy::RubyToken::TkId
- YARD::Parser::Ruby::Legacy::RubyToken::TkKW
- YARD::Parser::Ruby::Legacy::RubyToken::TkNode
- YARD::Parser::Ruby::Legacy::RubyToken::TkOPASGN
- YARD::Parser::Ruby::Legacy::RubyToken::TkOp
- YARD::Parser::Ruby::Legacy::RubyToken::TkStatementEnd
- YARD::Parser::Ruby::Legacy::RubyToken::TkUnknownChar
- YARD::Parser::Ruby::Legacy::RubyToken::TkVal
- YARD::Parser::Ruby::Legacy::RubyToken::TkWhitespace
- YARD::Parser::Ruby::Legacy::RubyToken::Token
- YARD::Parser::Ruby::Legacy::Statement
- YARD::Parser::Ruby::Legacy::StatementList
- YARD::Parser::Ruby::Legacy::TokenList
- YARD::Parser::Ruby::LiteralNode
- YARD::Parser::Ruby::LoopNode
- YARD::Parser::Ruby::MethodCallNode
- YARD::Parser::Ruby::MethodDefinitionNode
- YARD::Parser::Ruby::ModuleNode
- YARD::Parser::Ruby::ParameterNode
- YARD::Parser::Ruby::ReferenceNode
- YARD::Parser::Ruby::RipperParser
- YARD::Parser::Ruby::RubyParser
- YARD::Parser::SourceParser
- YARD::Parser::UndocumentableError
- YARD::Rake
- YARD::Rake::YardocTask
- YARD::Registry
- YARD::RegistryStore
- YARD::Serializers
- YARD::Serializers::Base
- YARD::Serializers::FileSystemSerializer
- YARD::Serializers::ProcessSerializer
- YARD::Serializers::StdoutSerializer
- YARD::Serializers::YardocSerializer
- YARD::Server
- YARD::Server::Adapter
- YARD::Server::Commands
- YARD::Server::Commands::Base
- YARD::Server::Commands::DisplayFileCommand
- YARD::Server::Commands::DisplayObjectCommand
- YARD::Server::Commands::FramesCommand
- YARD::Server::Commands::LibraryCommand
- YARD::Server::Commands::LibraryIndexCommand
- YARD::Server::Commands::LibraryOptions
- YARD::Server::Commands::ListCommand
- YARD::Server::Commands::SearchCommand
- YARD::Server::Commands::StaticFileCommand
- YARD::Server::DocServerHelper
- YARD::Server::DocServerSerializer
- YARD::Server::FinishRequest
- YARD::Server::LibraryNotPreparedError
- YARD::Server::LibraryVersion
- YARD::Server::NotFoundError
- YARD::Server::RackAdapter
- YARD::Server::RackMiddleware
- YARD::Server::Router
- YARD::Server::StaticCaching
- YARD::Server::WebrickAdapter
- YARD::Server::WebrickServlet
- YARD::StubProxy
- YARD::Tags
- YARD::Tags::AttributeDirective
- YARD::Tags::DefaultFactory
- YARD::Tags::DefaultTag
- YARD::Tags::Directive
- YARD::Tags::EndGroupDirective
- YARD::Tags::GroupDirective
- YARD::Tags::Library
- YARD::Tags::MacroDirective
- YARD::Tags::MethodDirective
- YARD::Tags::OptionTag
- YARD::Tags::OverloadTag
- YARD::Tags::ParseDirective
- YARD::Tags::RefTag
- YARD::Tags::RefTagList
- YARD::Tags::ScopeDirective
- YARD::Tags::Tag
- YARD::Tags::TagFormatError
- YARD::Tags::VisibilityDirective
- YARD::Templates
- YARD::Templates::Engine
- YARD::Templates::ErbCache
- YARD::Templates::Helpers
- YARD::Templates::Helpers::BaseHelper
- YARD::Templates::Helpers::FilterHelper
- YARD::Templates::Helpers::HtmlHelper
- YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
- YARD::Templates::Helpers::Markup
- YARD::Templates::Helpers::Markup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::MarkupHelper
- YARD::Templates::Helpers::MethodHelper
- YARD::Templates::Helpers::ModuleHelper
- YARD::Templates::Helpers::TextHelper
- YARD::Templates::Helpers::UMLHelper
- YARD::Templates::Section
- YARD::Templates::Template
- YARD::Templates::Template::ClassMethods
- YARD::Templates::TemplateOptions
- YARD::Verifier
- Gem
- Gem::DocManager
- Gem::SourceIndex
- Gem::Specification
- Rack
- Rack::Request
- WEBrick
- WEBrick::HTTPRequest
- Array
- File
- Hash
- Insertion
- Module
- Object
- String
- SymbolHash

No matching classes.

# YARD::Templates::Template

### Attributes

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

class[RW]
options[R]
section[RW]

### Public Class Methods

include_extra(template, options) click to toggle source

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]

    # File lib/yard/templates/template.rb, line 37
    def include_extra(template, options)
      extra_includes.each do |mod|
        mod = mod.call(options) if mod.is_a?(Proc)
        next unless mod.is_a?(Module)
        template.extend(mod)
      end
    end

included(klass) click to toggle source

@!parse extend ClassMethods @private

    # File lib/yard/templates/template.rb, line 28
    def included(klass)
      klass.extend(ClassMethods)
    end

new(opts = TemplateOptions.new) click to toggle source

    # File lib/yard/templates/template.rb, line 166
    def initialize(opts = TemplateOptions.new)
      opts_class = opts.class
      opts_class = TemplateOptions if opts_class == Hash
      @cache, @cache_filename = {}, {}
      @sections, @options = [], opts_class.new
      add_options(opts)
      Template.include_extra(self, options)
      init
    end

### Public Instance Methods

T(*path) click to toggle source

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

    # File lib/yard/templates/template.rb, line 182
    def T(*path)
      path.unshift(options.template) if options.template
      path.push(options.format) if options.format
      self.class.T(*path)
    end

erb(section, &block) click to toggle source

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

    # File lib/yard/templates/template.rb, line 263
    def erb(section, &block)
      method_name = ErbCache.method_for(cache_filename(section)) do
        erb_with(cache(section), cache_filename(section))
      end
      send(method_name, &block)
    end

file(basename, allow_inherited = false) click to toggle source

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

    # File lib/yard/templates/template.rb, line 290
    def file(basename, allow_inherited = false)
      file = self.class.find_file(basename)
      raise ArgumentError, "no file for '#{basename}' in #{self.class.path}" unless file

      data = IO.read(file)
      if allow_inherited
        superfile = self.class.find_nth_file(basename, 2)
        data.gsub!('{{{__super__}}}', superfile ? IO.read(superfile) : "")
      end

      data
    end

init() click to toggle source

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

    # File lib/yard/templates/template.rb, line 217
    def init
    end

inspect() click to toggle source

    # File lib/yard/templates/template.rb, line 320
    def inspect
      "Template(#{self.class.path}) [section=#{section.name}]"
    end

options=(value) click to toggle source

    # File lib/yard/templates/template.rb, line 315
    def options=(value)
      @options = value
      set_ivars
    end

run(opts = nil, sects = sections, start_at = 0, break_first = false, &block) click to toggle source

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

    # File lib/yard/templates/template.rb, line 230
    def run(opts = nil, sects = sections, start_at = 0, break_first = false, &block)
      out = ""
      return out if sects.nil?
      sects = sects[start_at..-1] if start_at > 0
      sects = Section.new(nil, sects) unless sects.is_a?(Section)
      add_options(opts) do
        sects.each do |s|
          self.section = s
          subsection_index = 0
          value = render_section(section) do |*args|
            value = with_section do
              run(args.first, section, subsection_index, true, &block)
            end
            subsection_index += 1
            value
          end
          out << (value || "")
          break if break_first
        end
      end
      out
    end

sections(*args) click to toggle source

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}

    # File lib/yard/templates/template.rb, line 204
    def sections(*args)
      @sections = Section.new(nil, *args) if args.size > 0
      @sections
    end

superb(section = section, &block) click to toggle source

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.

    # File lib/yard/templates/template.rb, line 308
    def superb(section = section, &block)
      filename = self.class.find_nth_file(erb_file_for(section), 2)
      return "" unless filename
      method_name = ErbCache.method_for(filename) { erb_with(IO.read(filename), filename) }
      send(method_name, &block)
    end

yieldall(opts = nil, &block) click to toggle source

Yields all subsections with any extra options

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

    # File lib/yard/templates/template.rb, line 256
    def yieldall(opts = nil, &block)
      with_section { run(opts, section, &block) }
    end

### Protected Instance Methods

erb_file_for(section) click to toggle source

    # File lib/yard/templates/template.rb, line 326
    def erb_file_for(section)
      "#{section}.erb"
    end

erb_with(content, filename = nil) click to toggle source

    # File lib/yard/templates/template.rb, line 330
    def erb_with(content, filename = nil)
      erb = ERB.new(content, nil, options.format == :text ? '<>' : nil)
      erb.filename = filename if filename
      erb
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.