Sha256: 6e98dbea0d0804e2d2367fd3ca24cdaebb369a7354de989d7aa5725f217adc61

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

module Enjoy
  module Models
    module News
      extend ActiveSupport::Concern
      include Enjoy::Model
      include ManualSlug
      include Enjoy::Seoable
      include Enjoy::Enableable
      include Enjoy::SitemapDataField
      include Enjoy::Connectable

      include Enjoy.orm_specific('News')

      # if Enjoy.config.search_enabled
      #   include Enjoy::ElasticSearch
      # end

      included do
        enjoy_connectable_field :connected_pages

        unless Enjoy.config.news_image_styles.nil?
          validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
        end

        validates_presence_of :name
        if Enjoy.config.news_content_required
          validates_presence_of :content_html
        end

        before_validation do
          self.time = Time.now if self.time.blank?
        end
        scope :recent, ->(count = 5) { enabled.after_now.by_date.limit(count) }
        unless Enjoy.config.news_per_page.nil?
          paginates_per Enjoy.config.news_per_page
        end
        smart_excerpt :excerpt, :content, Enjoy.config.news_excerpt
        manual_slug :report_slug
      end

      def report_slug
        if time.blank?
          name
        elsif name.blank?
          time.strftime('%Y-%m-%d')
        else
          time.strftime('%Y-%m-%d') + '-' + name[0..20]
        end
      end
      def html5_date
        time.strftime('%Y-%m-%d')
      end
      def format_date
        time.strftime(I18n.t('Enjoy.format_time'))
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
enjoy_cms-0.3.7.4 lib/enjoy/models/news.rb
enjoy_cms-0.3.7.3 lib/enjoy/models/news.rb
enjoy_cms-0.3.7.2 lib/enjoy/models/news.rb
enjoy_cms-0.3.7.1 lib/enjoy/models/news.rb
enjoy_cms-0.3.7 lib/enjoy/models/news.rb
enjoy_cms-0.3.6.2 lib/enjoy/models/news.rb
enjoy_cms-0.3.6.1 lib/enjoy/models/news.rb
enjoy_cms-0.3.6 lib/enjoy/models/news.rb
enjoy_cms-0.3.5 lib/enjoy/models/news.rb