Sha256: 60ed0fa5b778fdc86f96962d043104befec11242a1920bbc8917d1ce93ccbbc3

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

module Maildown
  class Md
    attr_accessor :string

    # responses is an array of hashes containing a body: and :content_type
    def initialize(responses)
      @responses  = responses.reject {|r| r[:content_type] == Mime[:html].to_s || r[:content_type] == Mime[:text].to_s }
      md_response = responses.detect {|r| r[:content_type] == Mime[:md].to_s }
      if md_response.present?
        @string = md_response[:body]
        @responses.delete(md_response)
      end
    end

    def to_text
      Maildown::MarkdownEngine.to_text(string)
    end

    def to_html
      Maildown::MarkdownEngine.to_html(string)
    end

    def to_responses
      [
        { body: to_text, content_type: "text/plain"},
        { body: to_html, content_type: "text/html"}
      ].concat(@responses)
    end


    def contains_md?
      string.present?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maildown-2.0.1 lib/maildown/md.rb