Sha256: 064e52afab2ff51c77e92eb5676bef7fb6d9ef5368a01b7f14563594a7ad16cd

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 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) 
      # The :// character sequence exists in no valid object path but just about every URL scheme.
      if args.first.is_a?(String) && args.first.include?("://")
        link_url(*args)
      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)
      url
    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

7 entries across 7 versions & 1 rubygems

Version Path
yard-0.5.4 lib/yard/templates/helpers/base_helper.rb
yard-0.5.3 lib/yard/templates/helpers/base_helper.rb
yard-0.5.2 lib/yard/templates/helpers/base_helper.rb
yard-0.5.1p1 lib/yard/templates/helpers/base_helper.rb
yard-0.5.1 lib/yard/templates/helpers/base_helper.rb
yard-0.5.0 lib/yard/templates/helpers/base_helper.rb
yard-0.4.0 lib/yard/templates/helpers/base_helper.rb