Sha256: 72735517e2fad4dad3f787b7ac5b998a3b68ad95fbe146f677cb0ac162ae2a38

Contents?: true

Size: 704 Bytes

Versions: 4

Compression:

Stored size: 704 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).force_encoding("utf-8")
      self.content = "\n" + (html.blank? ? "<p><br/></p>" : html) + "\n"
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blocky-0.0.9 app/models/blocky/content_block.rb
blocky-0.0.8 app/models/blocky/content_block.rb
blocky-0.0.7 app/models/blocky/content_block.rb
blocky-0.0.6 app/models/blocky/content_block.rb