Sha256: 40f12be33102904af03a05d7a8cbdb79c068c3312c4be0f1c66bb7c2133d94b0

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

module JsDuck

  # Export class data as hash with :cfg being replace with :cfgs and
  # including all the inherited members too.  Same for :properties,
  # :methods, and :events.
  class Exporter
    def initialize(relations)
      @relations = relations
    end

    # Returns all data in Class object as hash.
    def export(cls)
      h = cls.to_hash
      h[:members] = {}
      Class.default_members_hash.each_key do |key|
        h[:members][key] = cls.members(key)
        h[:statics][key] = cls.members(key, :statics)
      end
      h[:component] = cls.inherits_from?("Ext.Component")
      h[:superclasses] = cls.superclasses.collect {|c| c.full_name }
      h[:subclasses] = @relations.subclasses(cls).collect {|c| c.full_name }
      h[:mixedInto] = @relations.mixed_into(cls).collect {|c| c.full_name }
      h[:allMixins] = cls.all_mixins.collect {|c| c.full_name }
      h
    end

    # removes extra data from export
    def compact(cls)
      cls.delete(:doc)
      cls[:members] = compact_members_group(cls[:members])
      cls[:statics] = compact_members_group(cls[:statics])
      cls[:files] = compact_files(cls[:files])
      cls
    end

    def compact_members_group(group)
      c_group = {}
      group.each_pair do |type, members|
        c_group[type] = members.map {|m| compact_member(m) }
      end
      c_group
    end

    def compact_member(m)
      m_copy = {}
      [:name, :tagname, :owner, :protected, :static, :deprecated, :required, :template, :id].each do |key|
        m_copy[key] = m[key]
      end
      m_copy
    end

    # Remove full path from filename for privacy considerations as the
    # path can reveal information about the system where JSDuck was
    # run.  The docs app doesn't need to have this information.
    def compact_files(files)
      files.map do |f|
        {:filename => File.basename(f[:filename]), :href => f[:href]}
      end
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jsduck-3.0.1 lib/jsduck/exporter.rb
jsduck-3.0 lib/jsduck/exporter.rb
jsduck-3.0.pre3 lib/jsduck/exporter.rb