merb 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +25 -26
- data/Rakefile +48 -36
- data/app_generators/merb/USAGE +5 -0
- data/app_generators/merb/merb_generator.rb +107 -0
- data/app_generators/merb/templates/Rakefile +99 -0
- data/{examples/skeleton/dist → app_generators/merb/templates}/app/controllers/application.rb +1 -1
- data/app_generators/merb/templates/app/controllers/exceptions.rb +13 -0
- data/{examples/skeleton/dist → app_generators/merb/templates}/app/helpers/global_helper.rb +0 -0
- data/{examples/skeleton/dist/app/mailers → app_generators/merb/templates/app/mailers/views}/layout/application.erb +0 -0
- data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +207 -0
- data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +38 -0
- data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +40 -0
- data/app_generators/merb/templates/app/views/layout/application.html.erb +11 -0
- data/app_generators/merb/templates/config/boot.rb +11 -0
- data/app_generators/merb/templates/config/dependencies.rb +41 -0
- data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/development.rb +0 -0
- data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/production.rb +0 -0
- data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/test.rb +0 -0
- data/app_generators/merb/templates/config/merb.yml +64 -0
- data/app_generators/merb/templates/config/merb_init.rb +16 -0
- data/app_generators/merb/templates/config/plugins.yml +1 -0
- data/app_generators/merb/templates/config/router.rb +32 -0
- data/{lib/merb/core_ext/merb_array.rb → app_generators/merb/templates/config/upload.conf} +0 -0
- data/app_generators/merb/templates/public/images/merb.jpg +0 -0
- data/app_generators/merb/templates/public/merb.fcgi +6 -0
- data/app_generators/merb/templates/public/stylesheets/master.css +119 -0
- data/app_generators/merb/templates/script/destroy +28 -0
- data/app_generators/merb/templates/script/generate +28 -0
- data/{examples/skeleton → app_generators/merb/templates}/script/stop_merb +0 -0
- data/app_generators/merb/templates/script/win_script.cmd +1 -0
- data/app_generators/merb/templates/spec/spec.opts +6 -0
- data/app_generators/merb/templates/spec/spec_helper.rb +10 -0
- data/app_generators/merb/templates/test/test_helper.rb +13 -0
- data/app_generators/merb_plugin/USAGE +5 -0
- data/app_generators/merb_plugin/merb_plugin_generator.rb +64 -0
- data/app_generators/merb_plugin/templates/LICENSE +20 -0
- data/app_generators/merb_plugin/templates/README +4 -0
- data/app_generators/merb_plugin/templates/Rakefile +35 -0
- data/app_generators/merb_plugin/templates/TODO +5 -0
- data/app_generators/merb_plugin/templates/merbtasks.rb +6 -0
- data/app_generators/merb_plugin/templates/sampleplugin.rb +10 -0
- data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +7 -0
- data/app_generators/merb_plugin/templates/spec_helper.rb +2 -0
- data/bin/merb +1 -1
- data/lib/autotest/discover.rb +3 -0
- data/lib/autotest/merb_rspec.rb +79 -0
- data/lib/merb.rb +72 -93
- data/lib/merb/{merb_abstract_controller.rb → abstract_controller.rb} +28 -5
- data/lib/merb/caching/action_cache.rb +65 -29
- data/lib/merb/caching/fragment_cache.rb +9 -4
- data/lib/merb/caching/store/file_cache.rb +22 -14
- data/lib/merb/caching/store/memory_cache.rb +26 -8
- data/lib/merb/{merb_constants.rb → constants.rb} +9 -7
- data/lib/merb/controller.rb +178 -0
- data/lib/merb/core_ext.rb +13 -11
- data/lib/merb/core_ext/array.rb +0 -0
- data/lib/merb/core_ext/{merb_class.rb → class.rb} +0 -0
- data/lib/merb/core_ext/{merb_enumerable.rb → enumerable.rb} +0 -0
- data/lib/merb/core_ext/get_args.rb +52 -0
- data/lib/merb/core_ext/{merb_hash.rb → hash.rb} +40 -11
- data/lib/merb/core_ext/{merb_inflections.rb → inflections.rb} +0 -0
- data/lib/merb/core_ext/{merb_inflector.rb → inflector.rb} +1 -1
- data/lib/merb/core_ext/{merb_kernel.rb → kernel.rb} +56 -3
- data/lib/merb/core_ext/mash.rb +88 -0
- data/lib/merb/core_ext/{merb_module.rb → module.rb} +0 -0
- data/lib/merb/core_ext/{merb_numeric.rb → numeric.rb} +0 -0
- data/lib/merb/core_ext/{merb_object.rb → object.rb} +10 -47
- data/lib/merb/core_ext/string.rb +56 -0
- data/lib/merb/core_ext/{merb_symbol.rb → symbol.rb} +0 -0
- data/lib/merb/dispatcher.rb +109 -0
- data/lib/merb/{merb_drb_server.rb → drb_server.rb} +0 -0
- data/lib/merb/erubis_ext.rb +10 -0
- data/lib/merb/exceptions.rb +173 -0
- data/lib/merb/generators/merb_app/merb_app.rb +5 -25
- data/lib/merb/generators/merb_generator_helpers.rb +317 -0
- data/lib/merb/generators/merb_plugin.rb +19 -0
- data/lib/merb/logger.rb +65 -0
- data/lib/merb/{merb_mail_controller.rb → mail_controller.rb} +102 -49
- data/lib/merb/{merb_mailer.rb → mailer.rb} +31 -27
- data/lib/merb/mixins/{basic_authentication_mixin.rb → basic_authentication.rb} +3 -3
- data/lib/merb/mixins/{controller_mixin.rb → controller.rb} +131 -112
- data/lib/merb/mixins/{erubis_capture_mixin.rb → erubis_capture.rb} +12 -21
- data/lib/merb/mixins/{form_control_mixin.rb → form_control.rb} +6 -12
- data/lib/merb/mixins/render.rb +401 -0
- data/lib/merb/mixins/responder.rb +378 -0
- data/lib/merb/mixins/{view_context_mixin.rb → view_context.rb} +65 -10
- data/lib/merb/mixins/web_controller.rb +29 -0
- data/lib/merb/{merb_handler.rb → mongrel_handler.rb} +59 -38
- data/lib/merb/part_controller.rb +19 -0
- data/lib/merb/plugins.rb +16 -0
- data/lib/merb/rack_adapter.rb +37 -0
- data/lib/merb/request.rb +421 -0
- data/lib/merb/router.rb +576 -0
- data/lib/merb/{merb_server.rb → server.rb} +275 -71
- data/lib/merb/session.rb +10 -10
- data/lib/merb/session/cookie_store.rb +125 -0
- data/lib/merb/session/{merb_mem_cache_session.rb → mem_cache_session.rb} +22 -9
- data/lib/merb/session/{merb_memory_session.rb → memory_session.rb} +15 -11
- data/lib/merb/template.rb +35 -8
- data/lib/merb/template/erubis.rb +16 -10
- data/lib/merb/template/haml.rb +33 -20
- data/lib/merb/template/markaby.rb +16 -14
- data/lib/merb/template/xml_builder.rb +8 -4
- data/lib/merb/test/{merb_fake_request.rb → fake_request.rb} +11 -5
- data/lib/merb/test/helper.rb +31 -0
- data/lib/merb/test/hpricot.rb +136 -0
- data/lib/merb/test/{merb_multipart.rb → multipart.rb} +1 -1
- data/lib/merb/test/rspec.rb +93 -0
- data/lib/merb/{merb_upload_handler.rb → upload_handler.rb} +5 -6
- data/lib/merb/{merb_upload_progress.rb → upload_progress.rb} +1 -1
- data/lib/merb/{merb_view_context.rb → view_context.rb} +27 -42
- data/lib/{merb_tasks.rb → tasks.rb} +0 -0
- data/lib/tasks/merb.rake +21 -11
- data/merb_default_generators/model/USAGE +0 -0
- data/merb_default_generators/model/model_generator.rb +16 -0
- data/merb_default_generators/model/templates/new_model_template.erb +5 -0
- data/merb_default_generators/resource_controller/USAGE +0 -0
- data/merb_default_generators/resource_controller/resource_controller_generator.rb +26 -0
- data/merb_default_generators/resource_controller/templates/controller.rb +30 -0
- data/merb_default_generators/resource_controller/templates/edit.html.erb +1 -0
- data/merb_default_generators/resource_controller/templates/helper.rb +5 -0
- data/merb_default_generators/resource_controller/templates/index.html.erb +1 -0
- data/merb_default_generators/resource_controller/templates/new.html.erb +1 -0
- data/merb_default_generators/resource_controller/templates/show.html.erb +1 -0
- data/merb_generators/controller/USAGE +5 -0
- data/merb_generators/controller/controller_generator.rb +16 -0
- data/merb_generators/controller/templates/controller.rb +8 -0
- data/merb_generators/controller/templates/helper.rb +5 -0
- data/merb_generators/controller/templates/index.html.erb +3 -0
- data/merb_generators/resource/USAGE +0 -0
- data/merb_generators/resource/resource_generator.rb +60 -0
- data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +67 -0
- data/rspec_generators/merb_controller_test/templates/controller_spec.rb +8 -0
- data/rspec_generators/merb_controller_test/templates/edit_spec.rb +12 -0
- data/rspec_generators/merb_controller_test/templates/helper_spec.rb +5 -0
- data/rspec_generators/merb_controller_test/templates/index_spec.rb +12 -0
- data/rspec_generators/merb_controller_test/templates/new_spec.rb +12 -0
- data/rspec_generators/merb_controller_test/templates/show_spec.rb +5 -0
- data/rspec_generators/merb_model_test/merb_model_test_generator.rb +26 -0
- data/rspec_generators/merb_model_test/templates/model_spec_template.erb +7 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +53 -0
- data/test_unit_generators/merb_controller_test/templates/functional_test.rb +17 -0
- data/test_unit_generators/merb_controller_test/templates/helper_test.rb +9 -0
- data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +29 -0
- data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +9 -0
- metadata +172 -94
- data/examples/README_EXAMPLES +0 -10
- data/examples/skeleton/Rakefile +0 -68
- data/examples/skeleton/dist/app/views/layout/application.herb +0 -12
- data/examples/skeleton/dist/conf/database.yml +0 -23
- data/examples/skeleton/dist/conf/merb.yml +0 -57
- data/examples/skeleton/dist/conf/merb_init.rb +0 -24
- data/examples/skeleton/dist/conf/router.rb +0 -22
- data/examples/skeleton/dist/conf/upload.conf +0 -5
- data/examples/skeleton/dist/schema/migrations/001_add_sessions_table.rb +0 -14
- data/examples/skeleton/script/new_migration +0 -21
- data/lib/merb/core_ext/merb_string.rb +0 -18
- data/lib/merb/merb_controller.rb +0 -206
- data/lib/merb/merb_dispatcher.rb +0 -87
- data/lib/merb/merb_exceptions.rb +0 -319
- data/lib/merb/merb_part_controller.rb +0 -42
- data/lib/merb/merb_plugins.rb +0 -293
- data/lib/merb/merb_request.rb +0 -165
- data/lib/merb/merb_router.rb +0 -309
- data/lib/merb/merb_yaml_store.rb +0 -31
- data/lib/merb/mixins/render_mixin.rb +0 -283
- data/lib/merb/mixins/responder_mixin.rb +0 -159
- data/lib/merb/session/merb_ar_session.rb +0 -131
- data/lib/merb/vendor/paginator/README.txt +0 -84
- data/lib/merb/vendor/paginator/paginator.rb +0 -124
- data/lib/tasks/db.rake +0 -55
data/bin/merb
CHANGED
@@ -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
|
data/lib/merb.rb
CHANGED
@@ -9,114 +9,93 @@ else
|
|
9
9
|
require 'mongrel'
|
10
10
|
end
|
11
11
|
require 'fileutils'
|
12
|
-
require '
|
13
|
-
require 'logger'
|
14
|
-
|
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.
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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
|
-
|
103
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
31
|
-
if fragment = ::Merb::Caching::Fragment.get(
|
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
|
-
|
38
|
-
::Merb::Caching::Fragment.put(
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|