Sha256: e74eee5f22bf2f68c1e7f8a34ecfcaae95a47ab30c8aa0d02561feafaf998079

Contents?: true

Size: 1.27 KB

Versions: 36

Compression:

Stored size: 1.27 KB

Contents

module JsDuck
  module Inline

    # Implementation of @example tag.
    #
    # Looks for @example tag at the beginning of code blocks. When
    # found, adds an "inline-example" CSS class to the <pre> element.
    #
    # Unlike other Inline:: classes this doesn't implement an
    # {@example} tag as could be expected.  But it fits nicely along
    # with other inline tags as it's processed inside DocFormatter, so
    # it mostly fits here along with the others.
    #
    class Example
      # Constructor takes opts parameter for consistency with other
      # JsDuck::Inline::* classes.
      def initialize(opts={})
        @re = /<pre><code>\s*@example( +[^\n]*)?\s+/m
      end

      # Takes StringScanner instance.
      #
      # Looks for "<pre><code>@example" at the current scan pointer
      # position, when found, moves scan pointer forward and performs
      # the apporpriate replacement.
      def replace(input)
        if input.check(@re)
          # Match possible classnames following @example and add them
          # as CSS classes inside <pre> element.
          input.scan(@re) =~ @re
          css_classes = ($1 || "").strip

          return "<pre class='inline-example #{css_classes}'><code>"
        else
          false
        end
      end

    end

  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
jsduck-5.3.4 lib/jsduck/inline/example.rb
jsduck-5.3.3 lib/jsduck/inline/example.rb
jsduck-5.3.2 lib/jsduck/inline/example.rb
jsduck-5.3.1 lib/jsduck/inline/example.rb
jsduck-5.3.0 lib/jsduck/inline/example.rb
jsduck-5.2.0 lib/jsduck/inline/example.rb
jsduck-5.1.0 lib/jsduck/inline/example.rb
jsduck-5.0.1 lib/jsduck/inline/example.rb
jsduck-5.0.0 lib/jsduck/inline/example.rb
jsduck-5.0.0.beta5 lib/jsduck/inline/example.rb
jsduck-5.0.0.beta4 lib/jsduck/inline/example.rb
jsduck-4.10.4 lib/jsduck/inline/example.rb
jsduck-5.0.0.beta3 lib/jsduck/inline/example.rb
jsduck-4.10.3 lib/jsduck/inline/example.rb
jsduck-4.10.2 lib/jsduck/inline/example.rb
jsduck-4.10.1 lib/jsduck/inline/example.rb
jsduck-4.10.0 lib/jsduck/inline/example.rb
jsduck-4.9.0 lib/jsduck/inline/example.rb
jsduck-4.8.0 lib/jsduck/inline/example.rb
jsduck-5.0.0.beta2 lib/jsduck/inline/example.rb