Commit 7fc30feb authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implemented cache for rendered member rows.

This makes the generating of pages about twice as fast.
parent f3dd2e1b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -80,10 +80,11 @@ module JsDuck
    # Writes documentation page for each class
    def write_pages(path, docs)
      subclasses = Subclasses.new(docs)
      cache = {}
      docs.each do |cls|
        filename = path + "/" + cls[:name] + ".html"
        puts "Writing to #{filename} ..." if @verbose
        html = Page.new(cls, subclasses).to_html
        html = Page.new(cls, subclasses, cache).to_html
        File.open(filename, 'w') {|f| f.write(html) }
      end
    end
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ require 'jsduck/table'
module JsDuck

  class CfgTable < Table
    def initialize(cls)
      super(cls)
    def initialize(cls, cache={})
      super(cls, cache)
      @type = :cfg
      @id = @cls.full_name + "-configs"
      @title = "Config Options"
+2 −2
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@ require 'jsduck/long_params'
module JsDuck

  class EventTable < Table
    def initialize(cls)
      super(cls)
    def initialize(cls, cache={})
      super(cls, cache)
      @type = :event
      @id = @cls.full_name + "-events"
      @title = "Public Events"
+2 −2
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@ require 'jsduck/long_params'
module JsDuck

  class MethodTable < Table
    def initialize(cls)
      super(cls)
    def initialize(cls, cache={})
      super(cls, cache)
      @type = :method
      @id = @cls.full_name + "-methods"
      @title = "Public Methods"
+12 −5
Original line number Diff line number Diff line
@@ -9,9 +9,16 @@ module JsDuck

  # Creates HTML documentation page for one class.
  class Page
    def initialize(cls, subclasses = {})
    # Initializes doc page generator
    #
    # - cls : the Class object for which to generate documentation
    # - subclasses : lookup table for easy access to subclasses
    # - cache : cache for already generated HTML rows for class members
    #
    def initialize(cls, subclasses = {}, cache = {})
      @cls = cls
      @subclasses = subclasses
      @cache = cache
      @formatter = DocFormatter.new(cls.full_name)
    end

@@ -23,10 +30,10 @@ module JsDuck
       abstract,
       description,
       "<div class='hr'></div>",
       CfgTable.new(@cls).to_html,
       PropertyTable.new(@cls).to_html,
       MethodTable.new(@cls).to_html,
       EventTable.new(@cls).to_html,
       CfgTable.new(@cls, @cache).to_html,
       PropertyTable.new(@cls, @cache).to_html,
       MethodTable.new(@cls, @cache).to_html,
       EventTable.new(@cls, @cache).to_html,
       "</div>",
      ].join("\n")
    end
Loading