mack 0.7.0.1 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/CHANGELOG +34 -0
  2. data/README +6 -13
  3. data/bin/env_handler.rb +10 -0
  4. data/bin/gem_load_path.rb +25 -0
  5. data/bin/mack +1 -0
  6. data/bin/mackery +22 -0
  7. data/bin/mackery-console +16 -0
  8. data/bin/mackery-server +41 -0
  9. data/lib/mack.rb +7 -1
  10. data/lib/mack/controller/controller.rb +5 -4
  11. data/lib/mack/controller/request.rb +19 -1
  12. data/lib/mack/errors/errors.rb +8 -8
  13. data/lib/mack/generators/controller_generator/controller_generator.rb +1 -1
  14. data/lib/mack/generators/mack_application_generator/templates/app/views/layouts/application.html.erb.template +1 -2
  15. data/lib/mack/generators/mack_application_generator/templates/config/app_config/default.yml.template +2 -0
  16. data/lib/mack/generators/mack_application_generator/templates/config/database.yml.template +6 -6
  17. data/lib/mack/generators/passenger_generator/passenger_generator.rb +2 -0
  18. data/lib/mack/generators/passenger_generator/templates/config.ru.template +5 -0
  19. data/lib/mack/generators/passenger_generator/templates/tmp/README.template +2 -0
  20. data/lib/mack/initialization/application.rb +39 -36
  21. data/lib/mack/initialization/boot_loader.rb +174 -0
  22. data/lib/mack/initialization/configuration.rb +83 -95
  23. data/lib/mack/initialization/console.rb +11 -0
  24. data/lib/mack/initialization/environment.rb +16 -0
  25. data/lib/mack/initialization/helpers.rb +26 -24
  26. data/lib/mack/initialization/logging.rb +81 -81
  27. data/lib/mack/initialization/plugins.rb +14 -11
  28. data/lib/mack/initialization/server/simple_server.rb +3 -3
  29. data/lib/mack/rendering/type/base.rb +1 -1
  30. data/lib/mack/rendering/type/layout.rb +1 -1
  31. data/lib/mack/rendering/type/partial.rb +1 -1
  32. data/lib/mack/rendering/type/public.rb +1 -1
  33. data/lib/mack/rendering/type/template.rb +1 -1
  34. data/lib/mack/runner.rb +2 -2
  35. data/lib/mack/runner_helpers/session.rb +3 -3
  36. data/lib/mack/sessions/cookie_session_store.rb +44 -0
  37. data/lib/mack/{controller → sessions}/session.rb +0 -0
  38. data/lib/mack/sessions/session_store_base.rb +62 -0
  39. data/lib/mack/sessions/test_session_store.rb +38 -0
  40. data/lib/mack/tasks/mack_server_tasks.rake +8 -21
  41. data/lib/mack/tasks/mack_tasks.rake +33 -6
  42. data/lib/mack/tasks/rake_rules.rake +8 -0
  43. data/lib/mack/tasks/test_tasks.rake +39 -15
  44. data/lib/mack/testing/helpers.rb +6 -39
  45. data/lib/mack/utils/content_length_handler.rb +45 -0
  46. data/lib/mack/utils/forgery_detector.rb +152 -0
  47. data/lib/mack/utils/gem_manager.rb +22 -1
  48. data/lib/mack/utils/paths.rb +154 -0
  49. data/lib/mack/utils/server.rb +8 -6
  50. data/lib/mack/version.rb +1 -1
  51. data/lib/mack/view_helpers/asset_helpers.rb +50 -0
  52. data/lib/mack/view_helpers/form_helpers.rb +52 -6
  53. data/lib/mack/view_helpers/link_helpers.rb +6 -3
  54. data/lib/mack_app.rb +12 -14
  55. data/lib/mack_core.rb +35 -14
  56. data/lib/mack_tasks.rb +35 -20
  57. metadata +23 -27
  58. data/lib/mack/tasks/cachetastic_tasks.rake +0 -58
@@ -0,0 +1,174 @@
1
+ module Kernel
2
+
3
+ def boot_load(name, *dependencies, &block)
4
+ Mack::BootLoader.instance.add(name, *dependencies, &block)
5
+ end
6
+
7
+ end
8
+
9
+
10
+ module Mack
11
+ class BootLoader
12
+ include Singleton
13
+
14
+ attr_accessor :sequences
15
+
16
+ def initialize
17
+ self.sequences = {}
18
+ end
19
+
20
+ def add(name, *dependencies, &block)
21
+ self.sequences[name.to_sym] = Mack::BootLoader::Loader.new(name.to_sym, *dependencies, &block)
22
+ end
23
+
24
+ def self.run(*args)
25
+ args.each do |a|
26
+ begin
27
+ Mack::BootLoader.instance.sequences[a.to_sym].run
28
+ rescue Exception => e
29
+ puts "[#{a}]: #{e.message}"
30
+ puts e.backtrace
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.run!(*args)
36
+ args.each do |a|
37
+ Mack::BootLoader.instance.sequences[a.to_sym].run!
38
+ end
39
+ end
40
+
41
+ private
42
+ class Loader
43
+
44
+ attr_accessor :name
45
+ attr_accessor :dependencies
46
+ attr_accessor :sequence
47
+
48
+ def initialize(name, *dependencies, &block)
49
+ self.name = name.to_sym
50
+ self.dependencies = dependencies
51
+ self.sequence = block
52
+ @run = false
53
+ end
54
+
55
+ def run
56
+ return if @run
57
+ self.dependencies.each do |dep|
58
+ Mack::BootLoader.run(dep)
59
+ end
60
+ self.sequence.call
61
+ @run = true
62
+ end
63
+
64
+ def run!
65
+ self.dependencies.each do |dep|
66
+ Mack::BootLoader.run!(dep)
67
+ end
68
+ self.sequence.call
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+
75
+ # module Mack
76
+ # class BootLoader
77
+ # include Singleton
78
+ # include Extlib::Hook
79
+ #
80
+ # attr_accessor :steps
81
+ # attr_accessor :additional_procs
82
+ #
83
+ # def initialize
84
+ # self.steps = [:initializers, :gems, :plugins, :libs, :default_controller, :routes, :app, :additional]
85
+ # self.additional_procs = []
86
+ # end
87
+ #
88
+ # def start
89
+ # Mack.logger.debug "Starting boot loader sequence...."
90
+ # end
91
+ #
92
+ # def initializers
93
+ # # set up initializers:
94
+ # Mack.logger.debug "Initializing custom initializers..." unless app_config.log.disable_initialization_logging
95
+ # Dir.glob(Mack::Paths.initializers("**/*.rb")) do |d|
96
+ # require d
97
+ # end
98
+ # end
99
+ #
100
+ # def gems
101
+ # Mack.logger.debug "Initializing custom gems..." unless app_config.log.disable_initialization_logging
102
+ # Mack::Utils::GemManager.instance.do_requires
103
+ # end
104
+ #
105
+ # def plugins
106
+ # # require 'plugins':
107
+ # Mack.logger.debug "Initializing plugins..." unless app_config.log.disable_initialization_logging
108
+ # require File.join(File.dirname(__FILE__), "plugins.rb")
109
+ # end
110
+ #
111
+ # def libs
112
+ # # require 'lib' files:
113
+ # Mack.logger.debug "Initializing lib classes..." unless app_config.log.disable_initialization_logging
114
+ # Dir.glob(Mack::Paths.lib("**/*.rb")).each do |d|
115
+ # require d
116
+ # end
117
+ # end
118
+ #
119
+ # def default_controller
120
+ # # make sure that default_controller is available to other controllers
121
+ # path = Mack::Paths.controllers("default_controller.rb")
122
+ # require path if File.exists?(path)
123
+ # end
124
+ #
125
+ # def routes
126
+ # # set up routes:
127
+ # Mack.logger.debug "Initializing routes..." unless app_config.log.disable_initialization_logging
128
+ # require Mack::Paths.config("routes")
129
+ # end
130
+ #
131
+ # def app
132
+ # # require 'app' files:
133
+ # Mack.logger.debug "Initializing 'app' classes..." unless app_config.log.disable_initialization_logging
134
+ # Dir.glob(Mack::Paths.app("**/*.rb")).each do |d|
135
+ # # puts "d: #{d}"
136
+ # begin
137
+ # require d
138
+ # rescue NameError => e
139
+ # if e.message.match("uninitialized constant")
140
+ # mod = e.message.gsub("uninitialized constant ", "")
141
+ # x =%{
142
+ # module ::#{mod}
143
+ # end
144
+ # }
145
+ # eval(x)
146
+ # require d
147
+ # else
148
+ # raise e
149
+ # end
150
+ # end
151
+ # end
152
+ # end
153
+ #
154
+ # def additional
155
+ # self.additional_procs.each do |p|
156
+ # puts "p: #{p.inspect}"
157
+ # p.call
158
+ # end
159
+ # end
160
+ #
161
+ # def finish
162
+ # Mack.logger.debug "...Finished boot loader sequence."
163
+ # end
164
+ #
165
+ # def self.run
166
+ # Mack::BootLoader.instance.start
167
+ # Mack::BootLoader.instance.steps.each do |step|
168
+ # Mack::BootLoader.instance.send(step)
169
+ # end
170
+ # Mack::BootLoader.instance.finish
171
+ # end
172
+ #
173
+ # end
174
+ # end
@@ -1,110 +1,98 @@
1
- module Mack
1
+ require 'mack-facets'
2
+ require 'application_configuration'
3
+ require File.join(File.dirname(__FILE__), 'boot_loader')
4
+ require File.join(File.dirname(__FILE__), '..', 'utils', 'paths')
5
+ boot_load(:configuration) do
6
+ module Mack
2
7
 
3
- # Returns the root of the current Mack application
4
- def self.root
5
- ENV["MACK_ROOT"] ||= FileUtils.pwd
6
- end
8
+ # Returns the root of the current Mack application
9
+ def self.root
10
+ ENV["MACK_ROOT"] ||= FileUtils.pwd
11
+ end
7
12
 
8
- # Returns the environment of the current Mack application
9
- def self.env
10
- ENV["MACK_ENV"] ||= "development"
11
- end
13
+ # Returns the environment of the current Mack application
14
+ def self.env
15
+ ENV["MACK_ENV"] ||= "development"
16
+ end
12
17
 
13
- # All configuration for the Mack subsystem happens here. Each of the default environments,
14
- # production, development, and test have their own default configuration options. These
15
- # get merged with overall default options.
16
- module Configuration # :nodoc:
18
+ # All configuration for the Mack subsystem happens here. Each of the default environments,
19
+ # production, development, and test have their own default configuration options. These
20
+ # get merged with overall default options.
21
+ module Configuration # :nodoc:
17
22
 
18
- class << self
19
- attr_accessor :initialized_core
20
- attr_accessor :initialized_application
21
- end
23
+ class << self
24
+ attr_accessor :initialized_core
25
+ attr_accessor :initialized_application
26
+ end
22
27
 
23
- # use local memory and store stuff for 24 hours:
24
- # use file for sessions and store them for 4 hours:
25
- DEFAULTS_PRODUCTION = {
26
- "mack::use_lint" => false,
27
- "mack::show_exceptions" => false,
28
- "log_level" => "info",
29
- "log::detailed_requests" => false,
30
- "cachetastic_caches_mack_session_cache_options" => {
31
- "debug" => false,
32
- "adapter" => "file",
33
- "store_options" =>
34
- {"dir" => File.join(Mack.root, "tmp")},
35
- "expiry_time" => 14400,
36
- "logging" => {
37
- "logger_1" => {
38
- "type" => "file",
39
- "file" => File.join(Mack.root, "log", "cachetastic_caches_mack_session_cache.log")
40
- }
41
- }
42
- }
43
- } unless self.const_defined?("DEFAULTS_PRODUCTION")
28
+ # use local memory and store stuff for 24 hours:
29
+ # use file for sessions and store them for 4 hours:
30
+ DEFAULTS_PRODUCTION = {
31
+ "mack::use_lint" => false,
32
+ "mack::show_exceptions" => false,
33
+ "log_level" => "info",
34
+ "log::detailed_requests" => false
35
+ } unless self.const_defined?("DEFAULTS_PRODUCTION")
44
36
 
45
- # use local memory and store stuff for 5 minutes:
46
- DEFAULTS_DEVELOPMENT = {
47
- "mack::cache_classes" => false,
48
- "log_level" => "debug"
49
- } unless self.const_defined?("DEFAULTS_DEVELOPMENT")
37
+ # use local memory and store stuff for 5 minutes:
38
+ DEFAULTS_DEVELOPMENT = {
39
+ "mack::cache_classes" => false,
40
+ "log_level" => "debug"
41
+ } unless self.const_defined?("DEFAULTS_DEVELOPMENT")
50
42
 
51
- # use local memory and store stuff for 1 hour:
52
- DEFAULTS_TEST = {
53
- "log_level" => "error",
54
- "run_remote_tests" => true,
55
- "mack::cookie_values" => {}
56
- } unless self.const_defined?("DEFAULTS_TEST")
43
+ # use local memory and store stuff for 1 hour:
44
+ DEFAULTS_TEST = {
45
+ "log_level" => "error",
46
+ "run_remote_tests" => true,
47
+ "mack::cookie_values" => {},
48
+ "mack::session_store" => "test",
49
+ "mack::disable_forgery_detector" => true
50
+ } unless self.const_defined?("DEFAULTS_TEST")
57
51
 
58
- unless self.const_defined?("DEFAULTS")
59
- DEFAULTS = {
60
- "mack::render_url_timeout" => 5,
61
- "mack::cache_classes" => true,
62
- "mack::use_lint" => true,
63
- "mack::show_exceptions" => true,
64
- "mack::use_sessions" => true,
65
- "mack::session_id" => "_mack_session_id",
66
- "mack::cookie_values" => {
67
- "path" => "/"
68
- },
69
- "cachetastic_default_options" => {
70
- "debug" => false,
71
- "adapter" => "local_memory",
72
- "expiry_time" => 300,
73
- "logging" => {
74
- "logger_1" => {
75
- "type" => "file",
76
- "file" => File.join(Mack.root, "log", "cachetastic.log")
77
- }
78
- }
79
- },
80
- "mack::site_domain" => "http://localhost:3000",
81
- "mack::testing_framework" => "rspec",
82
- "log::detailed_requests" => true,
83
- "log::db_color" => "cyan",
84
- "log::error_color" => "red",
85
- "log::fatal_color" => "red",
86
- "log::warn_color" => "yellow",
87
- "log::completed_color" => "purple",
88
- "log_level" => "info"
89
- }#.merge(eval("DEFAULTS_#{Mack.env.upcase}"))
90
- end
52
+ unless self.const_defined?("DEFAULTS")
53
+ DEFAULTS = {
54
+ "mack::render_url_timeout" => 5,
55
+ "mack::cache_classes" => true,
56
+ "mack::use_lint" => true,
57
+ "mack::show_exceptions" => true,
58
+ "mack::use_sessions" => true,
59
+ "mack::session_id" => "_mack_session_id",
60
+ "mack::cookie_values" => {
61
+ "path" => "/"
62
+ },
63
+ "mack::site_domain" => "http://localhost:3000",
64
+ "mack::testing_framework" => "rspec",
65
+ "mack::rspec_file_pattern" => "test/**/*_spec.rb",
66
+ "mack::test_case_file_pattern" => "test/**/*_test.rb",
67
+ "log::detailed_requests" => true,
68
+ "log::db_color" => "cyan",
69
+ "log::error_color" => "red",
70
+ "log::fatal_color" => "red",
71
+ "log::warn_color" => "yellow",
72
+ "log::completed_color" => "purple",
73
+ "log_level" => "info",
74
+ "mack::session_store" => "cookie",
75
+ "cookie_session_store::expiry_time" => 4.hours
76
+ }#.merge(eval("DEFAULTS_#{Mack.env.upcase}"))
77
+ end
91
78
 
92
- app_config.load_hash(DEFAULTS, "mack_defaults")
93
- app_config.load_hash(eval("DEFAULTS_#{Mack.env.upcase}"), "mack_defaults_#{Mack.env}")
94
- app_config.load_file(File.join(Mack.root, "config", "app_config", "default.yml"))
95
- app_config.load_file(File.join(Mack.root, "config", "app_config", "#{Mack.env}.yml"))
96
- # app_config.reload
79
+ app_config.load_hash(DEFAULTS, "mack_defaults")
80
+ app_config.load_hash(eval("DEFAULTS_#{Mack.env.upcase}"), "mack_defaults_#{Mack.env}")
81
+ app_config.load_file(Mack::Paths.app_config("default.yml"))
82
+ app_config.load_file(Mack::Paths.app_config("#{Mack.env}.yml"))
83
+ # app_config.reload
97
84
 
98
- def self.dump
99
- fcs = app_config.instance.instance_variable_get("@final_configuration_settings")
100
- conf = {}
101
- fcs.each_pair do |k, v|
102
- unless v.is_a?(Application::Configuration::Namespace)
103
- conf[k.to_s] = v unless k.to_s.match("__")
85
+ def self.dump
86
+ fcs = app_config.instance.instance_variable_get("@final_configuration_settings")
87
+ conf = {}
88
+ fcs.each_pair do |k, v|
89
+ unless v.is_a?(Application::Configuration::Namespace)
90
+ conf[k.to_s] = v unless k.to_s.match("__")
91
+ end
104
92
  end
93
+ conf
105
94
  end
106
- conf
107
- end
108
95
 
96
+ end
109
97
  end
110
98
  end
@@ -7,6 +7,8 @@
7
7
 
8
8
  fl = File.join(File.dirname(__FILE__), "..")
9
9
 
10
+ require File.join(fl, "..", "..", "bin", "gem_load_path")
11
+
10
12
  require File.join(fl, "..", "mack")
11
13
 
12
14
  require File.join(fl, "testing", "helpers")
@@ -14,5 +16,14 @@ require File.join(fl, "testing", "helpers")
14
16
  # self.send(:include, Mack::TestHelpers)
15
17
  self.send(:include, Mack::Routes::Urls)
16
18
 
19
+ # When using the Mack console if you edit any files
20
+ # you can reload them in the console using this method
21
+ # without having to exit the console and start again.
22
+ def reload!
23
+ ivar_cache("_rack_reloader") do
24
+ Rack::Reloader.new(nil, 1)
25
+ end.reload!
26
+ end
27
+
17
28
  # Prevent AutoRunner from getting executed when user exits out of console
18
29
  Test::Unit.run = true
@@ -0,0 +1,16 @@
1
+ module Mack
2
+ # Allows hook methods for the loading of the environment.
3
+ module Environment
4
+ include Extlib::Hook
5
+
6
+ # Requires the Mack application classes only once.
7
+ # This is the method you want to add 'hooks' on for
8
+ # application load setup.
9
+ def self.load
10
+ ivar_cache do
11
+ require File.join(File.dirname(__FILE__), "..", "..", "mack_app")
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -1,31 +1,33 @@
1
- # Include ApplicationHelper into all controllers:
2
- Mack.logger.debug "Initializing helpers..." unless app_config.log.disable_initialization_logging
3
- # adding application_helper module into all defined controllers
4
- if Object.const_defined?("ApplicationHelper")
5
- deprecate_method("ApplicationHelper", "Mack::ViewHelpers::ApplicationHelper", "0.7.0")
6
- ApplicationHelper.include_safely_into(Mack::Rendering::ViewTemplate)
7
- end
8
-
9
- module Mack
10
- module ControllerHelpers # :nodoc:
1
+ boot_load(:helpers, :logging) do
2
+ # Include ApplicationHelper into all controllers:
3
+ Mack.logger.debug "Initializing helpers..." unless app_config.log.disable_initialization_logging
4
+ # adding application_helper module into all defined controllers
5
+ if Object.const_defined?("ApplicationHelper")
6
+ deprecate_method("ApplicationHelper", "Mack::ViewHelpers::ApplicationHelper", "0.7.0")
7
+ ApplicationHelper.include_safely_into(Mack::Rendering::ViewTemplate)
11
8
  end
9
+
10
+ module Mack
11
+ module ControllerHelpers # :nodoc:
12
+ end
12
13
 
13
- module ViewHelpers # :nodoc:
14
+ module ViewHelpers # :nodoc:
15
+ end
14
16
  end
15
- end
16
17
 
17
- # Find controller level Helpers and include them into their respective controllers
18
- Mack::ControllerHelpers.constants.each do |cont|
19
- h = "Mack::ControllerHelpers::#{cont}"
20
- if Object.const_defined?(cont)
21
- h.constantize.include_safely_into(cont.constantize)
22
- else
23
- Mack.logger.warn("Could not find: #{cont} controller for helper: #{h}")
18
+ # Find controller level Helpers and include them into their respective controllers
19
+ Mack::ControllerHelpers.constants.each do |cont|
20
+ h = "Mack::ControllerHelpers::#{cont}"
21
+ if Object.const_defined?(cont)
22
+ h.constantize.include_safely_into(cont.constantize)
23
+ else
24
+ Mack.logger.warn("Could not find: #{cont} controller for helper: #{h}")
25
+ end
24
26
  end
25
- end
26
27
 
27
- # Find view level Helpers and include them into the Mack::Rendering::ViewTemplate
28
- Mack::ViewHelpers.constants.each do |cont|
29
- h = "Mack::ViewHelpers::#{cont}".constantize
30
- Mack::Rendering::ViewTemplate.send(:include, h)
28
+ # Find view level Helpers and include them into the Mack::Rendering::ViewTemplate
29
+ Mack::ViewHelpers.constants.each do |cont|
30
+ h = "Mack::ViewHelpers::#{cont}".constantize
31
+ Mack::Rendering::ViewTemplate.send(:include, h)
32
+ end
31
33
  end