Sha256: a4b9b67fc09b6507cfde4b0b6e0dfc7475b8ec076e2519c7d82303f029b838f5

Contents?: true

Size: 1.72 KB

Versions: 62

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true
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(&: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 = object
        self.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 = $1
        suffix = "tag"
        if tag_name =~ /^!/
          tag_name = tag_name[1..-1]
          suffix = "directive"
        end

        obj = Registry.at("YARD::Tags::Library##{tag_name}_#{suffix}")
        return tag_link(obj.tag("yard.#{suffix}")) if obj

        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

62 entries across 61 versions & 9 rubygems

Version Path
kinetic_sdk-5.0.29 gems/yard-0.9.36/docs/templates/plugin.rb
kinetic_sdk-5.0.28 gems/yard-0.9.36/docs/templates/plugin.rb
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/docs/templates/plugin.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/docs/templates/plugin.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/docs/templates/plugin.rb
yard-0.9.37 docs/templates/plugin.rb
kinetic_sdk-5.0.27 gems/yard-0.9.36/docs/templates/plugin.rb
kinetic_sdk-5.0.26 gems/yard-0.9.36/docs/templates/plugin.rb
kinetic_sdk-5.0.25 gems/yard-0.9.25/docs/templates/plugin.rb
kinetic_sdk-5.0.24 gems/yard-0.9.25/docs/templates/plugin.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/docs/templates/plugin.rb
yard-0.9.36 docs/templates/plugin.rb
yard-0.9.35 docs/templates/plugin.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/docs/templates/plugin.rb
kinetic_sdk-5.0.23 gems/yard-0.9.25/docs/templates/plugin.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/yard-0.9.34/docs/templates/plugin.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/docs/templates/plugin.rb
kinetic_sdk-5.0.22 gems/yard-0.9.25/docs/templates/plugin.rb
kinetic_sdk-5.0.21 gems/yard-0.9.25/docs/templates/plugin.rb
yard-0.9.34 docs/templates/plugin.rb