4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'app/models/tomify_record.rb', line 4
def self.to_html(*attrs)
attrs.each do |attr|
define_method("#{attr}_to_html") do
Rails.cache.fetch("#{self.class.name.downcase}-#{id}-#{attr}") do
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
markdown.render(self[attr] || "").html_safe
end
end
end
define_method("bust_html_cache") do
attrs.each do |attr|
Rails.cache.delete("#{self.class.name.downcase}-#{id}-#{attr}")
end
end
after_save :bust_html_cache
end
|