Sha256: eb8a48b4f4136384f1c2f664e0c454353e5388c256d6f378c3d34bb7ca77497a

Contents?: true

Size: 680 Bytes

Versions: 2

Compression:

Stored size: 680 Bytes

Contents

module Blocky
  class ContentBlock < ActiveRecord::Base
    before_save :tidy_content

    scope :global,   -> { where("page_path IS NULL") }
    scope :per_page, -> { where("page_path IS NOT NULL") }

    def global?
      self.page_path.nil?
    end

    def tidy_content
      tidy = Tidy.new({
        char_encoding: "raw",
        doctype: "omit",
        indent: "auto",
        indent_spaces: 2,
        markup: true,
        output_xhtml: true,
        show_body_only: "yes",
        tab_size: 2,
        tidy_mark: false
      })
      html = tidy.clean(self.content.to_s.strip)
      self.content = "\n" + (html.blank? ? "<p><br/></p>" : html) + "\n"
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blocky-0.0.5 app/models/blocky/content_block.rb
blocky-0.0.4 app/models/blocky/content_block.rb