Sha256: 1e52ef3cff40e66ed999b47ae4ffd3e801e91759017fdac4efcc2383549718e7
Contents?: true
Size: 996 Bytes
Versions: 6
Compression:
Stored size: 996 Bytes
Contents
module Admin class Post < ::Post has_one :header, class_name: Admin::Image has_many :titles, -> { order "titles.created_at DESC" }, class_name: Admin::Title before_save :compile!, prepend: true before_save :excerptize! def publish!(params = {}) self.assign_attributes(params) self.published_at = DateTime.now self.save! end def unpublish!(params = {}) self.assign_attributes(params) self.published_at = nil self.save! end def stylesheet super || "" end def javascript super || "" end def content read_attribute(:content) || "" end private def compile! self.compiled_content = Ecrire::Markdown.parse(self.content).to_html end def excerptize! html = Nokogiri::HTML(self.compiled_content) html.xpath("//img").each do |img| img.remove end self.compiled_excerpt = html.xpath('//body').children[0..20].to_s end end end
Version data entries
6 entries across 6 versions & 1 rubygems