Sha256: feae5e5912d7e4e2a5ed2cce3133ffe95c0be124e44952188929c669798ea46f

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

module YARD::APIPlugin
  class Serializer < ::YARD::Serializers::FileSystemSerializer
    USNSEP = '__' # url-safe namespace separator
    FSSEP = '/'

    def self.topicize(str)
      str.lines.first.gsub(/\W+/, '_').downcase
    end

    def serialize(object, data)
      path = File.join(basepath, serialized_path(object))
      File.open!(path, "wb") {|f| f.write data }
    end

    def serialized_path(object)
      return object if object.is_a?(String)

      fspath = nil

      if object.is_a?(YARD::CodeObjects::ExtraFileObject)
        fspath = 'file.' + object.name + (extension.empty? ? '' : ".#{extension}")
      else
        fspath = if object == YARD::Registry.root
          "top-level-namespace"
        else
          self.class.topicize(get_api_id(object))
        end

        if object.is_a?(YARD::CodeObjects::MethodObject)
          fspath += '_' + object.scope.to_s[0,1]
        end

        unless extension.empty?
          fspath += ".#{extension}"
        end
      end

      fspath.gsub(/[^\w\.\-_\/]+/, '-')
    end

    def get_api_id(object)
      if object[:api_id]
        object.api_id
      elsif tag = object.tag(:API)
        tag.text.lines.first.strip
      else
        object.to_s
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yard-api-0.3.4 lib/yard-api/serializer.rb
yard-api-0.3.3 lib/yard-api/serializer.rb
yard-api-0.3.2 lib/yard-api/serializer.rb
yard-api-0.3.1 lib/yard-api/serializer.rb