Sha256: 21adec76292f9bec33214631b714817c607de24440de4cf6aa46b3ba710dd46d

Contents?: true

Size: 995 Bytes

Versions: 69

Compression:

Stored size: 995 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module Language
    module Comments
      extend self

      def commentize(description, indent: '')
        lines = description.split("\n")

        comment = ''.dup

        lines.each do |line|
          if line == ''
            comment << "#{indent}#\n"
          else
            sublines = break_line(line, 120 - indent.length)
            sublines.each do |subline|
              comment << "#{indent}# #{subline}\n"
            end
          end
        end

        comment
      end

      private

      def break_line(line, length)
        return [line] if line.length < length + 5

        parts = line.split(Regexp.new("((?: |^).{15,#{length - 40}}(?= |$))"))
        return [line] if parts.length < 4

        sublines = [parts.slice!(0, 3).join]

        parts.each_with_index do |part, i|
          next if i % 2 == 1
          sublines << "#{part[1..-1]}#{parts[i + 1]}"
        end

        sublines
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
graphql-1.9.0.pre1 lib/graphql/language/comments.rb
graphql-1.8.11 lib/graphql/language/comments.rb
graphql-1.8.10 lib/graphql/language/comments.rb
graphql-1.8.9 lib/graphql/language/comments.rb
graphql-1.8.8 lib/graphql/language/comments.rb
graphql-1.8.7 lib/graphql/language/comments.rb
graphql-1.8.6 lib/graphql/language/comments.rb
graphql-1.8.5 lib/graphql/language/comments.rb
graphql-1.8.4 lib/graphql/language/comments.rb
graphql-1.8.3 lib/graphql/language/comments.rb
graphql-1.8.2 lib/graphql/language/comments.rb
graphql-1.8.1 lib/graphql/language/comments.rb
graphql-1.8.0 lib/graphql/language/comments.rb
graphql-1.8.0.pre11 lib/graphql/language/comments.rb
graphql-1.8.0.pre10 lib/graphql/language/comments.rb
graphql-1.7.14 lib/graphql/language/comments.rb
graphql-1.8.0.pre9 lib/graphql/language/comments.rb
graphql-1.8.0.pre8 lib/graphql/language/comments.rb
graphql-1.7.13 lib/graphql/language/comments.rb
graphql-1.8.0.pre7 lib/graphql/language/comments.rb