Commit 1f012629 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add --guides-order command line option.

This allows us to specify a particular order for the guides listing.
Additionally: the guides not listed will be excluded completely.
parent 51d450d9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ def run_jsduck(extra_options)
    # appears inline withing text, but that just looks ugly in HTML
    '--img', '<p><img src="doc-resources/%u" alt="%a"></p>',
    "--guides", "#{SDK_DIR}/guides",
    "--guides-order", "getting,class,application,layouts,data,grid,tree,drawing,forms,components,theming,direct",
    "--output", "#{OUT_DIR}",
  ].concat(extra_options))

+8 −0
Original line number Diff line number Diff line
@@ -55,6 +55,14 @@ opts = OptionParser.new do | opts |
    app.guides_dir = path
  end

  opts.on('--guides-order=a,b,c', Array,
    "The order in which the guides should appear. When",
    "a guide name is not specified here, it will be excluded.",
    "You don't have to write the whole name of the guide,",
    "just the beginning of it, as long as it's unique.", " ") do |list|
    app.guides_order = list
  end

  opts.on('-h', '--help', "Prints this help message", " ") do
    puts opts
    exit
+3 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ module JsDuck
    attr_accessor :output_dir
    attr_accessor :template_dir
    attr_accessor :guides_dir
    attr_accessor :guides_order
    attr_accessor :template_links
    attr_accessor :input_files
    attr_accessor :export
@@ -44,6 +45,7 @@ module JsDuck
      @output_dir = nil
      @template_dir = nil
      @guides_dir = nil
      @guides_order = nil
      @template_links = false
      @input_files = []
      @warnings = true
@@ -86,7 +88,7 @@ module JsDuck
      warn_globals(relations)
      warn_unnamed(relations)

      @guides = Guides.new(get_doc_formatter(relations))
      @guides = Guides.new(get_doc_formatter(relations), @guides_order)
      if @guides_dir
        @timer.time(:parsing) { @guides.parse_dir(@guides_dir) }
      end
+11 −3
Original line number Diff line number Diff line
@@ -6,9 +6,10 @@ module JsDuck

  # Reads in guides and converts them to JsonP files
  class Guides
    def initialize(formatter)
    def initialize(formatter, order=nil)
      @guides = []
      @formatter = formatter
      @order = order
    end

    # Looks for guide in each subdir of given directory.
@@ -19,9 +20,15 @@ module JsDuck
        end
      end

      # Sort guides alphabetically
      if @order
        # When order specified, place guides into that order and
        # exclude those guides that aren't listed in @order
        @guides = @order.map {|name| @guides.find {|g| g[:name] =~ Regexp.new("^"+Regexp.escape(name)) } }
      else
        # Otherwise sort guides alphabetically
        @guides.sort! {|a, b| a[:title] <=> b[:title] }
      end
    end

    def parse_guide(dir)
      guide_file = dir + "/README.md"
@@ -62,6 +69,7 @@ module JsDuck
      end
    end

    # Returns HTML listing of guides
    def to_html
      return "" if @guides.length == 0