mack 0.5.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGELOG +34 -0
  2. data/README +1 -1
  3. data/bin/mack +7 -2
  4. data/lib/controller/controller.rb +371 -0
  5. data/lib/controller/cookie_jar.rb +2 -1
  6. data/lib/controller/filter.rb +3 -2
  7. data/lib/controller/request.rb +30 -26
  8. data/lib/controller/session.rb +5 -0
  9. data/lib/distributed/utils/rinda.rb +1 -1
  10. data/lib/errors/errors.rb +5 -3
  11. data/lib/generators/mack_application_generator/mack_application_generator.rb +4 -0
  12. data/lib/generators/mack_application_generator/manifest.yml +40 -7
  13. data/lib/generators/mack_application_generator/templates/Rakefile.template +5 -1
  14. data/lib/generators/mack_application_generator/templates/app/controllers/default_controller.rb.template +2 -1
  15. data/lib/generators/mack_application_generator/templates/app/helpers/controllers/default_controller_helper.rb.template +7 -0
  16. data/lib/generators/mack_application_generator/templates/app/helpers/views/application_helper.rb.template +7 -0
  17. data/lib/generators/mack_application_generator/templates/config/app_config/default.yml.template +2 -1
  18. data/lib/generators/mack_application_generator/templates/config/database.yml.template +11 -10
  19. data/lib/generators/mack_application_generator/templates/test/functional/default_controller_spec.rb.template +9 -0
  20. data/lib/generators/mack_application_generator/templates/test/functional/default_controller_test.rb.template +10 -0
  21. data/lib/generators/mack_application_generator/templates/test/spec.opts.template +2 -0
  22. data/lib/generators/mack_application_generator/templates/test/spec_helper.rb.template +8 -0
  23. data/lib/generators/mack_application_generator/templates/test/test_helper.rb.template +2 -1
  24. data/lib/initialization/application.rb +46 -0
  25. data/lib/initialization/configuration.rb +23 -38
  26. data/lib/initialization/console.rb +5 -2
  27. data/lib/initialization/helpers.rb +31 -0
  28. data/lib/initialization/logging.rb +69 -15
  29. data/lib/initialization/orm_support.rb +10 -4
  30. data/lib/initialization/plugins.rb +1 -1
  31. data/lib/mack.rb +18 -76
  32. data/lib/mack_tasks.rb +4 -1
  33. data/lib/rendering/engine/erubis.rb +1 -1
  34. data/lib/rendering/engine/registry.rb +5 -5
  35. data/lib/rendering/type/action.rb +3 -2
  36. data/lib/rendering/type/base.rb +1 -1
  37. data/lib/rendering/type/layout.rb +2 -2
  38. data/lib/rendering/type/partial.rb +1 -1
  39. data/lib/rendering/type/public.rb +1 -1
  40. data/lib/rendering/type/template.rb +1 -1
  41. data/lib/rendering/type/url.rb +4 -4
  42. data/lib/rendering/type/xml.rb +3 -2
  43. data/lib/rendering/view_template.rb +7 -7
  44. data/lib/routing/route_map.rb +27 -5
  45. data/lib/routing/urls.rb +1 -0
  46. data/lib/runner.rb +52 -17
  47. data/lib/tasks/cachetastic_tasks.rake +2 -2
  48. data/lib/tasks/mack_server_tasks.rake +2 -4
  49. data/lib/tasks/mack_update_tasks.rake +26 -0
  50. data/lib/tasks/rake_rules.rake +6 -2
  51. data/lib/tasks/test_tasks.rake +28 -10
  52. data/lib/testing/helpers.rb +187 -0
  53. data/lib/testing/response.rb +49 -0
  54. data/lib/testing/rspec.rb +20 -0
  55. data/lib/testing/test_assertions.rb +55 -0
  56. data/lib/{test_extensions → testing}/test_case.rb +9 -7
  57. data/lib/utils/crypt/keeper.rb +1 -1
  58. data/lib/utils/server.rb +2 -2
  59. data/lib/view_helpers/html_helpers.rb +4 -0
  60. metadata +26 -40
  61. data/lib/controller/base.rb +0 -345
  62. data/lib/generators/mack_application_generator/templates/app/helpers/application_helper.rb.template +0 -2
  63. data/lib/generators/mack_application_generator/templates/config/thin.ru.template +0 -1
  64. data/lib/generators/mack_application_generator/templates/config/thin.yml.template +0 -8
  65. data/lib/rendering/engine/haml.rb +0 -18
  66. data/lib/rendering/engine/markaby.rb +0 -28
  67. data/lib/test_extensions/test_assertions.rb +0 -55
  68. data/lib/test_extensions/test_helpers.rb +0 -192
@@ -9,7 +9,10 @@ fl = File.join(File.dirname(__FILE__), "..")
9
9
 
10
10
  require File.join(fl, "mack")
11
11
 
12
- require File.join(fl, "test_extensions", "test_helpers")
12
+ require File.join(fl, "testing", "helpers")
13
13
 
14
14
  # self.send(:include, Mack::TestHelpers)
15
- self.send(:include, Mack::Routes::Urls)
15
+ self.send(:include, Mack::Routes::Urls)
16
+
17
+ # Prevent AutoRunner from getting executed when user exits out of console
18
+ Test::Unit.run = true
@@ -0,0 +1,31 @@
1
+ # Include ApplicationHelper into all controllers:
2
+ Mack.logger.info "Initializing helpers..."
3
+ # adding application_helper module into all defined controllers
4
+ if Object.const_defined?("ApplicationHelper")
5
+ Mack.logger.warn("ApplicationHelper has been deprecated! Please use move it to Mack::ViewHelpers::ApplicationHelper instead.")
6
+ ApplicationHelper.include_safely_into(Mack::Rendering::ViewTemplate)
7
+ end
8
+
9
+ module Mack
10
+ module ControllerHelpers # :nodoc:
11
+ end
12
+
13
+ module ViewHelpers # :nodoc:
14
+ end
15
+ end
16
+
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}")
24
+ end
25
+ end
26
+
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
+ h.include_safely_into(Mack::Rendering::ViewTemplate)
31
+ end
@@ -1,24 +1,78 @@
1
1
  #--
2
2
  # Configure logging
3
3
  #++
4
- include Log4r
5
4
 
6
- log_dir_loc = File.join(Mack::Configuration.root, "log")
7
- FileUtils.mkdir_p(log_dir_loc)
5
+ module Mack
6
+
7
+ def self.logger
8
+ $mack_default_logger
9
+ end
10
+
11
+ def self.logger=(log)
12
+ $mack_default_logger = log
13
+ end
14
+
15
+ end
16
+
17
+ unless Mack.logger
18
+ log_directory = app_config.log_root || File.join(Mack.root, "log")
19
+ FileUtils.mkdir_p(log_directory)
8
20
 
9
- unless Object.const_defined?("MACK_DEFAULT_LOGGER")
10
- log = Log4r::Logger.new('')
11
- log.level = Module.instance_eval("Log4r::#{app_config.log.level.to_s.upcase}")
12
- # console:
13
- if app_config.log.console
14
- console_format = PatternFormatter.new(:pattern => app_config.log.console_format)
15
- log.add(Log4r::StdoutOutputter.new('console', :formatter => console_format))
21
+ Mack.logger = Log4r::Logger.new('')
22
+ Mack.logger.level = Module.instance_eval("Log4r::#{(app_config.log_level || :info).to_s.upcase}")
23
+
24
+ format = Log4r::PatternFormatter.new(:pattern => "%l:\t[%d]\t%M")
25
+
26
+ if Mack.env == "development"
27
+ # console:
28
+ Mack.logger.add(Log4r::StdoutOutputter.new('console', :formatter => format))
16
29
  end
30
+
17
31
  # file:
18
- if app_config.log.file
19
- file_format = PatternFormatter.new(:pattern => app_config.log.file_format)
20
- log.add(FileOutputter.new('fileOutputter', :filename => File.join(log_dir_loc, "#{Mack::Configuration.env}.log"), :trunc => false, :formatter => file_format))
32
+ Mack.logger.add(Log4r::FileOutputter.new('fileOutputter', :filename => File.join(log_directory, "#{Mack.env}.log"), :trunc => false, :formatter => format))
33
+ end
34
+
35
+ module Mack
36
+ module Logging # :nodoc:
37
+ # Used to house a list of filters for parameter logging. The initial list
38
+ # includes password and password_confirmation
39
+ class Filter
40
+ include Singleton
41
+
42
+ # The list of parameters you want filtered for logging.
43
+ attr_reader :list
44
+
45
+ def initialize
46
+ @list = [:password, :password_confirmation]
47
+ end
48
+
49
+ # Adds 'n' number of parameter names to the list
50
+ def add(*args)
51
+ @list << args
52
+ @list.flatten!
53
+ end
54
+
55
+ # Removes 'n' number of parameter names from the list
56
+ def remove(*args)
57
+ @list.delete_values(*args)
58
+ end
59
+
60
+ class << self
61
+
62
+ def remove(*args)
63
+ Mack::Logging::Filter.instance.remove(*args)
64
+ end
65
+
66
+ def add(*args)
67
+ Mack::Logging::Filter.instance.add(*args)
68
+ end
69
+
70
+ def list
71
+ Mack::Logging::Filter.instance.list
72
+ end
73
+
74
+ end
75
+
76
+ end
21
77
  end
22
-
23
- Object::MACK_DEFAULT_LOGGER = log
24
78
  end
@@ -1,4 +1,10 @@
1
- orm = app_config.orm || 'data_mapper'
2
-
3
- require "mack-#{orm}"
4
- require "mack-#{orm}_tasks"
1
+ # If the application explicitly says it doesn't want to use any orm,
2
+ # then we're not going to initialize any default orm.
3
+ # Note: this is initialization process only. By the default, application
4
+ # generated by mack still have data_mapper as default.
5
+ orm = app_config.orm
6
+ unless orm.nil?
7
+ Mack.logger.info "Initializing #{orm} orm..."
8
+ require "mack-#{orm}"
9
+ require "mack-#{orm}_tasks"
10
+ end
@@ -1,5 +1,5 @@
1
1
  plugins = [] # a list of all plugins
2
- Dir.glob(File.join(Mack::Configuration.plugins, "*")).each do |d|
2
+ Dir.glob(File.join(Mack.root, "vendor", "plugins", "*")).each do |d|
3
3
  plugins << d
4
4
  $: << File.join(d, "lib") # add the lib for this plugin to the global load path
5
5
  end
data/lib/mack.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rack'
3
3
  require 'digest'
4
- require 'mack_ruby_core_extensions'
4
+ require 'mack-facets'
5
5
  require 'application_configuration'
6
6
  require 'cachetastic'
7
7
  require 'fileutils'
@@ -15,101 +15,43 @@ require 'rinda/tuplespace'
15
15
  require 'builder'
16
16
  require 'erubis'
17
17
  require 'erb'
18
- require 'markaby'
19
- require 'haml'
20
18
  require 'genosaurus'
21
19
  require 'net/http'
20
+ require 'pp'
21
+ require 'test/unit'
22
22
 
23
23
  require File.join(File.dirname(__FILE__), "initialization", "configuration.rb")
24
24
 
25
25
  unless Mack::Configuration.initialized
26
26
 
27
- puts "Starting application in #{Mack::Configuration.env} mode."
28
- puts "Mack root: #{Mack::Configuration.root}"
29
-
27
+ puts "Initializing logging..."
30
28
  require File.join(File.dirname(__FILE__), "initialization", "logging.rb")
31
29
 
32
- require File.join(File.dirname(__FILE__), "initialization", "orm_support.rb")
33
-
34
30
  fl = File.join(File.dirname(__FILE__))
35
31
 
32
+ Mack.logger.info "Starting application in #{Mack.env} mode."
33
+ Mack.logger.info "Mack root: #{Mack.root}"
34
+
35
+ Mack.logger.info "Initializing core classes..."
36
36
  # Require all the necessary files to make Mack actually work!
37
- ["distributed", "errors", "core_extensions", "utils", "test_extensions", "routing", "view_helpers", "rendering", "controller", "tasks", "initialization/server", "generators"].each do |dir|
37
+ lib_dirs = ["distributed", "errors", "core_extensions", "utils", "routing", "view_helpers", "rendering", "controller", "tasks", "initialization/server", "generators"]
38
+ lib_dirs << "testing" if Mack.env == "test"
39
+ lib_dirs.each do |dir|
38
40
  dir_globs = Dir.glob(File.join(fl, dir, "**/*.rb"))
39
41
  dir_globs.each do |d|
40
42
  require d
41
43
  end
42
44
  end
43
45
 
44
-
45
-
46
- # ------------------------------------------------------------------------
47
-
48
- # set up application stuff:
49
-
50
- # set up routes:
51
- require File.join(Mack::Configuration.config_directory, "routes")
52
-
53
- # set up initializers:
54
- Dir.glob(File.join(Mack::Configuration.config_directory, "initializers", "**/*.rb")) do |d|
55
- require d
56
- end
57
- Mack::Utils::GemManager.instance.do_requires
58
-
59
- # require 'plugins':
60
- require File.join(File.dirname(__FILE__), "initialization", "plugins.rb")
61
-
62
- # make sure that default_controller is available to other controllers
63
- path = File.join(Mack::Configuration.app_directory, "controllers", "default_controller.rb")
64
- require path if File.exists?(path)
65
-
66
- # require 'app' files:
67
- Dir.glob(File.join(Mack::Configuration.app_directory, "**/*.rb")).each do |d|
68
- # puts "d: #{d}"
69
- begin
70
- require d
71
- rescue NameError => e
72
- if e.message.match("uninitialized constant")
73
- mod = e.message.gsub("uninitialized constant ", "")
74
- x =%{
75
- module ::#{mod}
76
- end
77
- }
78
- eval(x)
79
- require d
80
- else
81
- raise e
82
- end
83
- end
84
- end
85
-
86
- # require 'lib' files:
87
- Dir.glob(File.join(Mack::Configuration.lib_directory, "**/*.rb")).each do |d|
88
- require d
89
- end
46
+ require File.join(File.dirname(__FILE__), "runner")
90
47
 
48
+ require File.join(File.dirname(__FILE__), "initialization", "orm_support.rb")
91
49
 
92
- # ------------------------------------------------------------------------
93
-
94
- # Include ApplicationHelper into all controllers:
95
- if Object.const_defined?("ApplicationHelper")
96
- ApplicationHelper.include_safely_into(Mack::Controller::Base, Mack::Rendering::ViewTemplate)
97
- end
98
- # Find other Helpers and include them into their respective controllers.
99
- Object.constants.collect {|c| c if c.match(/Controller$/)}.compact.each do |cont|
100
- if Object.const_defined?("#{cont}Helper")
101
- h = "#{cont}Helper".constantize
102
- h.include_safely_into(cont, Mack::Rendering::ViewTemplate)
103
- end
104
- end
50
+ require File.join(File.dirname(__FILE__), "initialization", "application.rb")
105
51
 
106
- # Find view level Helpers and include them into the Mack::Rendering::ViewTemplate
107
- Mack::ViewHelpers.constants.each do |cont|
108
- h = "Mack::ViewHelpers::#{cont}".constantize
109
- h.include_safely_into(Mack::Rendering::ViewTemplate)
110
- end
52
+ require File.join(File.dirname(__FILE__), "initialization", "helpers.rb")
111
53
 
112
- Mack::Configuration.set(:initialized, "true") if Mack::Configuration.initialized.nil?
113
- end
54
+ Mack::Configuration.initialized = true if Mack::Configuration.initialized.nil?
114
55
 
115
- require File.join(File.dirname(__FILE__), "runner")
56
+ Mack.logger.info "Initialization finished."
57
+ end
data/lib/mack_tasks.rb CHANGED
@@ -5,7 +5,10 @@ require 'rubygems'
5
5
  require 'application_configuration'
6
6
 
7
7
  require File.join(File.dirname(__FILE__), "initialization", "configuration.rb")
8
- require File.join(File.dirname(__FILE__), "initialization", "orm_support.rb")
8
+ orm = app_config.orm
9
+ unless orm.nil?
10
+ require "mack-#{orm}_tasks"
11
+ end
9
12
 
10
13
  # Requires all rake tasks that ship with the Mack framework.
11
14
  [File.join(File.dirname(__FILE__)), File.join(FileUtils.pwd, "lib"), File.join(FileUtils.pwd, "vendor", "plugins")].each do |dir|
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'base')
1
+ require File.join(File.dirname(__FILE__), "base")
2
2
  module Mack
3
3
  module Rendering # :nodoc:
4
4
  module Engine # :nodoc:
@@ -14,11 +14,11 @@ module Mack
14
14
 
15
15
  def initialize
16
16
  @engines = {
17
- :action => [:erubis, :builder, :markaby, :haml],
18
- :template => [:erubis, :builder, :markaby, :haml],
19
- :partial => [:erubis, :builder, :markaby, :haml],
20
- :layout => [:erubis, :markaby, :haml],
21
- :xml => [:builder, :erubis, :markaby, :haml]
17
+ :action => [:erubis, :builder],
18
+ :template => [:erubis, :builder],
19
+ :partial => [:erubis, :builder],
20
+ :layout => [:erubis],
21
+ :xml => [:builder, :erubis]
22
22
  }
23
23
  end
24
24
 
@@ -5,10 +5,11 @@ module Mack
5
5
  # Used to render a template that's relative to a controller.
6
6
  #
7
7
  # Example:
8
- # class UsersController < Mack::Controller::Base
8
+ # class UsersController
9
+ # include Mack::Controller
9
10
  # # /users/:id
10
11
  # def show
11
- # @user = User.first(params(:id))
12
+ # @user = User.first(params[:id])
12
13
  # end
13
14
  # # /users
14
15
  # def index
@@ -49,7 +49,7 @@ module Mack
49
49
  # Returns the directory path for the current controller.
50
50
  def controller_view_path
51
51
  ivar_cache do
52
- File.join(Mack::Configuration.views_directory, self.controller.controller_name)
52
+ File.join(Mack.root, "app", "views", self.controller.controller_name)
53
53
  end
54
54
  end
55
55
 
@@ -12,11 +12,11 @@ module Mack
12
12
  # Example:
13
13
  # app/views/layouts/application.html.erb
14
14
  def render
15
- l_file = File.join(Mack::Configuration.views_directory, 'layouts', "#{self.options[:layout]}.#{self.options[:format]}")
15
+ l_file = File.join(Mack.root, "app", "views", 'layouts', "#{self.options[:layout]}.#{self.options[:format]}")
16
16
  begin
17
17
  render_file(l_file, :layout)
18
18
  rescue Mack::Errors::ResourceNotFound => e
19
- MACK_DEFAULT_LOGGER.warn(e)
19
+ Mack.logger.warn(e)
20
20
  self.view_template.yield_to :view
21
21
  end
22
22
  end
@@ -24,7 +24,7 @@ module Mack
24
24
  else
25
25
  # it's elsewhere
26
26
  parts[parts.size - 1] = "_" << parts.last
27
- partial = File.join(Mack::Configuration.views_directory, parts)
27
+ partial = File.join(Mack.root, "app", "views", parts)
28
28
  end
29
29
  partial = "#{partial}.#{self.options[:format]}"
30
30
  render_file(partial, :partial)
@@ -13,7 +13,7 @@ module Mack
13
13
  if File.extname(p_file).blank?
14
14
  p_file = "#{p_file}.#{self.options[:format]}"
15
15
  end
16
- find_file(Mack::Configuration.public_directory, p_file) do |f|
16
+ find_file(Mack.root, "public", p_file) do |f|
17
17
  return File.open(f).read
18
18
  end
19
19
  raise Mack::Errors::ResourceNotFound.new(p_file)
@@ -13,7 +13,7 @@ module Mack
13
13
  # Example:
14
14
  # <%= render(:template, "users/show") %> # => app/views/users/show.html.erb
15
15
  def render
16
- t_file = File.join(Mack::Configuration.views_directory, "#{self.render_value}.#{self.options[:format]}")
16
+ t_file = File.join(Mack.root, "app", "views", "#{self.render_value}.#{self.options[:format]}")
17
17
  render_file(t_file, :template)
18
18
  end
19
19
 
@@ -81,18 +81,18 @@ module Mack
81
81
  def do_render_local_url(url, options)
82
82
  Timeout::timeout(app_config.mack.render_url_timeout || 5) do
83
83
  cooks = {}
84
- self.cookies.all.each do |c,v|
84
+ self.view_template.cookies.all.each do |c,v|
85
85
  cooks[c] = v[:value]
86
86
  end
87
87
  request = self.view_template.request
88
- # MACK_DEFAULT_LOGGER.debug "ORIGINAL REQUEST: #{request.env.inspect}"
88
+ # Mack.logger.debug "ORIGINAL REQUEST: #{request.env.inspect}"
89
89
  env = request.env.dup
90
90
  env - ["rack.input", "rack.errors", "PATH_INFO", "REQUEST_PATH", "REQUEST_URI", "REQUEST_METHOD"]
91
91
  env["rack.request.query_hash"] = options[:parameters] || {}
92
92
  env["HTTP_COOKIE"] = "#{app_config.mack.session_id}=#{request.session.id};" if env["HTTP_COOKIE"].nil?
93
93
  options = env.merge(options)
94
- # MACK_DEFAULT_LOGGER.debug "NEW OPTIONS: #{options.inspect}"
95
- # MACK_DEFAULT_LOGGER.debug "url: #{url}"
94
+ # Mack.logger.debug "NEW OPTIONS: #{options.inspect}"
95
+ # Mack.logger.debug "url: #{url}"
96
96
  response = yield url, options
97
97
  if response.successful?
98
98
  return response.body
@@ -5,10 +5,11 @@ module Mack
5
5
  # Used to render an XML template that's relative to a controller.
6
6
  #
7
7
  # Example:
8
- # class UsersController < Mack::Controller::Base
8
+ # class UsersController
9
+ # include Mack::Controller
9
10
  # # /users/:id
10
11
  # def show
11
- # @user = User.first(params(:id))
12
+ # @user = User.first(params[:id])
12
13
  # end
13
14
  # # /users
14
15
  # def index
@@ -1,7 +1,7 @@
1
1
  module Mack
2
2
  module Rendering # :nodoc:
3
3
  # This class is used to do all the view level bindings.
4
- # It allows for seperation between the Mack::Controller::Base and the view levels.
4
+ # It allows for seperation between the Mack::Controller and the view levels.
5
5
  class ViewTemplate
6
6
 
7
7
  # Allows access to any options passed into the template.
@@ -16,12 +16,12 @@ module Mack
16
16
  @_yield_to_cache = {}
17
17
  end
18
18
 
19
- # Allows access to the current Mack::Controller::Base object.
19
+ # Allows access to the current Mack::Controller object.
20
20
  def controller
21
21
  self.options[:controller]
22
22
  end
23
23
 
24
- # Returns the Mack::Request associated with the current Mack::Controller::Base object.
24
+ # Returns the Mack::Request associated with the current Mack::Controller object.
25
25
  def request
26
26
  self.controller.request
27
27
  end
@@ -31,7 +31,7 @@ module Mack
31
31
  self.request.session
32
32
  end
33
33
 
34
- # Returns the Mack::CookieJar associated with the current Mack::Controller::Base object.
34
+ # Returns the Mack::CookieJar associated with the current Mack::Controller object.
35
35
  def cookies
36
36
  self.controller.cookies
37
37
  end
@@ -44,12 +44,12 @@ module Mack
44
44
  end
45
45
 
46
46
  # Maps to the controller's param method. See also Mack::Controller::Base params.
47
- def params(key)
48
- self.controller.params(key)
47
+ def params
48
+ self.controller.params
49
49
  end
50
50
 
51
51
  # Handles rendering calls both in the controller and in the view.
52
- # For full details of render examples see Mack::Controller::Base render.
52
+ # For full details of render examples see Mack::Controller render.
53
53
  # Although the examples there are all in controllers, they idea is still
54
54
  # the same for views.
55
55
  #