application.rb 3.79 KB
Newer Older
azul's avatar
azul committed
1
require_relative '../lib/crabgrass/info.rb'
2

azul's avatar
azul committed
3
info 'LOAD FRAMEWORK'
4
require_relative 'boot'
5
6
7

require 'rails/all'

8
9
10
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
11

azul's avatar
azul committed
12
13
require_relative '../lib/crabgrass/boot.rb'
require_relative '../lib/crabgrass/public_exceptions.rb'
14
15
16

module Crabgrass
  class Application < Rails::Application
azul's avatar
azul committed
17
    info 'LOAD CONFIG BLOCK'
18
19
20
21

    config.autoload_paths << "#{Rails.root}/lib"
    config.autoload_paths << "#{Rails.root}/app/models"

azul's avatar
azul committed
22
23
    config.autoload_paths += %w[chat profile requests mailers]
                             .collect { |dir| "#{Rails.root}/app/models/#{dir}" }
24
25
26
27
    config.autoload_paths << "#{Rails.root}/app/permissions"
    config.autoload_paths << "#{Rails.root}/app/helpers/classes"

    # Configure the default encoding used in templates for Ruby 1.9.
azul's avatar
azul committed
28
    config.encoding = 'utf-8'
29
30
31
32
33
34

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]

    # Enable escaping HTML in JSON.
    config.active_support.escape_html_entities_in_json = true
35
    config.active_record.disable_implicit_join_references = true
36

37
38
    config.active_support.deprecation = :notify

39
    config.session_store :cookie_store,
azul's avatar
azul committed
40
                         key: 'crabgrass_session'
azul's avatar
azul committed
41

42
43
44
45
46
47
48
    # Enable the asset pipeline
    config.assets.enabled = true
    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'
    # We serve assets from /static because /assets is already used
    config.assets.prefix = '/static'

49
50
51
    # store fragments on disk, we might have a lot of them.
    config.action_controller.cache_store = :file_store, CACHE_DIRECTORY

azul's avatar
azul committed
52
53
    # use the new json based cookies.
    config.action_dispatch.cookies_serializer = :hybrid
54
    # add our custom error classes
55
    config.action_dispatch.rescue_responses.merge!(
56
      'ErrorNotFound' => :not_found,
57
      'Wiki::Sections::SectionNotFoundError' => :not_found,
58
59
      'PermissionDenied' => :forbidden,
      'AuthenticationRequired' => :unauthorized
60
    )
61

62
63
64
65
66
67
68
69
70
    # Make Active Record use UTC-base instead of local time
    config.time_zone = 'UTC'
    config.active_record.default_timezone = :utc

    # Deliveries are disabled by default. Do NOT modify this section.
    # Define your email configuration in email.yml instead.
    # It will automatically turn deliveries on
    config.action_mailer.perform_deliveries = false

71
    config.exceptions_app = Crabgrass::PublicExceptions.new(Rails.public_path)
72

73
74
75
76
    ##
    ## PLUGINS
    ##

77
    config.before_configuration do
78
79
      Pathname.glob(CRABGRASS_PLUGINS_DIRECTORY + '*').each do |plugin|
        info "LOAD #{plugin.basename.to_s.humanize}"
azul's avatar
azul committed
80
        $LOAD_PATH.unshift plugin + 'lib'
81
82
83
84
85
86
        require plugin + 'init.rb'
      end

      # TODO: respect Conf.enabled_pages, ENV['PAGE'] 'page' and ENV['PAGE'] ALL
      Pathname.glob(PAGES_DIRECTORY + '*/lib/*_page.rb').each do |page|
        info "LOAD #{page.basename('.rb').to_s.humanize}"
87
88
89
        require page
      end
    end
90

91
92
93
94
95
96
97
98
    #
    # Reload the permissions when reloading models in development and once
    # in production.
    # (They monkeypatch the User and Group classes.)
    config.to_prepare do
      CastleGates.initialize('config/permissions')
    end

azul's avatar
azul committed
99
    initializer 'crabgrass_page.freeze_pages' do |_app|
100
101
102
103
      require 'crabgrass/page/class_registrar'
      ::PAGES = Crabgrass::Page::ClassRegistrar.proxies.dup.freeze
      Conf.available_page_types = PAGES.keys if Conf.available_page_types.empty?
    end
104
105
  end

106
  ## FIXME: require these, where they are actually needed (or fix autoloading).
107
108
109
110
111
  require 'int_array'
  require 'crabgrass/validations'
  require 'crabgrass/page/class_proxy'
  require 'crabgrass/page/class_registrar'
  require 'crabgrass/page/data'
112
end