Sha256: c14afe3d97c90f035041ae981d1df500cf61377e2022955ba2975fcdc4bab75c
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
require 'fileutils' module YARD module Serializers class FileSystemSerializer < Base attr_reader :basepath, :extension def initialize(opts = {}) super @basepath = (options[:basepath] || 'doc').to_s @extension = (options.has_key?(:extension) ? options[:extension] : 'html').to_s end def serialize(object, data) path = File.join(basepath, *serialized_path(object)) FileUtils.mkdir_p File.dirname(path) log.debug "Serializing to #{path}" File.open(path, "w") {|f| f.write data } end def serialized_path(object) return object if object.is_a?(String) objname = object.name.to_s objname += '_' + object.scope.to_s[0,1] if object.is_a?(CodeObjects::MethodObject) fspath = [objname + (extension.empty? ? '' : ".#{extension}")] if object.namespace && object.namespace.path != "" fspath.unshift *object.namespace.path.split(CodeObjects::NSEP) end # Don't change the filenames, it just makes it more complicated # to figure out the original name. #fspath.map! do |p| # p.gsub(/([a-z])([A-Z])/, '\1_\2').downcase #end # Remove special chars from filenames. # Windows disallows \ / : * ? " < > | but we will just remove any # non alphanumeric (plus period, underscore and dash). fspath.map! do |p| p.gsub(/[^\w\.-]/) {|x| '_' + x[0].to_s(16).upcase } end File.join(fspath) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yard-0.2.2 | lib/yard/serializers/file_system_serializer.rb |