Sha256: e185cdf8ac51e344c214031127c843a5728fc0e4bceb4d91c3d4b2f5c9a0ce64

Contents?: true

Size: 1.93 KB

Versions: 28

Compression:

Stored size: 1.93 KB

Contents

require 'jsduck/logger'
require 'jsduck/categories/file'
require 'jsduck/categories/auto'
require 'jsduck/categories/class_name'
require 'jsduck/columns'

module JsDuck
  module Categories

    # Reads in categories and outputs them as HTML div
    class Factory
      def self.create(filename, doc_formatter, relations)
        if filename
          categories = Categories::File.new(filename, relations)
        else
          categories = Categories::Auto.new(relations)
        end
        Categories::Factory.new(categories.generate, doc_formatter, relations)
      end

      def initialize(categories, doc_formatter, relations={})
        @categories = categories
        @class_name = Categories::ClassName.new(doc_formatter, relations)
        @columns = Columns.new("classes")
      end

      # Returns HTML listing of classes divided into categories
      def to_html(style="")
        html = @categories.map do |category|
          [
            "<div class='section'>",
            "<h1>#{category['name']}</h1>",
            render_columns(category['groups']),
            "<div style='clear:both'></div>",
            "</div>",
          ]
        end.flatten.join("\n")

        return <<-EOHTML
          <div id='categories-content' style='#{style}'>
            #{html}
          </div>
        EOHTML
      end

      private

      def render_columns(groups)
        align = ["left-column", "middle-column", "right-column"]
        i = -1
        return @columns.split(groups, 3).map do |col|
          i += 1
          [
            "<div class='#{align[i]}'>",
            render_groups(col),
            "</div>",
          ]
        end
      end

      def render_groups(groups)
        return groups.map do |g|
          [
            "<h3>#{g['name']}</h3>",
            "<ul class='links'>",
            g["classes"].map {|cls| "<li>" + @class_name.render(cls) + "</li>" },
            "</ul>",
          ]
        end
      end

    end

  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

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