Sha256: e621bbf82d58e070056449f8a49b9ab01aa593977b32b5b2f9f57d832e8f4aef

Contents?: true

Size: 1021 Bytes

Versions: 30

Compression:

Stored size: 1021 Bytes

Contents

module JsDuck
  module Doc

    # A simple helper to extract doc comment contents.
    class Comment

      # Extracts content inside /** ... */
      def self.purify(input)
        result = []

        # We can have two types of lines:
        # - those beginning with *
        # - and those without it
        indent = nil
        input.each_line do |line|
          line.chomp!
          if line =~ /\A\s*\*\s?(.*)\z/
            # When comment contains *-lines, switch indent-trimming off
            indent = 0
            result << $1
          elsif line =~ /\A\s*\z/
            # pass-through empty lines
            result << line
          elsif indent == nil && line =~ /\A(\s*)(.*?\z)/
            # When indent not measured, measure it and remember
            indent = $1.length
            result << $2
          else
            # Trim away indent if available
            result << line.sub(/\A\s{0,#{indent||0}}/, "")
          end
        end

        result.join("\n")
      end

    end

  end
end

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
jsduck-5.3.0 lib/jsduck/doc/comment.rb
jsduck-5.2.0 lib/jsduck/doc/comment.rb
jsduck-5.1.0 lib/jsduck/doc/comment.rb
jsduck-5.0.1 lib/jsduck/doc/comment.rb
jsduck-5.0.0 lib/jsduck/doc/comment.rb
jsduck-5.0.0.beta5 lib/jsduck/doc/comment.rb
jsduck-5.0.0.beta4 lib/jsduck/doc/comment.rb
jsduck-5.0.0.beta3 lib/jsduck/doc/comment.rb
jsduck-5.0.0.beta2 lib/jsduck/doc/comment.rb
jsduck-5.0.0.beta01 lib/jsduck/doc/comment.rb