1
config.gem "mislav-will_paginate", :lib => 'will_paginate', 
2
                                   :version => '>= 2.3.2',
3
                                   :source => 'http://gems.github.com/'
4
5
# Make Station app/ paths reloadable
6
ActiveSupport::Dependencies.load_once_paths.delete_if { |p| p =~ /^#{ directory }\/app/ }
7
8
# Core Extensions
9
require_dependency 'station/core_ext'
10
11
# ActiveRecord
12
require_dependency 'active_record/authorization'
13
ActiveRecord::Base.send :include, ActiveRecord::Authorization
14
15
require_dependency 'active_record/acts_as'
16
ActiveRecord::Base.extend ActiveRecord::ActsAs
17
18
# Initialize all Singular Agents
19
if SingularAgent.table_exists?
20
  SingularAgent
21
  Anonymous.current
22
  Anyone.current
23
  Authenticated.current
24
  CronAgent.current
25
end
26
27
# Mime Types
28
# Redefine Mime::ATOM to include "application/atom+xml;type=entry"
29
Mime::Type.register "application/atom+xml", :atom, [ "application/atom+xml;type=entry" ]
30
Mime::Type.register "application/atomsvc+xml", :atomsvc
31
Mime::Type.register "application/atomcat+xml", :atomcat
32
Mime::Type.register "application/xrds+xml",    :xrds
33
34
# ActionController
35
for mod in [ ActionController::Station, ActionController::Authentication, ActionController::Authorization ]
36
  ActionController::Base.send(:include, mod) unless ActionController::Base.ancestors.include?(mod)
37
end
38
39
# ActionView
40
# Helpers
41
%w( logos sortable sources station tags ).each do |item|
42
  require_dependency "action_view/helpers/#{ item }_helper"
43
  ActionView::Base.send :include, "ActionView::Helpers::#{ item.camelcase }Helper".constantize
44
end
45
# FormHelpers
46
%w( logo tags ).each do |item|
47
  require_dependency "action_view/helpers/form_#{ item }_helper"
48
  ActionView::Base.send :include, "ActionView::Helpers::Form#{ item.camelcase }Helper".constantize
49
end
50
51
# Inflections
52
ActiveSupport::Inflector.inflections do |inflect|
53
  inflect.uncountable 'cas'
54
  inflect.uncountable 'anonymous'
55
end
56
57
# i18n
58
locale_files = 
59
  Dir[ File.join(File.join(directory, 'config', 'locales'), '*.{rb,yml}') ]
60
61
if locale_files.present?
62
  first_app_element = 
63
    I18n.load_path.select{ |e| e =~ /^#{ RAILS_ROOT }/ }.reject{ |e|
64
      e =~ /^#{ RAILS_ROOT }\/vendor\/plugins/ }.first
65
66
  app_index = I18n.load_path.index(first_app_element) || - 1
67
68
  I18n.load_path.insert(app_index, *locale_files)
69
end
70
71
# Models Preload
72
file_patterns = [ File.dirname(__FILE__), RAILS_ROOT ].map{ |f| f + '/app/models/**/*.rb' }
73
file_exclusions = ['svn', 'CVS', 'bzr']
74
file_patterns.reject{ |f| f =~ /#{file_exclusions.join("|")}/ }
75
76
preloaded_files = []
77
# # Lazy files need other files to be loaded first
78
lazy_files = [ ]
79
80
# # Find all source files that need preloading
81
file_patterns.each do |file_pattern|
82
  Dir[file_pattern].each do |filename|
83
    open filename do |file|
84
      preloaded_files << filename if file.grep(/acts_as_(#{ ActiveRecord::ActsAs::Features.join('|') })/).any?
85
    end
86
  end
87
end
88
89
# # If there are overwritten engine files in the application, load them 
90
# # instead of the engine ones.
91
#
92
# If you only want to add functionality, you should use:
93
#   require_dependency "#{ RAILS_ROOT }/path/to/the/engine/file"
94
# on the top of the application file and then reopen the class
95
#
96
preloaded_files.select{ |f| f =~ /^#{ directory }/ }.each do |f|
97
  app_f = f.gsub(directory, RAILS_ROOT)
98
  if File.exists?(app_f)
99
    preloaded_files |= [ app_f ] 
100
    preloaded_files.delete(f)
101
  end
102
end
103
104
# # Move lazy files to the end
105
lazy_files.each do |lf|
106
  f = preloaded_files.find{ |pf| pf =~ /#{ lf }$/ }
107
  preloaded_files << preloaded_files.delete(f)
108
end
109
110
# # Finally, preload files
111
preloaded_files.each do |f|
112
  begin
113
    require_dependency(f)
114
  rescue Exception => e
115
    #FIXME: logger ?
116
    puts "Station autoload: Couldn't load file #{ f }: #{ e }"
117
  end
118
end
119
120
# ActionMailer default host
121
122
if Site.table_exists?
123
  ActionMailer::Base.default_url_options[:host] = Site.current.domain
124
end
125
126
127
# ExceptionNotifier Integration
128
begin
129
  def ExceptionNotifier.set_from_site(site)
130
    if site.respond_to?(:exception_notifications) && site.exception_notifications
131
      self.exception_recipients = Array(site.exception_notifications_email)
132
      self.sender_address = %("#{ site.name }" <#{ site.email }>)
133
    end
134
  end
135
136
  if Site.table_exists?
137
    ExceptionNotifier.set_from_site(Site.current)
138
  end
139
140
  ActionController::Base.send :include, ExceptionNotifiable
141
rescue NameError => e
142
  #TODO: print message when Site.current.exception_notifications is true but
143
  # exception_notification plugin is missing
144
end