4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# 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
options = { autolink: true, tables: true }
options.merge!(self.markdown_options) if self.try(:markdown_options)
markdown = Redcarpet::Markdown.new(Tomify::Markdown::HTML, options)
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
|