Sha256: 8ee431703a8bbf010ca3387972fdeb54487b8790ecf22775c823b404b3030535

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 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))

      if path.include?(' ')
      	debugger
      end

      log.debug "Serializing to #{path}"
      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

      if (fspath.include?(' '))
      	debugger
      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.name.to_s
			end
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yard-api-0.3.0 lib/yard-api/serializer.rb