Sha256: b16e563a8543680330e58b39a494b045a021209c1e2288c898343c58d7b756c9

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

module YARD::Templates::Helpers
  module BaseHelper
    attr_accessor :object, :serializer
    
    def run_verifier(list)
      return list unless options[:verifier]
      list.reject {|item| options[:verifier].call(item).is_a?(FalseClass) }
    end
    
    # This is used a lot by the HtmlHelper and there should
    # be some helper to "clean up" text for whatever, this is it.
    def h(text)
      text
    end
    
    def linkify(*args) 
      if args.first.is_a?(String)
        case args.first
        when %r{://}, /^mailto:/
          link_url(args[0], args[1], {:target => '_parent'}.merge(args[2]||{}))
        when /^file:(\S+?)(?:#(\S+))?$/
          link_file($1, args[1] ? args[1] : $1, $2)
        else
          link_object(*args)
        end
      else
        link_object(*args)
      end
    end

    def link_object(object, title = nil)
      return title if title
      
      case object
      when YARD::CodeObjects::Base, YARD::CodeObjects::Proxy
        object.path
      when String, Symbol
        P(object).path
      else
        object
      end
    end
    
    def link_url(url, title = nil, params = nil)
      url
    end
    
    def link_file(filename, title = nil, anchor = nil)
      filename
    end
    
    def format_types(list, brackets = true)
      list.nil? || list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
    end

    def format_object_type(object)
      case object
      when YARD::CodeObjects::ClassObject
        object.is_exception? ? "Exception" : "Class"
      else
        object.type.to_s.capitalize
      end
    end
    
    def format_object_title(object)
      case object
      when YARD::CodeObjects::RootObject
        "Top Level Namespace"
      else
        format_object_type(object) + ": " + object.path
      end
    end
    
    def format_source(value)
      sp = value.split("\n").last[/^(\s+)/, 1]
      num = sp ? sp.size : 0
      value.gsub(/^\s{#{num}}/, '')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yard-0.5.8 lib/yard/templates/helpers/base_helper.rb
yard-0.5.7 lib/yard/templates/helpers/base_helper.rb
yard-0.5.6 lib/yard/templates/helpers/base_helper.rb
yard-0.5.5 lib/yard/templates/helpers/base_helper.rb