application.rb 3.83 KB
Newer Older
1
require_relative "../lib/crabgrass/info.rb"
2

3

4
info "LOAD FRAMEWORK"
5
require_relative 'boot'
6
7
8
9
10

require 'rails/all'

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
11
  Bundler.require(*Rails.groups(:assets => %w(development test)))
12
13
14
15
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

16
require_relative "../lib/crabgrass/boot.rb"
17
require_relative "../lib/crabgrass/public_exceptions.rb"
18
19
20
21
22
23
24
25

module Crabgrass
  class Application < Rails::Application
    info "LOAD CONFIG BLOCK"

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

26
    config.autoload_paths += %w(chat profile poll requests mailers notice).
27
28
29
30
31
32
33
34
35
36
37
38
39
40
     collect { |dir| "#{Rails.root}/app/models/#{dir}" }
    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.
    config.encoding = "utf-8"

    # 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
    config.active_record.schema_format = :sql

41
42
    config.active_support.deprecation = :notify

43

44
    config.session_store :cookie_store,
azul's avatar
azul committed
45
46
47
      :key => 'crabgrass_session'

    config.secret_token = Conf.secret
48

49
50
51
52
53
54
55
    # 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'

56
57
58
    # store fragments on disk, we might have a lot of them.
    config.action_controller.cache_store = :file_store, CACHE_DIRECTORY

59
    # add our custom error classes
60
    config.action_dispatch.rescue_responses.merge!(
61
      'ErrorNotFound' => :not_found,
62
      'Wiki::Sections::SectionNotFoundError' => :not_found,
63
64
      'PermissionDenied' => :forbidden,
      'AuthenticationRequired' => :unauthorized
65
    )
66

67
68
69
70
71
72
73
74
75
    # 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

76
    config.exceptions_app = Crabgrass::PublicExceptions.new(Rails.public_path)
77

78
79
80
81
    ##
    ## PLUGINS
    ##

82
    config.before_configuration do
83
84
85
86
87
88
89
90
91
      Pathname.glob(CRABGRASS_PLUGINS_DIRECTORY + '*').each do |plugin|
        info "LOAD #{plugin.basename.to_s.humanize}"
        $:.unshift plugin + 'lib'
        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}"
92
93
94
        require page
      end
    end
95

96
97
98
99
100
101
102
103
    #
    # 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

104
105
106
107
108
109
    initializer "crabgrass_page.freeze_pages" do |app|
      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

110
111
  end

112
  ## FIXME: require these, where they are actually needed (or fix autoloading).
113
114
115
116
117
  require 'int_array'
  require 'crabgrass/validations'
  require 'crabgrass/page/class_proxy'
  require 'crabgrass/page/class_registrar'
  require 'crabgrass/page/data'
118

119
end