Commit 0f860379 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Format every meta-tags only once.

The rendering of meta-tags is now performed inside ClassFormatter
like the rendering of most other stuff.  The result of rendering
is stored to :html_meta field (to keep the plain :meta field for
purposes of export).

The performance gains of doing it all once are very small, but
we should now get less duplicate error messages for bad @links,
which is nice.

Additionally all Exporter classes can now get rid of opts parameter,
which was only needed for instanciating DocFormatter, but that's
now done inside ClassFormatter.
parent fd798378
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ module JsDuck
    def clone_meta(cfg)
      h = {}
      cfg[:meta].each_pair do |key, value|
        h[:key] = value unless key == :required
        h[key] = value unless key == :required
      end
      h
    end
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ module JsDuck
  # }
  #
  class ApiExporter
    def initialize(relations, opts)
    def initialize(relations)
      # All params ignored, they're present to be compatible with
      # other exporters.
    end
+2 −7
Original line number Diff line number Diff line
require 'jsduck/full_exporter'
require 'jsduck/renderer'
require 'jsduck/doc_formatter'
require 'jsduck/meta_tag_registry'

module JsDuck

  # Exports data for Docs app.
  class AppExporter < FullExporter
    def initialize(relations, opts)
      super(relations, opts)

    def initialize(relations)
      super(relations)
      @renderer = Renderer.new
      # Inject formatter to all meta-tags.
      doc_formatter = DocFormatter.new(relations, opts)
      MetaTagRegistry.instance.formatter = doc_formatter
    end

    # Returns compacted class data hash which contains an additional
+13 −0
Original line number Diff line number Diff line
require 'jsduck/type_parser'
require 'jsduck/logger'
require 'jsduck/meta_tag_registry'

module JsDuck

@@ -13,6 +14,8 @@ module JsDuck
    def initialize(relations, formatter)
      @relations = relations
      @formatter = formatter
      # inject formatter to all meta-tags
      MetaTagRegistry.instance.formatter = formatter
      @include_types = true
    end

@@ -31,6 +34,7 @@ module JsDuck
          cls[group][type] = members.map {|m| m[:private] ? m : format_member(m)  }
        end
      end
      cls[:html_meta] = format_meta_data(cls[:meta])
      cls
    end

@@ -48,6 +52,7 @@ module JsDuck
      m[:params] = m[:params].map {|p| format_item(p, is_css_tag) } if m[:params]
      m[:return] = format_item(m[:return], is_css_tag) if m[:return]
      m[:properties] = m[:properties].map {|b| format_item(b, is_css_tag) } if m[:properties]
      m[:html_meta] = format_meta_data(m[:meta])
      m
    end

@@ -77,6 +82,14 @@ module JsDuck
      end
    end

    def format_meta_data(meta_data)
      result = {}
      meta_data.each_pair do |key, value|
        result[key] = MetaTagRegistry.instance[key].to_html(value) if value
      end
      result
    end

  end

end
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ module JsDuck
  class ClassWriter
    def initialize(exporter_class, relations, opts)
      @relations = relations
      @exporter = exporter_class.new(relations, opts)
      @exporter = exporter_class.new(relations)
      @parallel = ParallelWrap.new(:in_processes => opts.processes)
    end

Loading