Module: Mongoid::Markdown::ClassMethods
- Defined in:
- lib/mongoid-markdown/mongoid_new.rb,
lib/mongoid-markdown/mongoid_old.rb
Instance Method Summary collapse
- #field(name, options = {}) ⇒ Object
-
#markdown(*attributes) ⇒ Object
For mongoid < 2.4 only.
- #markdown_attributes ⇒ Object
Instance Method Details
#field(name, options = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/mongoid-markdown/mongoid_old.rb', line 43 def field(name, = {}) returning super(name, .reject { |k, v| k == :markdown }) do markdown name if [: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 = %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 .include?(type.to_s) send("#{attribute}_#{type}") else raise "I don't understand the `#{type}' option. Try #{.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 ⇒ Object
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 |