Commit 7729a40a authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move {@example} replacement to parser side.

parent de88e6b2
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ module JsDuck
    # name actually exists.
    attr_accessor :relations

    @@example_counter = 0

    def initialize
      @class_context = ""
      @doc_context = {}
@@ -55,8 +57,10 @@ module JsDuck
      @relations = {}
      @link_tpl = '<a href="%c%#%m">%a</a>'
      @img_tpl = '<img src="%u" alt="%a"/>'
      @example_tpl = '<div class="inline-example" id="eg%i" rel="%u"></div>'
      @link_re = /\{@link\s+(\S*?)(?:\s+(.+?))?\}/m
      @img_re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m
      @example_re = /\{@example\s+(\S*?)\s*\}/m
    end

    # Replaces {@link} and {@img} tags, auto-generates links for
@@ -78,6 +82,8 @@ module JsDuck
          out += replace_link_tag(s.scan(@link_re))
        elsif s.check(@img_re)
          out += replace_img_tag(s.scan(@img_re))
        elsif s.check(@example_re)
          out += replace_example_tag(s.scan(@example_re))
        elsif s.check(/\{/)
          out += s.scan(/\{/)
        else
@@ -128,6 +134,10 @@ module JsDuck
      input.sub(@img_re) { img($1, $2) }
    end

    def replace_example_tag(input)
      input.sub(@example_re) { example($1) }
    end

    def replace_class_names(input)
      input.gsub(/(\A|\s)([A-Z][A-Za-z0-9.]*[A-Za-z0-9])(?:(#)([A-Za-z0-9]+))?([.,]?(?:\s|\Z))/m) do
        before = $1
@@ -159,6 +169,20 @@ module JsDuck
      end
    end

    # applies the example template
    def example(url)
      @example_tpl.gsub(/(%\w)/) do
        case $1
        when '%u'
          url
        when '%i'
          @@example_counter += 1
        else
          $1
        end
      end
    end

    # applies the link template
    def link(cls, member, anchor_text, type=nil)
      # Use the canonical class name for link (not some alternateClassName)
+0 −12
Original line number Diff line number Diff line
@@ -171,18 +171,6 @@ Ext.define('Docs.view.cls.Overview', {
            '</div>'
        );

        var egId = 0;
        var replaceExample = function() {
            var idx = cls.doc.match(/\{@example ([A-Za-z0-9_\/\.]+)\}/);
            if (idx) {
                cls.doc = cls.doc.replace(/\{@example ([A-Za-z0-9_\/\.]+)\}/, '<div class="inline-example" id="eg' + egId + '" rel="' + idx[1] + '"></div>');
                egId += 1;
                replaceExample();
            }
        }

        replaceExample();

        return this.classTpl.apply({
            doc: cls.doc,
            hierarchy: this.renderHierarchy(cls),