2018-04-13 19:23:04 -04:00
|
|
|
module ActionText
|
2018-02-08 15:48:45 -05:00
|
|
|
module Attribute
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
2018-04-13 19:47:33 -04:00
|
|
|
def has_rich_text(name)
|
|
|
|
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
|
|
|
def #{name}
|
2018-05-28 11:43:08 -04:00
|
|
|
self.rich_text_#{name} ||= ActionText::RichText.new(name: "#{name}", record: self)
|
2018-04-13 19:47:33 -04:00
|
|
|
end
|
2018-02-14 10:33:30 -05:00
|
|
|
|
2018-04-13 19:47:33 -04:00
|
|
|
def #{name}=(body)
|
|
|
|
#{name}.body = body
|
|
|
|
end
|
|
|
|
CODE
|
2018-02-14 10:33:30 -05:00
|
|
|
|
2018-04-13 19:47:33 -04:00
|
|
|
has_one :"rich_text_#{name}", -> { where(name: name) }, class_name: "ActionText::RichText", as: :record, inverse_of: :record, dependent: false
|
|
|
|
|
|
|
|
scope :"with_rich_text_#{name}", -> { includes("rich_text_#{name}") }
|
2018-02-08 15:48:45 -05:00
|
|
|
end
|
2018-04-13 19:47:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
# def has_rich_text(attribute_name)
|
|
|
|
# serialize(attribute_name, ActionText::Content)
|
|
|
|
#
|
|
|
|
# has_many_attached "#{attribute_name}_attachments"
|
|
|
|
#
|
|
|
|
# after_save do
|
|
|
|
# blobs = public_send(attribute_name).attachments.map(&:attachable)
|
|
|
|
# public_send("#{attribute_name}_attachments_blobs=", blobs)
|
|
|
|
# end
|
|
|
|
# end
|
2018-02-08 15:48:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|