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

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

require 'rails/all'

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

15
require_relative "../lib/crabgrass/boot.rb"
16
require_relative "../lib/crabgrass/public_exceptions.rb"
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

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

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

    config.autoload_paths += %w(activity assets associations discussion chat observers profile poll task tracking requests mailers notice).
     collect { |dir| "#{Rails.root}/app/models/#{dir}" }
    config.autoload_paths << "#{Rails.root}/app/permissions"
    config.autoload_paths << "#{Rails.root}/app/sweepers"
    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
45
46
    # Enforce whitelist mode for mass assignment.
    # This will create an empty whitelist of attributes available for mass-assignment for all models
    # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
    # parameters by using an attr_accessible or attr_protected declaration.
47
48
    #
    # We use strong parameters instead like rails4 does.
49
50
    #config.active_record.whitelist_attributes = true

51
    config.active_record.observers = :user_observer,
azul's avatar
azul committed
52
    :relationship_observer, :request_to_destroy_our_group_observer,
53
54
    :request_observer, :page_observer, "tracking/page_observer",
    "tracking/post_observer", "tracking/wiki_observer",
azul's avatar
azul committed
55
    "tracking/user_participation_observer", "tracking/group_participation_observer"
56

57
    config.session_store :cookie_store,
azul's avatar
azul committed
58
59
60
      :key => 'crabgrass_session'

    config.secret_token = Conf.secret
61

62
63
64
65
66
67
68
    # 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'

69
70
71
    # store fragments on disk, we might have a lot of them.
    config.action_controller.cache_store = :file_store, CACHE_DIRECTORY

72
73
74
75
    # add our custom 404 error class
    config.action_dispatch.rescue_responses.merge!(
      'ErrorNotFound' => :not_found
    )
76
77
78
79
80
81
82
83
84
    # 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

85
    config.exceptions_app = Crabgrass::PublicExceptions.new(Rails.public_path)
86

87
88
89
90
    ##
    ## PLUGINS
    ##

91
    config.before_configuration do
92
93
94
95
96
97
98
99
100
      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}"
101
102
103
        require page
      end
    end
104
105
106
107
108
109
110

    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

111
112
  end

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

120
end