Sha256: d69995ca8f8b88ba40646ceac5c990541ae7c491baff3a4d49c91d2bbe1a8d22

Contents?: true

Size: 1.76 KB

Versions: 10

Compression:

Stored size: 1.76 KB

Contents

require 'effective_resources'
require 'effective_posts/engine'
require 'effective_posts/version'

module EffectivePosts

  def self.config_keys
    [
      :posts_table_name, :layout, 
      :categories, :event_categories,
      :mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject,
      :use_category_routes, :use_blog_routes,
      :use_effective_roles, :use_active_storage, :use_description, :use_excerpt,
      :per_page, :post_meta_author,
      :submissions_enabled, :submissions_require_current_user,
      :submissions_require_approval, :submissions_note
    ]
  end

  include EffectiveGem

  def self.mailer_class
    mailer&.constantize || Effective::PostsMailer
  end

  def self.permitted_params
    @permitted_params ||= [
      :title, :excerpt, :description, :save_as_draft, :category, :slug, :published_start_at, :published_end_at, :body, :tags, :extra,
      :image, :start_at, :end_at, :location, :website_name, :website_href, roles: []
    ]
  end

  # Normalize and return the category that matches this value
  def self.category(value, safe: true)
    values = [value, value.to_s, value.to_s.downcase, value.to_s.downcase.parameterize, value.to_s.parameterize]

    category = categories.find do |cat|
      (values & [cat, cat.to_s, cat.to_s.downcase, cat.to_s.downcase.parameterize, cat.to_s.parameterize]).present?
    end

    raise("Unable to find EffectivePosts.category for value '#{value.presence || 'nil'}'") unless safe

    category
  end

  def self.categories
    Array(config[:categories])
  end

  def self.event_categories
    Array(config[:event_categories])
  end

  def self.not_event_categories
    categories - event_categories
  end

  def self.news_categories
    categories - event_categories
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
effective_posts-2.9.3 lib/effective_posts.rb
effective_posts-2.9.2 lib/effective_posts.rb
effective_posts-2.9.1 lib/effective_posts.rb
effective_posts-2.9.0 lib/effective_posts.rb
effective_posts-2.8.0 lib/effective_posts.rb
effective_posts-2.7.4 lib/effective_posts.rb
effective_posts-2.7.3 lib/effective_posts.rb
effective_posts-2.7.2 lib/effective_posts.rb
effective_posts-2.7.1 lib/effective_posts.rb
effective_posts-2.7.0 lib/effective_posts.rb