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
yard-0.9.25 docs/templates/plugin.rb
yard-0.9.24 docs/templates/plugin.rb
yard-0.9.23 docs/templates/plugin.rb
yard-0.9.22 docs/templates/plugin.rb
yard-0.9.21 docs/templates/plugin.rb
yard-0.9.20 docs/templates/plugin.rb
yard-0.9.19 docs/templates/plugin.rb
yard-0.9.16 docs/templates/plugin.rb
yard-0.9.15 docs/templates/plugin.rb
yard-0.9.14 docs/templates/plugin.rb
yard-0.9.13 docs/templates/plugin.rb
yard-0.9.12 docs/templates/plugin.rb
yard-0.9.11 docs/templates/plugin.rb
yard-0.9.10 docs/templates/plugin.rb
yard-0.9.9 docs/templates/plugin.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/docs/templates/plugin.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/docs/templates/plugin.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/docs/templates/plugin.rb
yard-0.9.8 docs/templates/plugin.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.7/docs/templates/plugin.rb