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
solvas-jsduck-6.0.0.30539 lib/jsduck/doc/comment.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/doc/comment.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/doc/comment.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/doc/comment.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/doc/comment.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/doc/comment.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/doc/comment.rb
jsduck-troopjs-0.0.10 lib/jsduck/doc/comment.rb
jsduck-troopjs-0.0.9 lib/jsduck/doc/comment.rb
jsduck-troopjs-0.0.8 lib/jsduck/doc/comment.rb
jsduck-troopjs-0.0.7 lib/jsduck/doc/comment.rb
jsduck-troopjs-0.0.5 lib/jsduck/doc/comment.rb
jsduck-troopjs-0.0.4 lib/jsduck/doc/comment.rb
jsduck-troopjs-0.0.3 lib/jsduck/doc/comment.rb
jsduck-troopjs-0.0.1 lib/jsduck/doc/comment.rb
jsduck-6.0.0beta lib/jsduck/doc/comment.rb
jsduck-5.3.4 lib/jsduck/doc/comment.rb
jsduck-5.3.3 lib/jsduck/doc/comment.rb
jsduck-5.3.2 lib/jsduck/doc/comment.rb
jsduck-5.3.1 lib/jsduck/doc/comment.rb