merb 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/README +25 -26
  2. data/Rakefile +48 -36
  3. data/app_generators/merb/USAGE +5 -0
  4. data/app_generators/merb/merb_generator.rb +107 -0
  5. data/app_generators/merb/templates/Rakefile +99 -0
  6. data/{examples/skeleton/dist → app_generators/merb/templates}/app/controllers/application.rb +1 -1
  7. data/app_generators/merb/templates/app/controllers/exceptions.rb +13 -0
  8. data/{examples/skeleton/dist → app_generators/merb/templates}/app/helpers/global_helper.rb +0 -0
  9. data/{examples/skeleton/dist/app/mailers → app_generators/merb/templates/app/mailers/views}/layout/application.erb +0 -0
  10. data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +207 -0
  11. data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +38 -0
  12. data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +40 -0
  13. data/app_generators/merb/templates/app/views/layout/application.html.erb +11 -0
  14. data/app_generators/merb/templates/config/boot.rb +11 -0
  15. data/app_generators/merb/templates/config/dependencies.rb +41 -0
  16. data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/development.rb +0 -0
  17. data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/production.rb +0 -0
  18. data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/test.rb +0 -0
  19. data/app_generators/merb/templates/config/merb.yml +64 -0
  20. data/app_generators/merb/templates/config/merb_init.rb +16 -0
  21. data/app_generators/merb/templates/config/plugins.yml +1 -0
  22. data/app_generators/merb/templates/config/router.rb +32 -0
  23. data/{lib/merb/core_ext/merb_array.rb → app_generators/merb/templates/config/upload.conf} +0 -0
  24. data/app_generators/merb/templates/public/images/merb.jpg +0 -0
  25. data/app_generators/merb/templates/public/merb.fcgi +6 -0
  26. data/app_generators/merb/templates/public/stylesheets/master.css +119 -0
  27. data/app_generators/merb/templates/script/destroy +28 -0
  28. data/app_generators/merb/templates/script/generate +28 -0
  29. data/{examples/skeleton → app_generators/merb/templates}/script/stop_merb +0 -0
  30. data/app_generators/merb/templates/script/win_script.cmd +1 -0
  31. data/app_generators/merb/templates/spec/spec.opts +6 -0
  32. data/app_generators/merb/templates/spec/spec_helper.rb +10 -0
  33. data/app_generators/merb/templates/test/test_helper.rb +13 -0
  34. data/app_generators/merb_plugin/USAGE +5 -0
  35. data/app_generators/merb_plugin/merb_plugin_generator.rb +64 -0
  36. data/app_generators/merb_plugin/templates/LICENSE +20 -0
  37. data/app_generators/merb_plugin/templates/README +4 -0
  38. data/app_generators/merb_plugin/templates/Rakefile +35 -0
  39. data/app_generators/merb_plugin/templates/TODO +5 -0
  40. data/app_generators/merb_plugin/templates/merbtasks.rb +6 -0
  41. data/app_generators/merb_plugin/templates/sampleplugin.rb +10 -0
  42. data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +7 -0
  43. data/app_generators/merb_plugin/templates/spec_helper.rb +2 -0
  44. data/bin/merb +1 -1
  45. data/lib/autotest/discover.rb +3 -0
  46. data/lib/autotest/merb_rspec.rb +79 -0
  47. data/lib/merb.rb +72 -93
  48. data/lib/merb/{merb_abstract_controller.rb → abstract_controller.rb} +28 -5
  49. data/lib/merb/caching/action_cache.rb +65 -29
  50. data/lib/merb/caching/fragment_cache.rb +9 -4
  51. data/lib/merb/caching/store/file_cache.rb +22 -14
  52. data/lib/merb/caching/store/memory_cache.rb +26 -8
  53. data/lib/merb/{merb_constants.rb → constants.rb} +9 -7
  54. data/lib/merb/controller.rb +178 -0
  55. data/lib/merb/core_ext.rb +13 -11
  56. data/lib/merb/core_ext/array.rb +0 -0
  57. data/lib/merb/core_ext/{merb_class.rb → class.rb} +0 -0
  58. data/lib/merb/core_ext/{merb_enumerable.rb → enumerable.rb} +0 -0
  59. data/lib/merb/core_ext/get_args.rb +52 -0
  60. data/lib/merb/core_ext/{merb_hash.rb → hash.rb} +40 -11
  61. data/lib/merb/core_ext/{merb_inflections.rb → inflections.rb} +0 -0
  62. data/lib/merb/core_ext/{merb_inflector.rb → inflector.rb} +1 -1
  63. data/lib/merb/core_ext/{merb_kernel.rb → kernel.rb} +56 -3
  64. data/lib/merb/core_ext/mash.rb +88 -0
  65. data/lib/merb/core_ext/{merb_module.rb → module.rb} +0 -0
  66. data/lib/merb/core_ext/{merb_numeric.rb → numeric.rb} +0 -0
  67. data/lib/merb/core_ext/{merb_object.rb → object.rb} +10 -47
  68. data/lib/merb/core_ext/string.rb +56 -0
  69. data/lib/merb/core_ext/{merb_symbol.rb → symbol.rb} +0 -0
  70. data/lib/merb/dispatcher.rb +109 -0
  71. data/lib/merb/{merb_drb_server.rb → drb_server.rb} +0 -0
  72. data/lib/merb/erubis_ext.rb +10 -0
  73. data/lib/merb/exceptions.rb +173 -0
  74. data/lib/merb/generators/merb_app/merb_app.rb +5 -25
  75. data/lib/merb/generators/merb_generator_helpers.rb +317 -0
  76. data/lib/merb/generators/merb_plugin.rb +19 -0
  77. data/lib/merb/logger.rb +65 -0
  78. data/lib/merb/{merb_mail_controller.rb → mail_controller.rb} +102 -49
  79. data/lib/merb/{merb_mailer.rb → mailer.rb} +31 -27
  80. data/lib/merb/mixins/{basic_authentication_mixin.rb → basic_authentication.rb} +3 -3
  81. data/lib/merb/mixins/{controller_mixin.rb → controller.rb} +131 -112
  82. data/lib/merb/mixins/{erubis_capture_mixin.rb → erubis_capture.rb} +12 -21
  83. data/lib/merb/mixins/{form_control_mixin.rb → form_control.rb} +6 -12
  84. data/lib/merb/mixins/render.rb +401 -0
  85. data/lib/merb/mixins/responder.rb +378 -0
  86. data/lib/merb/mixins/{view_context_mixin.rb → view_context.rb} +65 -10
  87. data/lib/merb/mixins/web_controller.rb +29 -0
  88. data/lib/merb/{merb_handler.rb → mongrel_handler.rb} +59 -38
  89. data/lib/merb/part_controller.rb +19 -0
  90. data/lib/merb/plugins.rb +16 -0
  91. data/lib/merb/rack_adapter.rb +37 -0
  92. data/lib/merb/request.rb +421 -0
  93. data/lib/merb/router.rb +576 -0
  94. data/lib/merb/{merb_server.rb → server.rb} +275 -71
  95. data/lib/merb/session.rb +10 -10
  96. data/lib/merb/session/cookie_store.rb +125 -0
  97. data/lib/merb/session/{merb_mem_cache_session.rb → mem_cache_session.rb} +22 -9
  98. data/lib/merb/session/{merb_memory_session.rb → memory_session.rb} +15 -11
  99. data/lib/merb/template.rb +35 -8
  100. data/lib/merb/template/erubis.rb +16 -10
  101. data/lib/merb/template/haml.rb +33 -20
  102. data/lib/merb/template/markaby.rb +16 -14
  103. data/lib/merb/template/xml_builder.rb +8 -4
  104. data/lib/merb/test/{merb_fake_request.rb → fake_request.rb} +11 -5
  105. data/lib/merb/test/helper.rb +31 -0
  106. data/lib/merb/test/hpricot.rb +136 -0
  107. data/lib/merb/test/{merb_multipart.rb → multipart.rb} +1 -1
  108. data/lib/merb/test/rspec.rb +93 -0
  109. data/lib/merb/{merb_upload_handler.rb → upload_handler.rb} +5 -6
  110. data/lib/merb/{merb_upload_progress.rb → upload_progress.rb} +1 -1
  111. data/lib/merb/{merb_view_context.rb → view_context.rb} +27 -42
  112. data/lib/{merb_tasks.rb → tasks.rb} +0 -0
  113. data/lib/tasks/merb.rake +21 -11
  114. data/merb_default_generators/model/USAGE +0 -0
  115. data/merb_default_generators/model/model_generator.rb +16 -0
  116. data/merb_default_generators/model/templates/new_model_template.erb +5 -0
  117. data/merb_default_generators/resource_controller/USAGE +0 -0
  118. data/merb_default_generators/resource_controller/resource_controller_generator.rb +26 -0
  119. data/merb_default_generators/resource_controller/templates/controller.rb +30 -0
  120. data/merb_default_generators/resource_controller/templates/edit.html.erb +1 -0
  121. data/merb_default_generators/resource_controller/templates/helper.rb +5 -0
  122. data/merb_default_generators/resource_controller/templates/index.html.erb +1 -0
  123. data/merb_default_generators/resource_controller/templates/new.html.erb +1 -0
  124. data/merb_default_generators/resource_controller/templates/show.html.erb +1 -0
  125. data/merb_generators/controller/USAGE +5 -0
  126. data/merb_generators/controller/controller_generator.rb +16 -0
  127. data/merb_generators/controller/templates/controller.rb +8 -0
  128. data/merb_generators/controller/templates/helper.rb +5 -0
  129. data/merb_generators/controller/templates/index.html.erb +3 -0
  130. data/merb_generators/resource/USAGE +0 -0
  131. data/merb_generators/resource/resource_generator.rb +60 -0
  132. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +67 -0
  133. data/rspec_generators/merb_controller_test/templates/controller_spec.rb +8 -0
  134. data/rspec_generators/merb_controller_test/templates/edit_spec.rb +12 -0
  135. data/rspec_generators/merb_controller_test/templates/helper_spec.rb +5 -0
  136. data/rspec_generators/merb_controller_test/templates/index_spec.rb +12 -0
  137. data/rspec_generators/merb_controller_test/templates/new_spec.rb +12 -0
  138. data/rspec_generators/merb_controller_test/templates/show_spec.rb +5 -0
  139. data/rspec_generators/merb_model_test/merb_model_test_generator.rb +26 -0
  140. data/rspec_generators/merb_model_test/templates/model_spec_template.erb +7 -0
  141. data/script/destroy +14 -0
  142. data/script/generate +14 -0
  143. data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +53 -0
  144. data/test_unit_generators/merb_controller_test/templates/functional_test.rb +17 -0
  145. data/test_unit_generators/merb_controller_test/templates/helper_test.rb +9 -0
  146. data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +29 -0
  147. data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +9 -0
  148. metadata +172 -94
  149. data/examples/README_EXAMPLES +0 -10
  150. data/examples/skeleton/Rakefile +0 -68
  151. data/examples/skeleton/dist/app/views/layout/application.herb +0 -12
  152. data/examples/skeleton/dist/conf/database.yml +0 -23
  153. data/examples/skeleton/dist/conf/merb.yml +0 -57
  154. data/examples/skeleton/dist/conf/merb_init.rb +0 -24
  155. data/examples/skeleton/dist/conf/router.rb +0 -22
  156. data/examples/skeleton/dist/conf/upload.conf +0 -5
  157. data/examples/skeleton/dist/schema/migrations/001_add_sessions_table.rb +0 -14
  158. data/examples/skeleton/script/new_migration +0 -21
  159. data/lib/merb/core_ext/merb_string.rb +0 -18
  160. data/lib/merb/merb_controller.rb +0 -206
  161. data/lib/merb/merb_dispatcher.rb +0 -87
  162. data/lib/merb/merb_exceptions.rb +0 -319
  163. data/lib/merb/merb_part_controller.rb +0 -42
  164. data/lib/merb/merb_plugins.rb +0 -293
  165. data/lib/merb/merb_request.rb +0 -165
  166. data/lib/merb/merb_router.rb +0 -309
  167. data/lib/merb/merb_yaml_store.rb +0 -31
  168. data/lib/merb/mixins/render_mixin.rb +0 -283
  169. data/lib/merb/mixins/responder_mixin.rb +0 -159
  170. data/lib/merb/session/merb_ar_session.rb +0 -131
  171. data/lib/merb/vendor/paginator/README.txt +0 -84
  172. data/lib/merb/vendor/paginator/paginator.rb +0 -124
  173. data/lib/tasks/db.rake +0 -55
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "<%= name %>" do
4
+ it "should do nothing" do
5
+ true.should == true
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
data/bin/merb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
- require 'merb/merb_server'
4
+ require 'merb/server'
5
5
 
6
6
  Merb::Server.run
@@ -0,0 +1,3 @@
1
+ Autotest.add_discovery do
2
+ "merb" if File.exist?('config/merb_init.rb')
3
+ end
@@ -0,0 +1,79 @@
1
+ # based on rails_rspec.rb from rspec_on_rails by Nick Sieger
2
+
3
+ ### rspec_on_rails (c) Copyright 2006 Nick Sieger <nicksieger@gmail.com>
4
+ ###
5
+ ### Permission is hereby granted, free of charge, to any person
6
+ ### obtaining a copy of this software and associated documentation files
7
+ ### (the "Software"), to deal in the Software without restriction,
8
+ ### including without limitation the rights to use, copy, modify, merge,
9
+ ### publish, distribute, sublicense, and/or sell copies of the Software,
10
+ ### and to permit persons to whom the Software is furnished to do so,
11
+ ### subject to the following conditions:
12
+ ###
13
+ ### The above copyright notice and this permission notice shall be
14
+ ### included in all copies or substantial portions of the Software.
15
+ ###
16
+ ### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ ### EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ ### MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ ### NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
+ ### BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
+ ### ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ ### CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ ### SOFTWARE.
24
+
25
+ require 'autotest/rspec'
26
+
27
+ class Autotest::MerbRspec < Autotest::Rspec
28
+
29
+ def initialize # :nodoc:
30
+ super
31
+ @exceptions = %r%^\./(?:coverage|gems|doc|log|public|schema|script|previous_failures.txt)%
32
+ @test_mappings = {
33
+ %r%^(test|spec)/fixtures/(.*).yml$% => proc { |_, m|
34
+ ["spec/models/#{m[2].singularize}_spec.rb"] + files_matching(%r%^spec\/views\/#{m[2]}/.*_spec\.rb$%)
35
+ },
36
+ %r%^spec/(models|controllers|views|helpers|lib)/.*rb$% => proc { |filename, _|
37
+ filename
38
+ },
39
+ %r%^app/models/(.*)\.rb$% => proc { |_, m|
40
+ ["spec/models/#{m[1]}_spec.rb"]
41
+ },
42
+ %r%^app/helpers/application_helper\.rb$% => proc {
43
+ files_matching %r%^spec/(views|helpers)/.*_spec\.rb$%
44
+ },
45
+ %r%^app/helpers/(.*)_helper\.rb$% => proc { |_, m|
46
+ if m[1] == "application" then
47
+ files_matching(%r%^spec/(views|helpers)/.*_spec\.rb$%)
48
+ else
49
+ ["spec/helpers/#{m[1]}_helper_spec.rb"] + files_matching(%r%^spec\/views\/#{m[1]}/.*_spec\.rb$%)
50
+ end
51
+ },
52
+ # Handles both the old .rhtml and new .html.erb extensions
53
+ # index.rhtml => index_rhtml_spec.rb
54
+ # index.html.erb => index_html_spec.rb
55
+ %r%^app/views/([^.]*)\.([^.]*)(\..*)?$% => proc { |_, m|
56
+ files_matching %r%^spec/views/#{m[1]}(_|\.)#{m[2]}_spec.rb$%
57
+ },
58
+ %r%^app/controllers/application\.rb$% => proc { |_, m|
59
+ files_matching %r%^spec/controllers/.*_spec\.rb$%
60
+ },
61
+ %r%^app/controllers/(.*)\.rb$% => proc { |_, m|
62
+ ["spec/controllers/#{m[1]}_spec.rb"]
63
+ },
64
+ %r%^config/router\.rb$% => proc { # FIX:
65
+ files_matching %r%^spec/(controllers|views|helpers)/.*_spec\.rb$%
66
+ },
67
+ %r%^config/database\.yml$% => proc { |_, m|
68
+ files_matching %r%^spec/models/.*_spec\.rb$%
69
+ },
70
+ %r%^(spec/(spec_helper|shared/.*)|config/(dependencies|merb_init|environment(s/test)?))\.rb$% => proc {
71
+ files_matching %r%^spec/(models|controllers|views|helpers)/.*_spec\.rb$%
72
+ },
73
+ %r%^lib/(.*)\.rb$% => proc { |_, m|
74
+ ["spec/lib/#{m[1]}_spec.rb"]
75
+ },
76
+ }
77
+ end
78
+
79
+ end
@@ -9,114 +9,93 @@ else
9
9
  require 'mongrel'
10
10
  end
11
11
  require 'fileutils'
12
- require 'erubis'
13
- require 'logger'
14
- require 'json'
12
+ require 'merb/erubis_ext'
13
+ require 'merb/logger'
14
+ begin
15
+ require 'json/ext'
16
+ rescue LoadError
17
+ puts "Using pure ruby JSON lib"
18
+ require 'json/pure'
19
+ end
15
20
 
21
+ require 'set'
22
+ autoload :MerbUploadHandler, 'merb/upload_handler'
23
+ autoload :MerbHandler, 'merb/mongrel_handler'
16
24
 
17
25
  module Merb
18
- VERSION='0.3.7' unless defined?VERSION
26
+ VERSION='0.4.0' unless defined?(::Merb::VERSION)
27
+ autoload :Authentication, 'merb/mixins/basic_authentication'
28
+ autoload :ControllerMixin, 'merb/mixins/controller'
29
+ autoload :ErubisCaptureMixin, 'merb/mixins/erubis_capture'
30
+ autoload :FormControls, 'merb/mixins/form_control'
31
+ autoload :RenderMixin, 'merb/mixins/render'
32
+ autoload :ResponderMixin, 'merb/mixins/responder'
33
+ autoload :ViewContextMixin, 'merb/mixins/view_context'
34
+ autoload :WebControllerMixin, 'merb/mixins/web_controller'
35
+ autoload :Caching, 'merb/caching'
36
+ autoload :AbstractController, 'merb/abstract_controller'
37
+ autoload :Const, 'merb/constants'
38
+ autoload :Controller, 'merb/controller'
39
+ autoload :Dispatcher, 'merb/dispatcher'
40
+ autoload :DrbServiceProvider, 'drb_server'
41
+ autoload :ControllerExceptions, 'merb/exceptions'
42
+ autoload :MailController, 'merb/mail_controller'
43
+ autoload :Mailer, 'merb/mailer'
44
+ autoload :PartController, 'merb/part_controller'
45
+ autoload :Request, 'merb/request'
46
+ autoload :Router, 'merb/router'
47
+ autoload :Server, 'merb/server'
48
+ autoload :UploadProgress, 'merb/upload_progress'
49
+ autoload :ViewContext, 'merb/view_context'
50
+ autoload :SessionMixin, 'merb/session'
51
+ autoload :Template, 'merb/template'
52
+ autoload :Plugins, 'merb/plugins'
53
+ autoload :Rack,'merb/rack_adapter'
54
+
55
+ # Set up Merb::Server.config[] as an accessor for @@merb_opts
19
56
  class Server
20
57
  class << self
21
- def config
22
- @@merb_opts ||= {}
23
- end
24
- def method_missing(meth, *args, &block)
25
- if meth.to_s[-1..-1] == '='
26
- key = meth.to_s[0..-2].to_sym
27
- config.send("[]=", key, *args)
28
- elsif args.empty?
29
- config[meth]
30
- else
31
- super
32
- end
33
- end
58
+ def config() @@merb_opts ||= {} end
34
59
  end
35
60
  end
36
- end
37
-
38
- module Erubis
39
- class MEruby < Erubis::Eruby
40
- include PercentLineEnhancer
41
- include StringBufferEnhancer
42
- end
61
+
62
+ # Set up default generator scope
63
+ GENERATOR_SCOPE = [:merb_default, :merb, :rspec]
43
64
  end
44
65
 
45
66
  def __DIR__; File.dirname(__FILE__); end
46
-
47
- require File.join(__DIR__, 'merb/core_ext')
48
-
49
- MERB_FRAMEWORK_ROOT = __DIR__
50
-
51
- MERB_ROOT = Merb::Server.merb_root || Dir.pwd
52
- DIST_ROOT = Merb::Server.dist_root || Dir.pwd+'/dist'
53
- MERB_ENV = Merb::Server.config[:environment].nil? ? 'development' : Merb::Server.config[:environment]
54
- MERB_VIEW_ROOT = MERB_ROOT / "dist/app/views"
55
-
56
- logpath = $TESTING ? "/tmp/merb_test.log" : "#{MERB_ROOT}/log/merb.#{Merb::Server.port}.log"
57
- MERB_LOGGER = Logger.new(logpath)
58
- # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
59
- MERB_LOGGER.level = case (Merb::Server.log_level.downcase rescue '')
60
- when 'debug'
61
- Logger::DEBUG
62
- when 'info'
63
- Logger::INFO
64
- when 'warn'
65
- Logger::WARN
66
- when 'error'
67
- Logger::ERROR
68
- when 'fatal'
69
- Logger::FATAL
70
- when 'unknown'
71
- Logger::UNKNOWN
72
- else
73
- Logger::INFO
74
- end
75
-
76
67
  lib = File.join(__DIR__, 'merb')
77
- Dir.entries(lib).sort.select{|f| f !~ /merb\/session\// }.each {|fn| require File.join(lib, fn) if fn =~ /\.rb$/}
78
-
79
- require File.join(__DIR__, 'merb/vendor/paginator/paginator')
80
-
81
- class Merb::Controller
82
- lib = File.join(__DIR__, 'merb')
83
- if Merb::Server.memory_session
84
- require lib + "/session/merb_memory_session"
85
- Merb::MemorySessionContainer.setup
86
- include ::Merb::SessionMixin
87
- puts "memory session mixed in"
88
- end
89
-
90
- if Merb::Server.sql_session
91
- puts "ActiveRecord session mixed in"
92
- begin
93
- require 'action_controller/flash'
94
- puts "Rails session compatibilty on."
95
- rescue LoadError
96
- puts "Rails session compatibilty disabled. If you need this then install the actionpack gem"
97
- end
98
- require lib + "/session/merb_ar_session"
99
- include ::Merb::SessionMixin
100
- end
68
+ require File.join(__DIR__, 'merb/core_ext')
101
69
 
102
- if Merb::Server.mem_cache_session
103
- require lib + "/session/merb_mem_cache_session"
104
- include ::Merb::SessionMixin
105
- puts "MemCache session mixed in"
106
- end
107
-
108
- if Merb::Server.basic_auth
109
- require lib + "/mixins/basic_authentication_mixin"
110
- include ::Merb::Authentication
111
- puts "Basic Authentication mixed in"
112
- end
70
+ unless Object.const_defined?('MERB_ENV')
71
+ MERB_ENV = Merb::Server.config[:environment].nil? ? ($TESTING ? 'test' : 'development') : Merb::Server.config[:environment]
113
72
  end
114
73
 
115
- if defined? ActiveRecord
116
- Thread.new{ loop{ sleep(60*60); ActiveRecord::Base.verify_active_connections! } }.priority = -10
117
- end
74
+ MERB_FRAMEWORK_ROOT = __DIR__
75
+ MERB_ROOT = Merb::Server.config[:merb_root] || Dir.pwd
76
+ MERB_VIEW_ROOT = MERB_ROOT / "app/views"
77
+ MERB_SKELETON_DIR = File.join(MERB_FRAMEWORK_ROOT, '../app_generators/merb/templates')
78
+ logpath = if $TESTING
79
+ "#{MERB_ROOT}/log/merb_test.log"
80
+ elsif !(Merb::Server.config[:daemonize] || Merb::Server.config[:cluster] )
81
+ STDOUT
82
+ else
83
+ "#{MERB_ROOT}/log/merb.#{Merb::Server.config[:port]}.log"
84
+ end
85
+ FileUtils.mkdir_p(File.dirname(logpath)) if logpath.is_a?(String)
86
+ MERB_LOGGER = Merb::Logger.new(logpath)
87
+ MERB_LOGGER.level = Merb::Logger.const_get(Merb::Server.config[:log_level].upcase) rescue Merb::Logger::INFO
88
+ MERB_PATHS = [
89
+ "/app/models/**/*.rb",
90
+ "/app/controllers/application.rb",
91
+ "/app/controllers/**/*.rb",
92
+ "/app/helpers/**/*.rb",
93
+ "/app/mailers/**/*.rb",
94
+ "/app/parts/**/*.rb",
95
+ "/config/router.rb"
96
+ ]
118
97
 
119
98
  if $TESTING
120
99
  test_files = File.join(lib, 'test', '*.rb')
121
100
  Dir[test_files].each { |file| require file }
122
- end
101
+ end
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__)+'/mixins/render_mixin'
2
-
3
1
  module Merb
4
2
 
5
3
  class AbstractController
@@ -7,13 +5,18 @@ module Merb
7
5
 
8
6
  class_inheritable_accessor :before_filters
9
7
  class_inheritable_accessor :after_filters
8
+ class_inheritable_accessor :action_argument_list
9
+ self.action_argument_list = Hash.new([])
10
+
11
+
10
12
 
11
13
  # Holds internal execution times. Prefaced with an underscore to not
12
14
  # conflict with user-defined controller instance variables.
13
- attr_accessor :_benchmarks
15
+ attr_accessor :_benchmarks, :thrown_content
14
16
 
15
17
  def initialize(*args)
16
18
  @_benchmarks = {}
19
+ @thrown_content = AbstractController.default_thrown_content
17
20
  end
18
21
 
19
22
  def dispatch(action=:to_s)
@@ -23,6 +26,7 @@ module Merb
23
26
  @_benchmarks[:before_filters_time] = Time.now - start if before_filters
24
27
  result
25
28
  end
29
+
26
30
  @_body = case caught
27
31
  when :filter_chain_completed
28
32
  call_action(action)
@@ -45,7 +49,12 @@ module Merb
45
49
  protected
46
50
 
47
51
  def call_action(action)
48
- send(action)
52
+ # [[:id], [:foo, 7]]
53
+ args = self.class.action_argument_list[action.to_sym].map do |arg, default|
54
+ raise BadRequest unless params[arg.to_sym] || default
55
+ params[arg.to_sym] || default
56
+ end
57
+ send(action, *args)
49
58
  end
50
59
 
51
60
  # calls a filter chain according to rules.
@@ -55,7 +64,7 @@ module Merb
55
64
  if rule.has_key?(:only)
56
65
  if rule[:only].include?(params[:action].intern)
57
66
  ok = true
58
- end
67
+ end
59
68
  elsif rule.has_key?(:exclude)
60
69
  if !rule[:exclude].include?(params[:action].intern)
61
70
  ok = true
@@ -188,6 +197,20 @@ module Merb
188
197
  end
189
198
  return opts
190
199
  end
200
+
201
+ def self.default_thrown_content
202
+ Hash.new{ |hash, key| hash[key] = "" }
203
+ end
204
+
205
+ # Set here to respond when rendering to cover the provides syntax of setting the content_type
206
+ def content_type_set?
207
+ false
208
+ end
209
+
210
+
211
+ def content_type
212
+ params[:format]
213
+ end
191
214
  end
192
215
 
193
216
  end
@@ -1,56 +1,92 @@
1
1
  module Merb
2
2
  module Caching
3
-
3
+
4
+
5
+ # Action caching provides the ability to cache the output of individual actions. This output will be stored using fragment caching
6
+ # (Merb::Caching::Fragment). The output is stored based on a multipart key, which is comprised of the following pieces, in this order:
7
+ # * controller
8
+ # * action
9
+ # * parameters (represented as a list of parameter name/value pairs, sorted by name)
10
+ #
11
+ #
12
+ # === Examples
13
+ #
14
+ # class UserController < Merb::Controller
15
+ # cache_action(:show, :index)
16
+ #
17
+ # def show
18
+ # ... do some work to show a user ...
19
+ # end
20
+ #
21
+ # def index
22
+ # ... get the list of users ...
23
+ # end
24
+ # end
25
+ #
26
+ # In this case, we would expect show to take an :id parameter, and index to take no parameters, so the fragment stored for this action
27
+ # will be represented thus:
28
+ # get :show, :id => 25 => [:user_controller, :show, :id, 25]
29
+ # get :index => [:user_controller, :index]
30
+ #
31
+ # Action caches are expired based on the action alone (TODO: We need to modify expire action to allow expiration for specific parameter values).
32
+ # expire_action(:show) => This will expire all cached show actions (i.e. All users, in this case)
33
+
4
34
  module Actions
5
35
 
6
36
  def self.included(base) # :nodoc:
7
- base.class_eval {
8
- def caching_enabled?
9
- @_caching_enabled ||= ::Merb::Server.cache_templates
10
- end
11
- }
37
+
12
38
  base.extend(ClassMethods)
13
39
  end
14
40
 
15
41
  module ClassMethods
16
42
 
17
- # Cache the given actions.
18
-
43
+ # Cache the specific actions. If those actions take parameters, then those parameters will be considered part of the key.
44
+ #
19
45
  def cache_action(*actions)
20
- return unless caching_enabled?
21
46
  before :_get_action_fragment, :only => actions
22
47
  after :_store_action_fragment, :only => actions
23
48
  end
24
49
 
25
50
  end
26
-
27
- private
28
-
51
+
52
+
53
+ # Expire all cached content for the specific action, or array of actions.
54
+ def expire_action(*actions)
55
+ return unless _caching_enabled?
56
+ for action in [actions].flatten
57
+ ::Merb::Caching::Fragment.expire_fragment(params_key(:action => action))
58
+ end
59
+ end
60
+
61
+
62
+ private
63
+
64
+ def _caching_enabled?
65
+ ::Merb::Server.config[:cache_templates]
66
+ end
67
+
29
68
  def _get_action_fragment
30
- fragment_name = "#{params[:action]}#{@request.query_string}"
31
- if fragment = ::Merb::Caching::Fragment.get(fragment_name)
69
+ return unless _caching_enabled?
70
+ if fragment = ::Merb::Caching::Fragment.get(params_key)
32
71
  throw :halt, fragment
33
72
  end
34
73
  end
35
-
36
- def _store_action_fragment
37
- fragment_name = "#{params[:action]}#{@request.query_string}"
38
- ::Merb::Caching::Fragment.put(fragment_name, @body)
39
- end
40
-
41
- def caching_enabled?
42
- @_caching_enabled ||= ::Merb::Server.cache_templates
74
+
75
+ def _store_action_fragment
76
+ return unless _caching_enabled?
77
+ ::Merb::Caching::Fragment.put(params_key, body)
43
78
  end
44
79
 
45
- def expire_action(*actions)
46
- return unless caching_enabled?
47
- for action in [actions].flatten
48
- expire_fragment(action)
49
- end
80
+
81
+ def params_key(overrides = {})
82
+ key = []
83
+ additional_parameters = params.clone.merge(overrides)
84
+ key << additional_parameters.delete(:controller).to_s.snake_case
85
+ key << additional_parameters.delete(:action).to_s.snake_case
86
+ key << additional_parameters.keys.sort{|a,b| a.to_s <=> b.to_s}.collect{|k| [k.to_s, additional_parameters[k].to_s]}.flatten
87
+ key.flatten
50
88
  end
51
89
 
52
90
  end
53
-
54
91
  end
55
-
56
92
  end