Commit c7b0f17d authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move CSS type parsing skipping logic out of Tag classes.

Handle it at the Format::Class level again - but this time do it through
the Format::Doc#skip_type_parsing setter method.

Because the concrete CSS member types are hard-coded anyway it's better
to have this hard-coded logic in one spot, not scattered around several
Tag classes.
parent 9e6a2f06
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -34,6 +34,9 @@ module JsDuck
      def format_member(m)
        @formatter.doc_context = m[:files][0]

        # Turn off type parsing for CSS vars and mixins
        @formatter.skip_type_parsing = [:css_var, :css_mixin].include?(m[:tagname])

        format_tags(m)
      end

+15 −5
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ module JsDuck
      def initialize(relations={}, opts={})
        @relations = relations
        @opts = opts
        @subproperties = Format::Subproperties.new(self, opts)
        @subproperties = Format::Subproperties.new(self, !!opts[:export])
        @link_renderer = Inline::LinkRenderer.new(relations, opts)
        @inline_link = Inline::Link.new(@link_renderer)
        @auto_link = Inline::AutoLink.new(@link_renderer)
@@ -144,17 +144,27 @@ module JsDuck
        @link_renderer.link(cls, member, anchor_text, type, static)
      end

      # Turns type parsing on or off.
      #
      # Used to skipping parsing of CSS var and mixin types.
      #
      # Won't have any effect when performing export -
      # type parsing is then automatically turned off.
      def skip_type_parsing=(skip)
        @subproperties.skip_types = !!@opts[:export] || skip
      end

      # Recursively formats a subproperty.
      # See Format::Subproperties#format for details.
      def format_subproperty(item, skip_types=false)
        @subproperties.format(item, skip_types)
      def format_subproperty(item)
        @subproperties.format(item)
      end

      # Parses and formats type definition.
      # Returns HTML-rendering of the type.
      # See Format::Subproperties#format_type for details.
      def format_type(type, skip_types=false)
        @subproperties.format_type(type, skip_types)
      def format_type(type)
        @subproperties.format_type(type)
      end

    end
+11 −8
Original line number Diff line number Diff line
@@ -8,27 +8,30 @@ module JsDuck
    # Helper for recursively formatting subproperties.
    class Subproperties

      def initialize(formatter, opts={})
      def initialize(formatter, skip_types=false)
        @formatter = formatter
        # Don't format types when exporting
        @skip_types = !!opts[:export]
        @skip_types = skip_types
      end

      # Set to true to skip parsing and formatting of types.
      # Used when doing export and to skip parsing of CSS typesdefs.
      attr_accessor :skip_types

      # Takes a hash of param, return value, throws value or subproperty.
      #
      # - Markdown-formats the :doc field in it.
      # - Parses the :type field and saves HTML to :html_type.
      # - Recursively does the same with all items in :properties field.
      #
      def format(item, skip_types=false)
      def format(item)
        item[:doc] = @formatter.format(item[:doc]) if item[:doc]

        if item[:type]
          item[:html_type] = format_type(item[:type], skip_types)
          item[:html_type] = format_type(item[:type])
        end

        if item[:properties]
          item[:properties].each {|p| format(p, skip_types) }
          item[:properties].each {|p| format(p) }
        end
      end

@@ -37,9 +40,9 @@ module JsDuck
      # - On success returns HTML-version of the type definition.
      # - On failure logs error and returns the type string with only HTML escaped.
      #
      def format_type(type, skip_types=false)
      def format_type(type)
        # Skip the formatting entirely when type-parsing is turned off.
        return Util::HTML.escape(type) if @skip_types || skip_types
        return Util::HTML.escape(type) if @skip_types

        tp = TypeParser.new(@formatter)
        if tp.parse(type)
+1 −4
Original line number Diff line number Diff line
@@ -33,10 +33,7 @@ module JsDuck::Tag
    end

    def format(m, formatter)
      # We don't validate and format CSS var and mixin type definitions
      skip_type = m[:tagname] == :css_var || m[:tagname] == :css_mixin

      m[:params].each {|p| formatter.format_subproperty(p, skip_type) }
      m[:params].each {|p| formatter.format_subproperty(p) }
    end

    def to_html(m)
+1 −4
Original line number Diff line number Diff line
@@ -41,10 +41,7 @@ module JsDuck::Tag
    end

    def format(m, formatter)
      # We don't validate and format CSS var and mixin type definitions
      skip_type = m[:tagname] == :css_var || m[:tagname] == :css_mixin

      m[:html_type] = formatter.format_type(m[:type], skip_type)
      m[:html_type] = formatter.format_type(m[:type])
    end

  end