Sha256: ff01a0ea7bcce6fa8b0774a564336145e0ee18fe52799b59a79da8333c00fc29

Contents?: true

Size: 899 Bytes

Versions: 5

Compression:

Stored size: 899 Bytes

Contents

module AbAdmin
  module Models
    module Header
      extend ActiveSupport::Concern

      included do
        include ActionView::Helpers::SanitizeHelper

        belongs_to :headerable, polymorphic: true
        before_save :normalize_html
      end
      
      def empty?
        [keywords, description, title].map(&:blank?).all?
      end

      def has_info?
        !empty?
      end

      def read(key)
        value = read_attribute(key)
        value.blank? ? nil : value
      end

      def normalize_html
        ::Globalize.available_locales.each do |loc|
          %w(title h1 keywords description).each do |attr|
            send("#{attr}_#{loc}=", send("#{attr}_#{loc}").to_s.no_html)
          end
        end
        ::Globalize.available_locales.each do |loc|
          send("seo_block_#{loc}=", sanitize(send("seo_block_#{loc}").to_s))
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ab_admin-0.8.3 lib/ab_admin/models/header.rb
ab_admin-0.8.2 lib/ab_admin/models/header.rb
ab_admin-0.8.1 lib/ab_admin/models/header.rb
ab_admin-0.8.0 lib/ab_admin/models/header.rb
ab_admin-0.7.0 lib/ab_admin/models/header.rb