Module: Mongoid::Markdown::ClassMethods

Defined in:
lib/mongoid-markdown/mongoid_new.rb,
lib/mongoid-markdown/mongoid_old.rb

Instance Method Summary collapse

Instance Method Details

#field(name, options = {}) ⇒ Object



43
44
45
46
47
# 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) ⇒ Object

For mongoid < 2.4 only



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mongoid-markdown/mongoid_old.rb', line 9

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_attributesObject



38
39
40
41
# File 'lib/mongoid-markdown/mongoid_old.rb', line 38

def markdown_attributes
  read_inheritable_attribute(:markdown_attributes) ||
  write_inheritable_attribute(:markdown_attributes, [])
end