Sha256: c56c3abdbff2b99f2a97d65e0d931637ac95d1b72620eb38d3e9627ce97be0c1

Contents?: true

Size: 743 Bytes

Versions: 7

Compression:

Stored size: 743 Bytes

Contents

# frozen_string_literal: true

module Onebox
  module Mixins
    module GithubBody
      def self.included(klass)
        klass.include(Onebox::Engine)
        klass.include(InstanceMethods)
      end

      module InstanceMethods
        GITHUB_COMMENT_REGEX = /(<!--.*?-->\r\n)/
        MAX_BODY_LENGTH = 80
        def compute_body(body)
          body = body.dup
          excerpt = nil

          body = (body || '').gsub(GITHUB_COMMENT_REGEX, '')
          body = body.length > 0 ? body : nil
          if body && body.length > MAX_BODY_LENGTH
            excerpt = body[MAX_BODY_LENGTH..body.length].rstrip
            body = body[0..MAX_BODY_LENGTH - 1]
          end

          [body, excerpt]
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
onebox-2.2.19 lib/onebox/mixins/github_body.rb
onebox-2.2.18 lib/onebox/mixins/github_body.rb
onebox-2.2.17 lib/onebox/mixins/github_body.rb
onebox-2.2.16 lib/onebox/mixins/github_body.rb
onebox-2.2.15 lib/onebox/mixins/github_body.rb
onebox-2.2.14 lib/onebox/mixins/github_body.rb
onebox-2.2.13 lib/onebox/mixins/github_body.rb