Sha256: eb232b84e41d74934c1d891f896dd7010bd01c82fc000706cdf498c9f2db9604

Contents?: true

Size: 1.3 KB

Versions: 16

Compression:

Stored size: 1.3 KB

Contents

require 'ostruct'

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=OpenStruct.new)
        @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

16 entries across 16 versions & 3 rubygems

Version Path
solvas-jsduck-6.0.0.30539 lib/jsduck/inline/example.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/inline/example.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/inline/example.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/inline/example.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/inline/example.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/inline/example.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/inline/example.rb
jsduck-troopjs-0.0.10 lib/jsduck/inline/example.rb
jsduck-troopjs-0.0.9 lib/jsduck/inline/example.rb
jsduck-troopjs-0.0.8 lib/jsduck/inline/example.rb
jsduck-troopjs-0.0.7 lib/jsduck/inline/example.rb
jsduck-troopjs-0.0.5 lib/jsduck/inline/example.rb
jsduck-troopjs-0.0.4 lib/jsduck/inline/example.rb
jsduck-troopjs-0.0.3 lib/jsduck/inline/example.rb
jsduck-troopjs-0.0.1 lib/jsduck/inline/example.rb
jsduck-6.0.0beta lib/jsduck/inline/example.rb