Sha256: f295824bd7a507e83d2f3c615396bc8a1866f71d47548b7c2d14af9d25fe3fba

Contents?: true

Size: 1.7 KB

Versions: 76

Compression:

Stored size: 1.7 KB

Contents

include YARD
include Templates

module TagTemplateHelper
  def all_tags
    Registry.all(:method).map {|m| m.tag('yard.tag') }.compact
  end

  def all_directives
    Registry.all(:method).map {|m| m.tag('yard.directive') }.compact
  end

  def collect_tags
    (all_tags + all_directives).sort_by {|t| t.name }
  end

  def tag_link(tag)
    link_file("docs/Tags.md", tag_link_name(tag), tag.name)
  end

  def tag_link_name(tag)
    prefix = tag.tag_name == 'yard.directive' ? '@!' : '@'
    h(prefix + tag.name)
  end

  # Wrap url_for and url_for_file to rewrite object when generating docs for
  # yard.tag/directive objects.
  %w(url_for, url_for_file).each do |meth|
    self.class.send(:define_method, meth) do
      if object.is_a?(CodeObjects::Base) &&
            (object.tag('yard.tag') || object.tag('yard.directive') ||
            (object.type == :class && object.superclass.name == :Directive))
          obj, self.object = object, Registry.root
          url = super
          self.object = obj
          url
      else
        super
      end
    end
  end

  def linkify(*args)
    if args.first.is_a?(String)
      case args.first
      when "yard:include_tags"
        return T('yard_tags').run(options)
      when /^tag:(\S+)/
        tag_name, suffix = $1, "tag"
        if tag_name =~ /^!/
          tag_name, suffix = tag_name[1..-1], "directive"
        end
        if obj = Registry.at("YARD::Tags::Library##{tag_name}_#{suffix}")
          return tag_link(obj.tag("yard.#{suffix}"))
        end
        log.warn "Cannot find tag: #{args.first}"
        return args.first
      end
    end
    super
  end
end

Template.extra_includes << TagTemplateHelper
Engine.register_template_path(File.dirname(__FILE__))

Version data entries

76 entries across 59 versions & 8 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/yard-0.9.2/docs/templates/plugin.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.1/docs/templates/plugin.rb
yard-0.9.5 docs/templates/plugin.rb
yard-0.9.4 docs/templates/plugin.rb
yard-0.9.3 docs/templates/plugin.rb
yard-0.9.2 docs/templates/plugin.rb
yard-0.9.1 docs/templates/plugin.rb
yard-0.9.0 docs/templates/plugin.rb
yard-0.8.7.6 docs/templates/plugin.rb
yard-0.8.7.5 docs/templates/plugin.rb
climine-0.0.7 vendor/bundle/ruby/2.1.0/gems/yard-0.8.7.3/docs/templates/plugin.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/docs/templates/plugin.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/docs/templates/plugin.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/docs/templates/plugin.rb
yard-0.8.7.4 docs/templates/plugin.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/docs/templates/plugin.rb
climine-0.0.3 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/docs/templates/plugin.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/yard-0.8.7.3/docs/templates/plugin.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/yard-0.8.7.3/docs/templates/plugin.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/yard-0.8.7.3/docs/templates/plugin.rb