Sha256: 93f5d8baa285ce8be97939dbdfec018fdaf973bd6378ef5c2e5d9ce9b3ccc7a1

Contents?: true

Size: 1.5 KB

Versions: 15

Compression:

Stored size: 1.5 KB

Contents

require 'maruku'

class Maruku
  include Stringlike
  
  attr_reader :text
  
  def initialize(s=nil, meta={})
    super(nil)
    self.attributes.merge! meta
    if s
      @text = s
      parse_doc(s)
    end
  end
  
  # Used to get the original Markdown text.
  def to_s
    @text
  end
  
  # used to be compatable with Rails/ActiveSupport
  def blank?
    @text.blank?
  end
  
end

class String
  alias_method :to_html, :to_s
  
  def to_xml
    REXML::Text.new(self)
  end
end

module MaRuKu # :nodoc:
  module Out # :nodoc:
    module HTML
      
      # We patch this method to play nicely with our own modifications of String.
      #
      # It originally used a +to_html+ method on String we've swapped this out for a +to_xml+ 
      # method because we need +to_html+ to return the original text on plain text fields of
      # the variable language option on +acts_as_markup+
      def array_to_html(array)
        elements = []
        array.each do |item|
          method = item.kind_of?(MDElement) ? "to_html_#{item.node_type}" : "to_xml"
          unless item.respond_to?(method)
            next
          end

          html_text =  item.send(method)
          if html_text.nil?
            raise "Nil html created by method  #{method}:\n#{html_text.inspect}\n for object #{item.inspect[0,300]}"
          end

          if html_text.kind_of?Array
            elements = elements + html_text
          else
            elements << html_text
          end
        end
        elements
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
acts_as_markup-2.0.2 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-2.0.1 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-2.0.0 lib/acts_as_markup/exts/maruku.rb
vigetlabs-acts_as_markup-1.3.1 lib/acts_as_markup/exts/maruku.rb
vigetlabs-acts_as_markup-1.3.2 lib/acts_as_markup/exts/maruku.rb
vigetlabs-acts_as_markup-1.3.3 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-1.4.2 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-1.4.1 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-1.4.0 lib/acts_as_markup/exts/maruku.rb
acts_as_markup_extended-1.0.2 lib/acts_as_markup/exts/maruku.rb
acts_as_markup_extended-1.0.1 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-1.3.4 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-1.3.3 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-1.3.2 lib/acts_as_markup/exts/maruku.rb
acts_as_markup-1.3.1 lib/acts_as_markup/exts/maruku.rb