module Mongoid::Markdown::ClassMethods

Public Instance Methods

field(name, options = {}) click to toggle source
Calls superclass method
# File lib/mongoid-markdown/mongoid_old.rb, line 43
def field(name, options = {})
  returning super(name, options.reject { |k, v| k == :markdown }) do
    markdown name if options[:markdown]
  end
end
markdown(*attributes) click to toggle source
# File lib/mongoid-markdown/mongoid_new.rb, line 104
def markdown(*attributes)        
  @markdown_unicode = String.new.respond_to? :chars

  type_options = %w( plain source )

  attributes.each do |attribute|
    define_method(attribute) do |*type|
      type = type.first
      value = read_attribute(attribute)

      if type.nil? && value
        marked_down[attribute.to_sym] ||= RDiscount.new(value).to_html.html_safe
      elsif type.nil? && value.nil?
        nil
      elsif type_options.include?(type.to_s)
        send("#{attribute}_#{type}")
      else
        raise "I don't understand the `#{type}' option.  Try #{type_options.join(' or ')}."
      end
    end

    define_method("#{attribute}_plain",  proc { strip_markdown_html(__send__(attribute)) if __send__(attribute) } )
    define_method("#{attribute}_source", proc { read_attribute(attribute) } )
  end

  include InstanceMethods
end
markdown_attributes() click to toggle source
# File lib/mongoid-markdown/mongoid_old.rb, line 38
def markdown_attributes
  read_inheritable_attribute(:markdown_attributes) ||
  write_inheritable_attribute(:markdown_attributes, [])
end