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

Remove support for {@example}.

The support has been implemented for a while, but nobody has ever
really used the functionality. Time to remove it. Along with it
goes the --inline-examples option.
parent 94fc8729
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -166,7 +166,6 @@ class JsDuckRunner
      "--guides", "#{@sdk_dir}/extjs/docs/guides.json",
      "--videos", "#{@sdk_dir}/extjs/docs/videos.json",
      "--examples", "#{@sdk_dir}/extjs/examples/examples.json",
      "--inline-examples", "#{@sdk_dir}/extjs/docs/resources",
      "--categories", "#{@sdk_dir}/extjs/docs/categories.json",
      "--output", "#{@out_dir}",
      "--builtin-classes",
+0 −3
Original line number Diff line number Diff line
@@ -222,9 +222,6 @@ module JsDuck
      formatter.link_tpl = @opts.link_tpl if @opts.link_tpl
      formatter.img_tpl = @opts.img_tpl if @opts.img_tpl
      formatter.relations = @relations
      if @opts.inline_examples_dir
        formatter.get_example = lambda {|path| IO.read(@opts.inline_examples_dir + "/" + path) }
      end
      formatter
    end

+0 −32
Original line number Diff line number Diff line
@@ -29,10 +29,6 @@ module JsDuck
    # Default value: '<img src="%u" alt="%a"/>'
    attr_accessor :img_tpl

    # Assign to this a function that retrieves the example code when
    # passed in a filename
    attr_accessor :get_example

    # This will hold list of all image paths gathered from {@img} tags.
    attr_accessor :images

@@ -67,10 +63,8 @@ module JsDuck
      @images = []
      @link_tpl = '<a href="%c%#%m">%a</a>'
      @img_tpl = '<img src="%u" alt="%a"/>'
      @example_tpl = '<pre class="inline-example"><code>%a</code></pre>'
      @link_re = /\{@link\s+(\S*?)(?:\s+(.+?))?\}/m
      @img_re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m
      @example_re = /\{@example\s+(\S*?)\s*\}/m
      @example_annotation_re = /<pre><code>\s*@example( +[^\n]*)?\s+/m
    end

@@ -82,8 +76,6 @@ module JsDuck
    #
    # Replaces {@img path/to/image.jpg Alt text} with HTML from @img_tpl.
    #
    # Replaces {@example path/to/example.js} with source from that file.
    #
    # Adds 'inline-example' class to code examples beginning with @example.
    #
    # Additionally replaces strings recognized as ClassNames with
@@ -97,8 +89,6 @@ 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(@example_annotation_re)
          s.scan(@example_annotation_re)
          out += '<pre class="inline-example"><code>'
@@ -152,10 +142,6 @@ 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
@@ -188,24 +174,6 @@ module JsDuck
      end
    end

    # Replaces example template with example read from file
    def example(path)
      @example_tpl.gsub(/(%\w)/) do
        case $1
        when '%a'
          if @get_example
            CGI.escapeHTML(@get_example.call(path))
          else
            file = @doc_context[:filename]
            line = @doc_context[:linenr]
            Logger.instance.warn("--inline-examples not specified, but {@example} found", file, line)
          end
        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 −6
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ module JsDuck
    attr_accessor :videos
    attr_accessor :examples
    attr_accessor :categories_path
    attr_accessor :inline_examples_dir
    attr_accessor :pretty_json
    attr_accessor :images
    attr_accessor :link_tpl
@@ -87,7 +86,6 @@ module JsDuck
      @videos = nil
      @examples = nil
      @categories_path = nil
      @inline_examples_dir = nil
      @pretty_json = false
      @images = []
      @link_tpl = '<a href="#!/api/%c%-%m" rel="%c%-%m" class="docClass">%a</a>'
@@ -214,10 +212,6 @@ module JsDuck
          @categories_path = canonical(path)
        end

        opts.on('--inline-examples=PATH', "Path to inline examples directory.", " ") do |path|
          @inline_examples_dir = canonical(path)
        end

        opts.on('--pretty-json', "Turn on pretty-printing of JSON.", " ") do
          @pretty_json = true
        end
+0 −14
Original line number Diff line number Diff line
@@ -113,20 +113,6 @@ describe JsDuck::DocFormatter do
        '<img src="some/image.png" alt="foo&quot;bar"/>'
    end

    # {@example ...}

    it "replaces {@example foo.js} with source from foo.js file" do
      @formatter.get_example = lambda { "Some code" }
      @formatter.replace('{@example foo.js}').should ==
        '<pre class="inline-example"><code>Some code</code></pre>'
    end

    it "escapes HTML inside source of {@example}" do
      @formatter.get_example = lambda { "Some <html> code" }
      @formatter.replace('{@example foo.js}').should ==
        '<pre class="inline-example"><code>Some &lt;html&gt; code</code></pre>'
    end

    # auto-conversion of identifiable ClassNames to links
    describe "auto-detect" do
      before do