Sha256: 23e1ec2b6c193fc4e7cc2b34699b2ef7d8c0662f399ef5db0075fe9f63b03dde

Contents?: true

Size: 1.32 KB

Versions: 29

Compression:

Stored size: 1.32 KB

Contents

require "jsduck/tag/tag"

module JsDuck

  # Loads Tag classes from the builtin tags/ dir and optionally also
  # from additional paths.
  class TagLoader
    def initialize(extra_paths=[])
      @paths = [File.dirname(__FILE__) + "/tag"]
      @paths += extra_paths
    end

    # Loads Tag classes from all supplied paths.
    #
    # Returns the tag classes that got loaded, sorted alphabetically
    # by class name.
    def load_all
      @paths.each {|path| load(path) }
      tag_classes
    end

    private

    # Loads tag classes from given dir or single file.
    def load(path)
      if File.directory?(path)
        Dir[path+"/**/*.rb"].each do |file|
          # Ruby 1.8 doesn't understand that "jsduck/tag/tag" and
          # "./lib/jsduck/tag/tag.rb" refer to the same file.  So
          # explicitly avoid loading this file (as it's required on
          # top already) to prevent warnings of constants getting
          # defined multiple times.
          require(file) unless file =~ /jsduck\/tag\/tag\.rb$/
        end
      else
        require(path)
      end
    end

    def tag_classes
      classes = JsDuck::Tag::Tag.descendants
      # sort by classname
      # This ensures attributes in member signatures are
      # always rendered in the same order.
      classes.sort {|a, b| a.name <=> b.name }
    end

  end

end

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
solvas-jsduck-6.0.0.30539 lib/jsduck/tag_loader.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/tag_loader.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/tag_loader.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/tag_loader.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/tag_loader.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/tag_loader.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/tag_loader.rb
jsduck-troopjs-0.0.10 lib/jsduck/tag_loader.rb
jsduck-troopjs-0.0.9 lib/jsduck/tag_loader.rb
jsduck-troopjs-0.0.8 lib/jsduck/tag_loader.rb
jsduck-troopjs-0.0.7 lib/jsduck/tag_loader.rb
jsduck-troopjs-0.0.5 lib/jsduck/tag_loader.rb
jsduck-troopjs-0.0.4 lib/jsduck/tag_loader.rb
jsduck-troopjs-0.0.3 lib/jsduck/tag_loader.rb
jsduck-troopjs-0.0.1 lib/jsduck/tag_loader.rb
jsduck-6.0.0beta lib/jsduck/tag_loader.rb
jsduck-5.3.4 lib/jsduck/tag_loader.rb
jsduck-5.3.3 lib/jsduck/tag_loader.rb
jsduck-5.3.2 lib/jsduck/tag_loader.rb
jsduck-5.3.1 lib/jsduck/tag_loader.rb