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
|