Sha256: ec26a4ab8bb8e145f1554e92d27ea67219784b00acd677896f1ae1299b7ed82b

Contents?: true

Size: 1.17 KB

Versions: 21

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require "cancancan"

class BaseController < ApplicationController
  before_action :fire_triggers, :load_lang, :set_paths

  private

  def login_required
    authenticate_user! && authorize!(params[:action], params[:controller])
  end

  def set_paths
    prepend_view_path this_blog.current_theme.view_path
    Dir.glob(File.join(::Rails.root.to_s, "lib", "*_sidebar/app/views")).select do |file|
      append_view_path file
    end
  end

  def fire_triggers
    Trigger.fire
  end

  def load_lang
    if I18n.available_locales.include?(this_blog.lang.to_sym)
      I18n.locale = this_blog.lang
    elsif I18n.available_locales.include?(this_blog.lang[0..1].to_sym)
      I18n.locale = this_blog.lang[0..1]
    # for the same language used in different areas, e.g. zh_CN, zh_TW
    elsif I18n.available_locales.include?(this_blog.lang.sub("_", "-").to_sym)
      I18n.locale = this_blog.lang.sub("_", "-")
    end
  end

  def add_to_cookies(name, value, path = nil, _expires = nil)
    cookies[name] = { value: value,
                      path: path || "/#{controller_name}",
                      expires: 6.weeks.from_now }
  end

  include BlogHelper
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
HornsAndHooves-publify_core-10.5.0 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.4.0 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.3.0 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.2.0 app/controllers/base_controller.rb
publify_core-9.2.10 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.1.1 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.1.0 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.0.3 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.0.2 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.0.1 app/controllers/base_controller.rb
HornsAndHooves-publify_core-10.0.0 app/controllers/base_controller.rb
publify_core-9.2.9 app/controllers/base_controller.rb
publify_core-9.2.8 app/controllers/base_controller.rb
publify_core-9.2.7 app/controllers/base_controller.rb
publify_core-9.2.6 app/controllers/base_controller.rb
publify_core-9.2.5 app/controllers/base_controller.rb
publify_core-9.2.4 app/controllers/base_controller.rb
publify_core-9.2.3 app/controllers/base_controller.rb
publify_core-9.2.2 app/controllers/base_controller.rb
publify_core-9.2.1 app/controllers/base_controller.rb