mack 0.8.0.101 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CHANGELOG +29 -0
  2. data/bin/mackery-console +6 -5
  3. data/bin/mackery-server +23 -7
  4. data/lib/mack.rb +0 -3
  5. data/lib/mack/application.rb +161 -0
  6. data/lib/mack/assets/asset_helpers.rb +8 -0
  7. data/lib/mack/assets/assets_mgr.rb +0 -10
  8. data/lib/mack/boot/app.rb +46 -0
  9. data/lib/mack/boot/assets.rb +10 -0
  10. data/lib/mack/boot/configuration.rb +87 -0
  11. data/lib/mack/boot/console.rb +36 -0
  12. data/lib/mack/boot/core.rb +21 -0
  13. data/lib/mack/boot/environment.rb +22 -0
  14. data/lib/mack/boot/extensions.rb +13 -0
  15. data/lib/mack/boot/gem_tasks.rb +20 -0
  16. data/lib/mack/boot/gems.rb +18 -0
  17. data/lib/mack/boot/hello.rb +11 -0
  18. data/lib/mack/{initialization → boot}/helpers.rb +8 -3
  19. data/lib/mack/boot/initializers.rb +17 -0
  20. data/lib/mack/boot/lib.rb +19 -0
  21. data/lib/mack/{initialization → boot}/logging.rb +16 -9
  22. data/lib/mack/{initialization → boot}/logging/basic_layout.rb +0 -0
  23. data/lib/mack/{initialization → boot}/logging/color_layout.rb +1 -1
  24. data/lib/mack/{initialization → boot}/logging/filter.rb +0 -0
  25. data/lib/mack/boot/paths.rb +234 -0
  26. data/lib/mack/boot/plugins.rb +26 -0
  27. data/lib/mack/boot/portlets.rb +20 -0
  28. data/lib/mack/boot/routes.rb +15 -0
  29. data/lib/mack/boot/version.rb +7 -0
  30. data/lib/mack/controller/request.rb +5 -2
  31. data/lib/mack/controller/uploaded_file.rb +4 -0
  32. data/lib/mack/core_extensions/kernel.rb +26 -0
  33. data/lib/mack/core_extensions/object.rb +16 -0
  34. data/lib/mack/generators/mack_application_generator/manifest.yml +5 -3
  35. data/lib/mack/generators/mack_application_generator/templates/config/initializers/portlets.rb.template +9 -0
  36. data/lib/mack/generators/mack_application_generator/templates/public/stylesheets/scaffold.css.template +4 -0
  37. data/lib/mack/generators/portlet_generator/portlet_generator.rb +2 -0
  38. data/lib/mack/generators/portlet_generator/templates/README.template +3 -0
  39. data/lib/mack/generators/portlet_generator/templates/portlet_config/portlet.spec.template +28 -0
  40. data/lib/mack/portlets/manager.rb +27 -0
  41. data/lib/mack/portlets/portlet.rb +93 -0
  42. data/lib/mack/portlets/unpacker.rb +34 -0
  43. data/lib/mack/rendering/engine/erubis.rb +2 -2
  44. data/lib/mack/rendering/type/file_base.rb +8 -4
  45. data/lib/mack/rendering/type/public.rb +4 -2
  46. data/lib/mack/routing/resource_proxy.rb +30 -4
  47. data/lib/mack/routing/route_map.rb +28 -15
  48. data/lib/mack/routing/route_object.rb +57 -24
  49. data/lib/mack/routing/urls.rb +12 -2
  50. data/lib/mack/runner.rb +6 -154
  51. data/lib/mack/sessions/cookie_session_store.rb +2 -1
  52. data/lib/mack/tasks/mack_dump_tasks.rake +62 -18
  53. data/lib/mack/tasks/mack_tasks.rake +1 -15
  54. data/lib/mack/tasks/portlet_tasks.rake +33 -0
  55. data/lib/mack/tasks/rake_rules.rake +6 -0
  56. data/lib/mack/tasks/test_tasks.rake +4 -6
  57. data/lib/mack/testing/helpers.rb +12 -4
  58. data/lib/mack/utils/server.rb +7 -1
  59. data/lib/mack/utils/static.rb +19 -0
  60. data/lib/mack/version.rb +1 -1
  61. data/lib/mack/view_helpers/all_helpers.rb +0 -8
  62. data/lib/mack/view_helpers/date_time_helpers.rb +18 -12
  63. data/lib/mack/view_helpers/form_helpers.rb +9 -0
  64. data/lib/mack/view_helpers/html_helpers.rb +18 -7
  65. data/lib/mack/view_helpers/link_helpers.rb +2 -1
  66. data/lib/mack/view_helpers/object_helpers.rb +1 -1
  67. data/lib/mack_app.rb +26 -14
  68. data/lib/mack_core.rb +50 -39
  69. data/lib/mack_tasks.rb +46 -19
  70. metadata +37 -18
  71. data/lib/mack/initialization/application.rb +0 -53
  72. data/lib/mack/initialization/boot_loader.rb +0 -72
  73. data/lib/mack/initialization/configuration.rb +0 -101
  74. data/lib/mack/initialization/console.rb +0 -29
  75. data/lib/mack/initialization/environment.rb +0 -16
  76. data/lib/mack/initialization/plugins.rb +0 -16
  77. data/lib/mack/initialization/server/simple_server.rb +0 -19
  78. data/lib/mack/tasks/mack_server_tasks.rake +0 -24
  79. data/lib/mack/utils/paths.rb +0 -154
data/CHANGELOG CHANGED
@@ -1,5 +1,34 @@
1
+ * [#217] Fixed rake mack:dump:routes throws errors
2
+ * [#216] Added ability to turn off view caching in distributed app
3
+ * [#215] Asset path lookup flow update
4
+ * [#213] Fixed the params method should be case insensitive
5
+ * [#211] Added a pagination API to mack-data_mapper
6
+ * [#210] Added a pagination API to mack-orm
7
+ * [#209] inline form built by link_to should include authenticity token
8
+ * [#208] Added support for DataMapper repository context per request
9
+ * [#207] Fixed session cookie not being deleted properly
10
+ * [#206] Portlet now have access to its base_path
11
+ * [#205] Fixed testing of nested parameters and file uploads breaks
12
+ * [#204] Resource routes can now take options when being defined.
13
+ * [#203] Updated distributed: view_cache to include Mack::ViewHelpers instead of Mack::ViewHelpers::LinkHelpers
14
+ * [#200] INCOMPATIBILITY NOTICE: mack-notifier configatron namespaces have changed from *_settings to * (e.g. smtp_settings to smtp)
15
+ * [#198] Added Embedded parameters in 'host' for Routes
16
+ * [#196] Extlib 0.9.8 support
17
+ * [#195] DataMapper 0.9.6 support
18
+ * [#193] Portlet Support
19
+ * [#192] mack-localization now supports portlet
20
+ * [#191] Asset-Packager support for Portlet
21
+ * [#143] Nested resources in Routes
22
+ * [#134] Form elements are now 'errorfied'.
23
+ * [#131] Date/Time select boxes can now be easily re-arranged.
24
+ * [#78] Jabber support
25
+ * gem: configatron 2.1.5
26
+ * gem: extlib 0.9.8
27
+
1
28
  === 0.8.0.2
2
29
  * [#190] Fixed ViewTemplate methods can easily be overridden
30
+ * [#134] 'errorfy' form elements [this update include changes in mack-active_record, mack-data_mapper, and mack-notifier]
31
+ * [#131] Added ability to rearrange date/time select
3
32
 
4
33
  === 0.8.0
5
34
  * [#187] Fixed: When an exception is raised, the request doesn't get 'logged'
@@ -1,16 +1,17 @@
1
1
  #!/usr/local/bin/ruby
2
2
  # require File.join(File.dirname(__FILE__), "options_handler")
3
3
 
4
- require File.join(File.dirname(__FILE__), "env_handler")
4
+ require File.expand_path(File.join(File.dirname(__FILE__), "env_handler.rb"))
5
5
 
6
- require File.join(File.dirname(__FILE__), "gem_load_path")
6
+ require File.expand_path(File.join(File.dirname(__FILE__), "gem_load_path.rb"))
7
7
 
8
8
  libs = []
9
9
  libs << "-r irb/completion"
10
- mack_lib_path = File.join(FileUtils.pwd, 'vendor', 'framework', 'mack', 'lib', 'mack')
10
+ mack_lib_path = File.expand_path(File.join(FileUtils.pwd, 'vendor', 'framework', 'mack', 'lib', 'mack'))
11
+
11
12
  if File.exists?(mack_lib_path)
12
- libs << "-r #{File.join(mack_lib_path, 'initialization', 'console')}"
13
+ libs << "-r #{File.expand_path(File.join(mack_lib_path, 'boot', 'console'))}"
13
14
  else
14
- libs << "-r #{File.join(File.dirname(__FILE__), '..', 'lib', 'mack', 'initialization', 'console')}"
15
+ libs << "-r #{File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'mack', 'boot', 'console'))}"
15
16
  end
16
17
  system "irb #{libs.join(" ")} --simple-prompt"
@@ -1,20 +1,15 @@
1
1
  #!/usr/local/bin/ruby
2
2
  # require File.join(File.dirname(__FILE__), "options_handler")
3
3
 
4
- require File.join(File.dirname(__FILE__), "env_handler")
4
+ require File.expand_path(File.join(File.dirname(__FILE__), "env_handler.rb"))
5
5
 
6
- require File.join(File.dirname(__FILE__), "gem_load_path")
6
+ require File.expand_path(File.join(File.dirname(__FILE__), "gem_load_path.rb"))
7
7
 
8
8
  require 'rubygems'
9
9
 
10
10
  require 'fileutils'
11
11
  require 'thin'
12
12
 
13
- module Rack
14
- ADAPTERS[:mack] = 'config/configatron/default.rb' if ADAPTERS.is_a?(Hash)
15
- ADAPTERS << [:mack, 'config/configatron/default.rb'] if ADAPTERS.is_a?(Array)
16
- end
17
-
18
13
  require 'mack'
19
14
 
20
15
  handler = "thin"
@@ -41,5 +36,26 @@ else
41
36
  if ARGV.include?("-p")
42
37
  port = ARGV[ARGV.index("-p") + 1]
43
38
  end
39
+
40
+ module Mack
41
+ # Even though it's called, SimpleServer, this might be the only server you need to run
42
+ # a Mack application.
43
+ #
44
+ # This SimpleServer does not use Thin. But does work with anything that Rack has a handler for.
45
+ class SimpleServer
46
+
47
+ class << self
48
+
49
+ def run(options)
50
+ r = "Rack::Handler::#{options[:handler].camelcase}"
51
+ puts "Starting app using: #{r} in #{options[:environment]} mode on port: #{options[:port]}"
52
+ eval(r).run(Mack::Utils::Server.build_app, :Port => options[:port])
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ end
59
+
44
60
  Mack::SimpleServer.run(:handler => handler, :port => port, :environment => ENV["MACK_ENV"])
45
61
  end
@@ -1,6 +1,3 @@
1
- # require the core classes:
2
-
3
- # puts "Loading mack from: #{File.dirname(__FILE__)}"
4
1
  require File.join(File.dirname(__FILE__), 'mack_core')
5
2
 
6
3
  # load the environment:
@@ -0,0 +1,161 @@
1
+ require File.join(File.dirname(__FILE__), 'routing', 'urls')
2
+ module Mack
3
+ # This is the heart and soul of the Mack framework! This class interfaces with the Rack framework.
4
+ # It handles all the dispatching back and forth between the Rack framework and a Mack application.
5
+ class Application
6
+ include Extlib::Hook
7
+ include Mack::Routes::Urls
8
+
9
+ attr_reader :response # :nodoc:
10
+ attr_reader :request # :nodoc:
11
+ attr_reader :cookies # :nodoc:
12
+ attr_reader :runner_helpers # :nodoc:
13
+ attr_reader :original_controller
14
+ attr_reader :original_action
15
+
16
+ # This method needs to be defined as part of the Rack framework. As is noted for the Mack::Runner
17
+ # class, this is where the center of the Mack framework lies.
18
+ def call(env)
19
+ env["rack.errors"] = StringIO.new # Send Rack errors nowhere fast!
20
+ begin
21
+ setup(env)
22
+ begin
23
+ route = Mack::Routes.retrieve(self.request)
24
+ if route[:redirect_to]
25
+ # because the route is specified to be a redirect, let's do that:
26
+ redirect_to(route)
27
+ else
28
+ # set these in case we need them for handling errors:
29
+ @original_controller = route[:controller]
30
+ @original_action = route[:action]
31
+ run_controller(route)
32
+ end
33
+ # return teardown
34
+ rescue Exception => e
35
+ # There was an exception, let's see if there's a handler for this error in routes:
36
+ route = Mack::Routes.retrieve_from_error(e.class)
37
+ unless route.nil?
38
+ self.request.all_params[:original_controller] = @original_controller
39
+ self.request.all_params[:original_action] = @original_action
40
+ # There is a handler, let's try running that:
41
+ run_controller(route, e)
42
+ else
43
+ # If we can't find the resource, or there's no route, let's check the public directory:
44
+ case e
45
+ when Mack::Errors::ResourceNotFound, Mack::Errors::UndefinedRoute
46
+ return try_to_find_resource(env, e)
47
+ else
48
+ # Re-raise the exception
49
+ raise e
50
+ end
51
+ end
52
+ # return teardown
53
+ end
54
+ # Capture all the Exceptions for this call:
55
+ rescue Exception => e
56
+ Mack.logger.error e
57
+ case e
58
+ when Mack::Errors::ResourceNotFound, Mack::Errors::UndefinedRoute
59
+ handle_error(404, 'Page Not Found!', e)
60
+ # If it's any other type of exception render the 500.html page:
61
+ else
62
+ handle_error(500, 'Server Error!', e)
63
+ end
64
+ # return teardown
65
+ ensure
66
+ teardown
67
+ end
68
+ return self.response.finish
69
+ end
70
+
71
+ #private
72
+ def run_controller(route, e = nil)
73
+ runner_block = route[:runner_block]
74
+ route - :runner_block
75
+
76
+ self.request.params = self.request.all_params.merge(route)
77
+ self.response.content_type = Mack::Utils::MimeTypes[self.request.params[:format]]
78
+ catch(:finished) do
79
+ if runner_block
80
+ runner_block.call(self.request, self.response, self.cookies)
81
+ end
82
+
83
+ # let's handle a normal request:
84
+ begin
85
+ cont = "#{route[:controller].to_s.camelcase}Controller".constantize
86
+ rescue NameError => e
87
+ raise Mack::Errors::ResourceNotFound.new(self.request.path_info)
88
+ end
89
+
90
+ c = cont.new
91
+ c.configure_controller(self.request, self.response, self.cookies)
92
+ c.caught_exception = e unless e.nil?
93
+
94
+ self.response.controller = c
95
+ return self.response.write(c.run)
96
+ end
97
+ end
98
+
99
+ # Setup the request, response, cookies, session, etc...
100
+ # yield up, and then clean things up afterwards.
101
+ def setup(env)
102
+ @request = Mack::Request.new(env)
103
+ @response = Mack::Response.new
104
+ @cookies = Mack::CookieJar.new(self.request, self.response)
105
+ @runner_helpers = []
106
+ Mack::RunnerHelpers::Registry.registered_items.each do |helper|
107
+ help = helper.new
108
+ help.start(self.request, self.response, self.cookies)
109
+ @runner_helpers << help
110
+ end
111
+ end
112
+
113
+ def teardown
114
+ self.runner_helpers.reverse.each do |help|
115
+ help.complete(self.request, self.response, self.cookies)
116
+ end
117
+ # self.response.finish
118
+ end
119
+
120
+ def try_to_find_resource(env, exception)
121
+ # we can't find a route for this, so let's try and see if it's in the public directory:
122
+ path = env["PATH_INFO"].dup
123
+ path << ".html" if File.extname(path).blank?
124
+
125
+ Mack.search_path(:public).each do |p|
126
+ f = File.join(p, path)
127
+ if File.exists?(f)
128
+ return Rack::File.new(p).call(Rack::MockRequest.env_for(path))
129
+ end
130
+ end
131
+ raise exception
132
+ end
133
+
134
+ # This will redirect the request to the specified url. A default status of
135
+ # 302, Moved Temporarily, is set if no status is specified. A simple HTML
136
+ # page is rendered in case the redirect does not occur.
137
+ def redirect_to(route)
138
+ status = route[:status] || 302
139
+ url = route[:redirect_to]
140
+ options = self.request.all_params
141
+ options.merge!(route)
142
+ options - [:controller, :action, :redirect_to, :method, :status, :format]
143
+ url = url_for_pattern(url, options)
144
+ self.response.status = status
145
+ self.response[:location] = url
146
+ self.response.write(redirect_html(self.request.path_info, url, status))
147
+ end
148
+
149
+ private
150
+ def handle_error(status, body, e)
151
+ self.response.status = status
152
+ raise e if configatron.mack.show_exceptions
153
+ path = Mack::Paths.public("#{status}.html")
154
+ if File.exists?(path)
155
+ body = File.read(path)
156
+ end
157
+ self.response.write(body)
158
+ end
159
+
160
+ end
161
+ end
@@ -1,5 +1,13 @@
1
1
  module Mack
2
2
  module Assets
3
+
4
+ def get_resource_root(resource)
5
+ path = ""
6
+ path = Mack::Assets::Helpers.instance.asset_hosts(resource) if path.empty?
7
+ path = "#{configatron.mack.distributed.site_domain}" unless !path.empty? or configatron.mack.distributed.site_domain.nil?
8
+ return path
9
+ end
10
+
3
11
  class Helpers # :nodoc:
4
12
  include Singleton
5
13
 
@@ -153,13 +153,3 @@ module Mack
153
153
  end
154
154
  end
155
155
 
156
-
157
-
158
- module Kernel
159
- #
160
- # Return the instance of the AssetManager class.
161
- #
162
- def assets_mgr
163
- return Mack::Assets::Manager.instance
164
- end
165
- end
@@ -0,0 +1,46 @@
1
+ run_once do
2
+
3
+ require File.join_from_here('paths.rb')
4
+ require File.join_from_here('configuration.rb')
5
+ require File.join_from_here('logging.rb')
6
+ require File.join_from_here('extensions.rb')
7
+ require File.join_from_here('assets.rb')
8
+ require File.join_from_here('core.rb')
9
+ require File.join_from_here('gems.rb')
10
+ require File.join_from_here('plugins.rb')
11
+ require File.join_from_here('lib.rb')
12
+
13
+ init_message('application')
14
+
15
+ Mack.search_path(:app).each do |path|
16
+ # make sure that default_controller is available to other controllers
17
+ dcont = File.join(path, 'controllers', 'default_controller.rb')
18
+ require dcont if File.exists?(dcont)
19
+
20
+ Dir.glob(File.join(path, "**/*.rb")).each do |d|
21
+ begin
22
+ d = File.expand_path(d)
23
+ # puts d
24
+ require d
25
+ rescue NameError => e
26
+ if e.message.match("uninitialized constant")
27
+ mod = e.message.gsub("uninitialized constant ", "")
28
+ x =%{
29
+ module ::#{mod}
30
+ end
31
+ }
32
+ eval(x)
33
+ require d
34
+ else
35
+ raise e
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ # Add default assets
42
+ assets_mgr.defaults do |a|
43
+ a.add_css "scaffold" if File.exists?Mack::Paths.stylesheets("scaffold.css")
44
+ end
45
+
46
+ end
@@ -0,0 +1,10 @@
1
+ run_once do
2
+
3
+ # init_message('assets')
4
+
5
+ Dir.glob(File.join_from_here('..', 'assets', '**/*.rb')).each do |f|
6
+ f = File.expand_path(f)
7
+ require f
8
+ end
9
+
10
+ end
@@ -0,0 +1,87 @@
1
+ require 'configatron'
2
+
3
+ run_once do
4
+ require File.join_from_here('paths.rb')
5
+ require File.join_from_here('extensions.rb')
6
+
7
+ # init_message('configuration')
8
+
9
+ module Mack
10
+ module Configuration
11
+
12
+ configatron.mack.render_url_timeout = 5
13
+ configatron.mack.cache_classes = true
14
+ configatron.mack.reload_classes = 1
15
+ configatron.mack.deep_class_reload = false
16
+ configatron.mack.use_lint = true
17
+ configatron.mack.show_exceptions = true
18
+ configatron.mack.use_sessions = true
19
+ configatron.mack.session_id = '_mack_session_id'
20
+ configatron.mack.cookie_values = {:path => '/'}
21
+ configatron.mack.site_domain = 'http://localhost:3000'
22
+ configatron.mack.testing_framework = :rspec
23
+ configatron.mack.rspec_file_pattern = 'test/**/*_spec.rb'
24
+ configatron.mack.test_case_file_pattern = 'test/**/*_test.rb'
25
+ configatron.mack.session_store = :cookie
26
+ configatron.mack.disable_forgery_detector = false
27
+ configatron.mack.assets.max_distribution = 4
28
+ configatron.mack.assets.hosts = ''
29
+ configatron.mack.assets.stamp = Time.now.to_i
30
+ configatron.mack.cookie_session_store.expiry_time = 4.hours
31
+
32
+ configatron.mack.log.level = :info
33
+ configatron.mack.log.detailed_requests = true
34
+ configatron.mack.log.disable_initialization_logging = false
35
+ configatron.mack.log.root = Mack::Paths.log
36
+ configatron.mack.log.colors.db = :cyan
37
+ configatron.mack.log.colors.error = :red
38
+ configatron.mack.log.colors.fatal = :red
39
+ configatron.mack.log.colors.warn = :yellow
40
+ configatron.mack.log.colors.completed = :purple
41
+ configatron.mack.log.use_colors = true
42
+ configatron.mack.log.time_format = '%Y-%m-%d %H:%M:%S'
43
+
44
+ configatron.mack.static_paths = ["/css", "/images", "/files", "/images", "/stylesheets", "/javascripts", "/media", "/favicon.ico"]
45
+
46
+ configatron.mack.portlet.verbose = false
47
+ configatron.mack.portlet.need_tar = false
48
+ configatron.mack.portlet.need_zip = false
49
+
50
+ if Mack.env?(:production)
51
+ configatron.mack.use_lint = false
52
+ configatron.mack.show_exceptions = false
53
+ configatron.mack.log.level = :info
54
+ configatron.mack.log.detailed_requests = true
55
+ configatron.mack.log.use_colors = false
56
+ end
57
+
58
+ if Mack.env?(:development)
59
+ configatron.mack.cache_classes = false
60
+ configatron.mack.log.level = :debug
61
+ end
62
+
63
+ if Mack.env?(:test)
64
+ configatron.mack.cookie_values = {}
65
+ configatron.mack.session_store = :test
66
+ configatron.mack.disable_forgery_detector = true
67
+ configatron.mack.run_remote_tests = true
68
+ configatron.mack.log.level = :error
69
+ end
70
+
71
+ Mack.search_path(:configatron).each do |path|
72
+ [:default, Mack.env].each do |f|
73
+ fp = File.join(path, "#{f}.rb")
74
+ if File.exists?(fp)
75
+ require fp
76
+ end
77
+ end
78
+ end
79
+
80
+ def self.dump
81
+ configatron.inspect
82
+ end
83
+
84
+ end # Configuration
85
+ end # Mack
86
+
87
+ end # run_once