Sha256: d40b7e8bf181aaa40301c275ad4211595b39b6b3b047879ec3df92613a9abdea

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module RailsAdminContentBuilder
  class ContentBuilder < ActiveRecord::Base
    include SearchCop
    extend FriendlyId

    self.table_name = 'content_builders'

    friendly_id :title, use: :slugged

    validates :title, :date_publish, :content_builder_category,
              :written_by, presence: true

    has_many :content_builder_images, inverse_of: :content_builder,
                                      dependent: :destroy
    belongs_to :content_builder_category, inverse_of: :content_builders

    search_scope :search do
      attributes :title
    end

    def content_sanitized
      white_list_sanitizer = Rails::Html::WhiteListSanitizer.new
      white_list_sanitizer.sanitize(
        content,
        tags: tags_hash,
        attributes: attributes_hash
      ).try(:html_safe)
    end

    def tags_hash
      %w(
        div b i a u p img figure figcaption a iframe footer aside
        section blockquote ul ol li h1 h2 h3 h4 h5 h6
      )
    end

    def attributes_hash
      %w(
        src class alt href allowfullscreen frameborder height width
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_admin_content_builder-1.0.6 app/models/rails_admin_content_builder/content_builder.rb
rails_admin_content_builder-1.0.5 app/models/rails_admin_content_builder/content_builder.rb