public
Fork of markbates/mack
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/juretta/mack.git
Search Repo:
commit  49227d9242910362140937683d1a46d7c14c8293
tree    538ddd6fa3410703eddcaaab1b60851b6e4fecd1
parent  78e3dc3cdd25d0a64c150acdbf1788647868335f
mack / lib / initialization / initializer.rb
100644 101 lines (78 sloc) 3.763 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require 'rubygems'
require 'rack'
require 'digest'
require 'mack_ruby_core_extensions'
require 'application_configuration'
require 'cachetastic'
require 'fileutils'
require 'log4r'
require 'crypt/rijndael'
require 'singleton'
require 'uri'
 
# Set up Mack constants, if they haven't already been set up.
unless Object.const_defined?("MACK_ENV")
  (Object::MACK_ENV = (ENV["MACK_ENV"] ||= "development")).to_sym
end
(Object::MACK_ROOT = (ENV["MACK_ROOT"] ||= FileUtils.pwd)) unless Object.const_defined?("MACK_ROOT")
 
Object::MACK_PUBLIC = File.join(MACK_ROOT, "public") unless Object.const_defined?("MACK_PUBLIC")
Object::MACK_APP = File.join(MACK_ROOT, "app") unless Object.const_defined?("MACK_APP")
Object::MACK_LIB = File.join(MACK_ROOT, "lib") unless Object.const_defined?("MACK_LIB")
Object::MACK_CONFIG = File.join(MACK_ROOT, "config") unless Object.const_defined?("MACK_CONFIG")
Object::MACK_VIEWS = File.join(MACK_APP, "views") unless Object.const_defined?("MACK_VIEWS")
Object::MACK_LAYOUTS = File.join(MACK_VIEWS, "layouts") unless Object.const_defined?("MACK_LAYOUTS")
Object::MACK_PLUGINS = File.join(MACK_ROOT, "vendor", "plugins") unless Object.const_defined?("MACK_PLUGINS")
 
unless Object.const_defined?("MACK_INITIALIZED")
  puts "Starting application in #{MACK_ENV} mode."
  
  Object::MACK_INITIALIZED = true
  
  # Set up 'Rails' constants to allow for easier use of existing gems/plugins like application_configuration.
  # I would like to take these out eventually, but for right now, it's not doing too much harm.
  # Object::RAILS_ENV = MACK_ENV unless Object.const_defined?("RAILS_ENV")
  # Object::RAILS_ROOT = MACK_ROOT unless Object.const_defined?("RAILS_ROOT")
 
  require File.join(File.dirname(__FILE__), "configuration.rb")
 
  require File.join(File.dirname(__FILE__), "initializers", "logging.rb")
  
  require File.join(File.dirname(__FILE__), "initializers", "orm_support.rb")
 
  fl = File.join(File.dirname(__FILE__), "..")
 
  # Require all the necessary files to make Mack actually work!
  ["distributed", "errors", "core_extensions", "utils", "test_extensions", "routing", "rendering", "sea_level", "tasks", "initialization/server", "generators"].each do |dir|
    dir_globs = Dir.glob(File.join(fl, dir, "**/*.rb"))
    dir_globs.each do |d|
      require d
    end
  end
  
 
 
  # ------------------------------------------------------------------------
 
  # set up application stuff:
 
  # set up routes:
  require File.join(MACK_CONFIG, "routes")
  
  # set up initializers:
  Dir.glob(File.join(MACK_CONFIG, "initializers", "**/*.rb")) do |d|
    require d
  end
  Mack::Utils::GemManager.instance.do_requires
 
  # require 'plugins':
  require File.join(File.dirname(__FILE__), "initializers", "plugins.rb")
  
  # require 'app' files:
  Dir.glob(File.join(MACK_APP, "**/*.rb")).each do |d|
    require d
  end
  
  # require 'lib' files:
  Dir.glob(File.join(MACK_LIB, "**/*.rb")).each do |d|
    require d
  end
  
 
  # ------------------------------------------------------------------------
  
  # Include ApplicationHelper into all controllers:
  if Object.const_defined?("ApplicationHelper")
    ApplicationHelper.include_safely_into(Mack::Controller::Base, Mack::ViewBinder)
  end
  # Find other Helpers and include them into their respective controllers.
  Object.constants.collect {|c| c if c.match(/Controller$/)}.compact.each do |cont|
    if Object.const_defined?("#{cont}Helper")
      h = "#{cont}Helper".constantize
      h.include_safely_into(cont, Mack::ViewBinder)
    end
  end
  
  # Find view level Helpers and include them into the Mack::ViewBinder
  Mack::ViewHelpers.constants.each do |cont|
      h = "Mack::ViewHelpers::#{cont}".constantize
      h.include_safely_into(Mack::ViewBinder)
  end
end