merb-core 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +285 -0
- data/TODO +0 -0
- data/bin/merb +8 -0
- data/bin/merb-specs +5 -0
- data/docs/bootloading.dox +57 -0
- data/docs/documentation_standards +40 -0
- data/docs/new_render_api +51 -0
- data/lib/merb-core.rb +304 -0
- data/lib/merb-core/autoload.rb +29 -0
- data/lib/merb-core/bootloader.rb +601 -0
- data/lib/merb-core/config.rb +284 -0
- data/lib/merb-core/constants.rb +43 -0
- data/lib/merb-core/controller/abstract_controller.rb +531 -0
- data/lib/merb-core/controller/exceptions.rb +257 -0
- data/lib/merb-core/controller/merb_controller.rb +214 -0
- data/lib/merb-core/controller/mime.rb +88 -0
- data/lib/merb-core/controller/mixins/controller.rb +262 -0
- data/lib/merb-core/controller/mixins/render.rb +324 -0
- data/lib/merb-core/controller/mixins/responder.rb +464 -0
- data/lib/merb-core/controller/template.rb +205 -0
- data/lib/merb-core/core_ext.rb +12 -0
- data/lib/merb-core/core_ext/class.rb +192 -0
- data/lib/merb-core/core_ext/hash.rb +422 -0
- data/lib/merb-core/core_ext/kernel.rb +304 -0
- data/lib/merb-core/core_ext/mash.rb +154 -0
- data/lib/merb-core/core_ext/object.rb +136 -0
- data/lib/merb-core/core_ext/object_space.rb +14 -0
- data/lib/merb-core/core_ext/rubygems.rb +28 -0
- data/lib/merb-core/core_ext/set.rb +41 -0
- data/lib/merb-core/core_ext/string.rb +69 -0
- data/lib/merb-core/dispatch/cookies.rb +92 -0
- data/lib/merb-core/dispatch/dispatcher.rb +233 -0
- data/lib/merb-core/dispatch/exceptions.html.erb +297 -0
- data/lib/merb-core/dispatch/request.rb +560 -0
- data/lib/merb-core/dispatch/router.rb +141 -0
- data/lib/merb-core/dispatch/router/behavior.rb +777 -0
- data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
- data/lib/merb-core/dispatch/router/route.rb +212 -0
- data/lib/merb-core/dispatch/session.rb +28 -0
- data/lib/merb-core/dispatch/session/cookie.rb +166 -0
- data/lib/merb-core/dispatch/session/memcached.rb +161 -0
- data/lib/merb-core/dispatch/session/memory.rb +234 -0
- data/lib/merb-core/gem_ext/erubis.rb +19 -0
- data/lib/merb-core/logger.rb +230 -0
- data/lib/merb-core/plugins.rb +25 -0
- data/lib/merb-core/rack.rb +15 -0
- data/lib/merb-core/rack/adapter.rb +42 -0
- data/lib/merb-core/rack/adapter/ebb.rb +22 -0
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +24 -0
- data/lib/merb-core/rack/adapter/fcgi.rb +16 -0
- data/lib/merb-core/rack/adapter/irb.rb +108 -0
- data/lib/merb-core/rack/adapter/mongrel.rb +25 -0
- data/lib/merb-core/rack/adapter/runner.rb +27 -0
- data/lib/merb-core/rack/adapter/thin.rb +27 -0
- data/lib/merb-core/rack/adapter/webrick.rb +35 -0
- data/lib/merb-core/rack/application.rb +77 -0
- data/lib/merb-core/rack/handler/mongrel.rb +97 -0
- data/lib/merb-core/server.rb +184 -0
- data/lib/merb-core/test.rb +10 -0
- data/lib/merb-core/test/helpers.rb +9 -0
- data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
- data/lib/merb-core/test/helpers/request_helper.rb +257 -0
- data/lib/merb-core/test/helpers/route_helper.rb +33 -0
- data/lib/merb-core/test/helpers/view_helper.rb +121 -0
- data/lib/merb-core/test/matchers.rb +9 -0
- data/lib/merb-core/test/matchers/controller_matchers.rb +269 -0
- data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
- data/lib/merb-core/test/matchers/view_matchers.rb +293 -0
- data/lib/merb-core/test/run_specs.rb +38 -0
- data/lib/merb-core/test/tasks/spectasks.rb +39 -0
- data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
- data/lib/merb-core/test/test_ext/object.rb +14 -0
- data/lib/merb-core/vendor/facets.rb +2 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
- data/lib/merb-core/vendor/facets/inflect.rb +211 -0
- data/lib/merb-core/version.rb +11 -0
- data/spec/private/config/adapter_spec.rb +32 -0
- data/spec/private/config/config_spec.rb +139 -0
- data/spec/private/config/environment_spec.rb +13 -0
- data/spec/private/config/spec_helper.rb +1 -0
- data/spec/private/core_ext/hash_spec.rb +506 -0
- data/spec/private/core_ext/kernel_spec.rb +46 -0
- data/spec/private/core_ext/object_spec.rb +39 -0
- data/spec/private/core_ext/set_spec.rb +26 -0
- data/spec/private/core_ext/string_spec.rb +9 -0
- data/spec/private/dispatch/cookies_spec.rb +107 -0
- data/spec/private/dispatch/dispatch_spec.rb +26 -0
- data/spec/private/dispatch/fixture/app/controllers/application.rb +4 -0
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +27 -0
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +21 -0
- data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +8 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +37 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +40 -0
- data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +11 -0
- data/spec/private/dispatch/fixture/config/environments/development.rb +6 -0
- data/spec/private/dispatch/fixture/config/environments/production.rb +5 -0
- data/spec/private/dispatch/fixture/config/environments/test.rb +6 -0
- data/spec/private/dispatch/fixture/config/init.rb +45 -0
- data/spec/private/dispatch/fixture/config/rack.rb +1 -0
- data/spec/private/dispatch/fixture/config/router.rb +35 -0
- data/spec/private/dispatch/fixture/log/development.log +1 -0
- data/spec/private/dispatch/fixture/log/merb.4000.pid +1 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +2040 -0
- data/spec/private/dispatch/fixture/log/production.log +1 -0
- data/spec/private/dispatch/fixture/merb.4000.pid +1 -0
- data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
- data/spec/private/dispatch/fixture/public/merb.fcgi +4 -0
- data/spec/private/dispatch/fixture/public/stylesheets/master.css +119 -0
- data/spec/private/dispatch/route_params_spec.rb +24 -0
- data/spec/private/dispatch/spec_helper.rb +1 -0
- data/spec/private/plugins/plugin_spec.rb +81 -0
- data/spec/private/rack/application_spec.rb +43 -0
- data/spec/public/DEFINITIONS +11 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/display.rb +54 -0
- data/spec/public/abstract_controller/controllers/filters.rb +167 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +31 -0
- data/spec/public/abstract_controller/controllers/partial.rb +106 -0
- data/spec/public/abstract_controller/controllers/render.rb +86 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/alt.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/custom.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +1 -0
- data/spec/public/abstract_controller/display_spec.rb +33 -0
- data/spec/public/abstract_controller/filter_spec.rb +80 -0
- data/spec/public/abstract_controller/helper_spec.rb +13 -0
- data/spec/public/abstract_controller/partial_spec.rb +53 -0
- data/spec/public/abstract_controller/render_spec.rb +70 -0
- data/spec/public/abstract_controller/spec_helper.rb +27 -0
- data/spec/public/boot_loader/boot_loader_spec.rb +33 -0
- data/spec/public/boot_loader/spec_helper.rb +1 -0
- data/spec/public/controller/base_spec.rb +31 -0
- data/spec/public/controller/controllers/base.rb +41 -0
- data/spec/public/controller/controllers/display.rb +40 -0
- data/spec/public/controller/controllers/responder.rb +67 -0
- data/spec/public/controller/controllers/url.rb +7 -0
- data/spec/public/controller/controllers/views/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +1 -0
- data/spec/public/controller/display_spec.rb +34 -0
- data/spec/public/controller/log/merb.4000.pid +1 -0
- data/spec/public/controller/responder_spec.rb +95 -0
- data/spec/public/controller/spec_helper.rb +9 -0
- data/spec/public/controller/url_spec.rb +152 -0
- data/spec/public/directory_structure/directory/app/controllers/application.rb +3 -0
- data/spec/public/directory_structure/directory/app/controllers/base.rb +13 -0
- data/spec/public/directory_structure/directory/app/controllers/custom.rb +19 -0
- data/spec/public/directory_structure/directory/app/views/base/template.html.erb +1 -0
- data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +1 -0
- data/spec/public/directory_structure/directory/config/router.rb +3 -0
- data/spec/public/directory_structure/directory/log/merb.4000.pid +1 -0
- data/spec/public/directory_structure/directory/log/merb_test.log +265 -0
- data/spec/public/directory_structure/directory/merb.4000.pid +1 -0
- data/spec/public/directory_structure/directory_spec.rb +44 -0
- data/spec/public/logger/logger_spec.rb +175 -0
- data/spec/public/logger/spec_helper.rb +1 -0
- data/spec/public/reloading/directory/app/controllers/application.rb +3 -0
- data/spec/public/reloading/directory/app/controllers/reload.rb +6 -0
- data/spec/public/reloading/directory/config/init.rb +2 -0
- data/spec/public/reloading/directory/log/merb.4000.pid +1 -0
- data/spec/public/reloading/directory/log/merb_test.log +59 -0
- data/spec/public/reloading/directory/merb.4000.pid +1 -0
- data/spec/public/reloading/reload_spec.rb +80 -0
- data/spec/public/request/multipart_spec.rb +15 -0
- data/spec/public/request/request_spec.rb +207 -0
- data/spec/public/router/default_spec.rb +21 -0
- data/spec/public/router/deferred_spec.rb +22 -0
- data/spec/public/router/namespace_spec.rb +113 -0
- data/spec/public/router/nested_resources_spec.rb +34 -0
- data/spec/public/router/resource_spec.rb +45 -0
- data/spec/public/router/resources_spec.rb +57 -0
- data/spec/public/router/spec_helper.rb +72 -0
- data/spec/public/router/special_spec.rb +44 -0
- data/spec/public/router/string_spec.rb +61 -0
- data/spec/public/template/template_spec.rb +92 -0
- data/spec/public/template/templates/error.html.erb +2 -0
- data/spec/public/template/templates/template.html.erb +1 -0
- data/spec/public/template/templates/template.html.myt +1 -0
- data/spec/public/test/controller_matchers_spec.rb +378 -0
- data/spec/public/test/controllers/controller_assertion_mock.rb +7 -0
- data/spec/public/test/controllers/dispatch_controller.rb +11 -0
- data/spec/public/test/controllers/spec_helper_controller.rb +30 -0
- data/spec/public/test/multipart_request_helper_spec.rb +159 -0
- data/spec/public/test/multipart_upload_text_file.txt +1 -0
- data/spec/public/test/request_helper_spec.rb +153 -0
- data/spec/public/test/route_helper_spec.rb +54 -0
- data/spec/public/test/route_matchers_spec.rb +133 -0
- data/spec/public/test/view_helper_spec.rb +96 -0
- data/spec/public/test/view_matchers_spec.rb +107 -0
- data/spec/spec_helper.rb +71 -0
- metadata +488 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
module Merb
|
2
|
+
|
3
|
+
module Plugins
|
4
|
+
|
5
|
+
# ==== Returns
|
6
|
+
# Hash::
|
7
|
+
# The configuration loaded from Merb.root / "config/plugins.yml" or, if
|
8
|
+
# the load fails, an empty hash.
|
9
|
+
def self.config
|
10
|
+
@config ||= File.exists?(Merb.root / "config" / "plugins.yml") ? YAML.load(File.read(Merb.root / "config" / "plugins.yml")) || {} : {}
|
11
|
+
end
|
12
|
+
|
13
|
+
# ==== Returns
|
14
|
+
# Array:: All Rakefiles for plugins.
|
15
|
+
def self.rakefiles
|
16
|
+
Merb.rakefiles
|
17
|
+
end
|
18
|
+
|
19
|
+
# ==== Parameters
|
20
|
+
# *rakefiles:: Rakefiles to add to the list of plugin Rakefiles.
|
21
|
+
def self.add_rakefiles(*rakefiles)
|
22
|
+
Merb.add_rakefiles *rakefiles
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rack'
|
2
|
+
module Merb
|
3
|
+
module Rack
|
4
|
+
autoload :Application, "merb-core/rack/application"
|
5
|
+
autoload :Adapter, "merb-core/rack/adapter"
|
6
|
+
autoload :Ebb, "merb-core/rack/adapter/ebb"
|
7
|
+
autoload :EventedMongrel, "merb-core/rack/adapter/evented_mongrel"
|
8
|
+
autoload :FastCGI, "merb-core/rack/adapter/fcgi"
|
9
|
+
autoload :Irb, "merb-core/rack/adapter/irb"
|
10
|
+
autoload :Mongrel, "merb-core/rack/adapter/mongrel"
|
11
|
+
autoload :Runner, "merb-core/rack/adapter/runner"
|
12
|
+
autoload :Thin, "merb-core/rack/adapter/thin"
|
13
|
+
autoload :WEBrick, "merb-core/rack/adapter/webrick"
|
14
|
+
end # Rack
|
15
|
+
end # Merb
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Merb
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
|
5
|
+
class Adapter
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# ==== Parameters
|
9
|
+
# id<String>:: The identifier of the Rack adapter class to retrieve.
|
10
|
+
#
|
11
|
+
# ==== Returns.
|
12
|
+
# Class:: The adapter class.
|
13
|
+
def get(id)
|
14
|
+
Object.full_const_get(@adapters[id])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Registers a new Rack adapter.
|
18
|
+
#
|
19
|
+
# ==== Parameters
|
20
|
+
# ids<Array>:: Identifiers by which this adapter is recognized by.
|
21
|
+
# adapter_class<Class>:: The Rack adapter class.
|
22
|
+
def register(ids, adapter_class)
|
23
|
+
@adapters ||= Hash.new
|
24
|
+
ids.each { |id| @adapters[id] = "Merb::Rack::#{adapter_class}" }
|
25
|
+
end
|
26
|
+
end # class << self
|
27
|
+
|
28
|
+
end # Adapter
|
29
|
+
|
30
|
+
# Register some Rack adapters
|
31
|
+
Adapter.register %w{ebb}, :Ebb
|
32
|
+
Adapter.register %w{emongrel}, :EventedMongrel
|
33
|
+
Adapter.register %w{fastcgi fcgi}, :FastCGI
|
34
|
+
Adapter.register %w{irb}, :Irb
|
35
|
+
Adapter.register %w{mongrel}, :Mongrel
|
36
|
+
Adapter.register %w{runner}, :Runner
|
37
|
+
Adapter.register %w{thin}, :Thin
|
38
|
+
Adapter.register %w{webrick}, :WEBrick
|
39
|
+
|
40
|
+
end # Rack
|
41
|
+
end # Merb
|
42
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'ebb'
|
2
|
+
module Merb
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
|
6
|
+
class Ebb
|
7
|
+
# start an Ebb server on given host and port.
|
8
|
+
|
9
|
+
# ==== Parameters
|
10
|
+
# opts<Hash>:: Options for Thin (see below).
|
11
|
+
#
|
12
|
+
# ==== Options (opts)
|
13
|
+
# :host<String>:: The hostname that Thin should serve.
|
14
|
+
# :port<Fixnum>:: The port Ebb should bind to.
|
15
|
+
# :app:: The application
|
16
|
+
def self.start(opts={})
|
17
|
+
Merb.logger.warn!("Using Ebb adapter")
|
18
|
+
::Ebb.start_server(opts[:app], opts)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'swiftcore/evented_mongrel'
|
2
|
+
require 'merb-core/rack/handler/mongrel'
|
3
|
+
module Merb
|
4
|
+
module Rack
|
5
|
+
|
6
|
+
class EventedMongrel < Mongrel
|
7
|
+
# Starts Mongrel as evented.
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# opts<Hash>:: Options for Mongrel (see below).
|
11
|
+
#
|
12
|
+
# ==== Options (opts)
|
13
|
+
# :host<String>:: The hostname that Mongrel should serve.
|
14
|
+
# :port<Fixnum>:: The port Mongrel should bind to.
|
15
|
+
# :app<String>>:: The application name.
|
16
|
+
def self.start(opts={})
|
17
|
+
Merb.logger.warn!("Using EventedMongrel adapter")
|
18
|
+
server = ::Mongrel::HttpServer.new(opts[:host], opts[:port].to_i)
|
19
|
+
server.register('/', ::Merb::Rack::Handler::Mongrel.new(opts[:app]))
|
20
|
+
server.run.join
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Merb
|
2
|
+
module Rack
|
3
|
+
|
4
|
+
class FastCGI
|
5
|
+
# ==== Parameters
|
6
|
+
# opts<Hash>:: Options for FastCGI (see below).
|
7
|
+
#
|
8
|
+
# ==== Options (opts)
|
9
|
+
# :app<String>>:: The application name.
|
10
|
+
def self.start(opts={})
|
11
|
+
Merb.logger.warn!("Using FastCGI adapter")
|
12
|
+
::Rack::Handler::FastCGI.run(opts[:app], opts)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module Merb
|
2
|
+
module Rack
|
3
|
+
class Console
|
4
|
+
# ==== Parameters
|
5
|
+
# name<~to_sym, Hash>:: The name of the route to generate.
|
6
|
+
# params<Hash>:: The params to use in the route generation.
|
7
|
+
#
|
8
|
+
# ==== Returns
|
9
|
+
# String:: The generated URL.
|
10
|
+
#
|
11
|
+
# ==== Alternatives
|
12
|
+
# If name is a hash, it will be merged with params.
|
13
|
+
def url(name, params={})
|
14
|
+
Merb::Router.generate(name, params)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Reloads classes using Merb::BootLoader::ReloadClasses.
|
18
|
+
def reload!
|
19
|
+
Merb::BootLoader::ReloadClasses.reload
|
20
|
+
end
|
21
|
+
|
22
|
+
# Prints all routes for the application.
|
23
|
+
def show_routes
|
24
|
+
seen = []
|
25
|
+
unless Merb::Router.named_routes.empty?
|
26
|
+
puts "Named Routes"
|
27
|
+
Merb::Router.named_routes.each do |name,route|
|
28
|
+
puts " #{name}: #{route}"
|
29
|
+
seen << route
|
30
|
+
end
|
31
|
+
end
|
32
|
+
puts "Anonymous Routes"
|
33
|
+
(Merb::Router.routes - seen).each do |route|
|
34
|
+
puts " #{route}"
|
35
|
+
end
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# Starts a sandboxed session (delegates to any Merb::Orms::* modules).
|
40
|
+
#
|
41
|
+
# An ORM should implement Merb::Orms::MyOrm#open_sandbox! to support this.
|
42
|
+
# Usually this involves starting a transaction.
|
43
|
+
def open_sandbox!
|
44
|
+
puts "Loading #{Merb.environment} environment in sandbox (Merb #{Merb::VERSION})"
|
45
|
+
puts "Any modifications you make will be rolled back on exit"
|
46
|
+
orm_modules.each { |orm| orm.open_sandbox! if orm.respond_to?(:open_sandbox!) }
|
47
|
+
end
|
48
|
+
|
49
|
+
# Ends a sandboxed session (delegates to any Merb::Orms::* modules).
|
50
|
+
#
|
51
|
+
# An ORM should implement Merb::Orms::MyOrm#close_sandbox! to support this.
|
52
|
+
# Usually this involves rolling back a transaction.
|
53
|
+
def close_sandbox!
|
54
|
+
orm_modules.each { |orm| orm.close_sandbox! if orm.respond_to?(:close_sandbox!) }
|
55
|
+
puts "Modifications have been rolled back"
|
56
|
+
end
|
57
|
+
|
58
|
+
# Explictly show logger output during IRB session
|
59
|
+
def trace_log!
|
60
|
+
Merb.logger.auto_flush = true
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
# ==== Returns
|
66
|
+
# Array:: All Merb::Orms::* modules.
|
67
|
+
def orm_modules
|
68
|
+
if Merb.const_defined?('Orms')
|
69
|
+
Merb::Orms.constants.map { |c| Merb::Orms::const_get(c) }
|
70
|
+
else
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
class Irb
|
78
|
+
# ==== Parameters
|
79
|
+
# opts<Hash>:
|
80
|
+
# Options for IRB. Currently this is not used by the IRB adapter.
|
81
|
+
#
|
82
|
+
# ==== Notes
|
83
|
+
# If the +.irbrc+ file exists, it will be loaded into the IRBRC
|
84
|
+
# environment variable.
|
85
|
+
def self.start(opts={})
|
86
|
+
m = Merb::Rack::Console.new
|
87
|
+
m.extend Merb::Test::RequestHelper
|
88
|
+
Object.send(:define_method, :merb) { m }
|
89
|
+
ARGV.clear # Avoid passing args to IRB
|
90
|
+
m.open_sandbox! if sandboxed?
|
91
|
+
require 'irb'
|
92
|
+
require 'irb/completion'
|
93
|
+
if File.exists? ".irbrc"
|
94
|
+
ENV['IRBRC'] = ".irbrc"
|
95
|
+
end
|
96
|
+
IRB.start
|
97
|
+
at_exit do merb.close_sandbox! if sandboxed? end
|
98
|
+
exit
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def self.sandboxed?
|
104
|
+
Merb::Config[:sandbox]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'mongrel'
|
2
|
+
require 'merb-core/rack/handler/mongrel'
|
3
|
+
module Merb
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
|
7
|
+
class Mongrel
|
8
|
+
# start server on given host and port.
|
9
|
+
|
10
|
+
# ==== Parameters
|
11
|
+
# opts<Hash>:: Options for Mongrel (see below).
|
12
|
+
#
|
13
|
+
# ==== Options (opts)
|
14
|
+
# :host<String>:: The hostname that Mongrel should serve.
|
15
|
+
# :port<Fixnum>:: The port Mongrel should bind to.
|
16
|
+
# :app<String>>:: The application name.
|
17
|
+
def self.start(opts={})
|
18
|
+
Merb.logger.warn!("Using Mongrel adapter")
|
19
|
+
server = ::Mongrel::HttpServer.new(opts[:host], opts[:port].to_i)
|
20
|
+
server.register('/', ::Merb::Rack::Handler::Mongrel.new(opts[:app]))
|
21
|
+
server.run.join
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Merb
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
|
5
|
+
class Runner
|
6
|
+
# ==== Parameters
|
7
|
+
# opts<Hash>:: Options for the runner (see below).
|
8
|
+
#
|
9
|
+
# ==== Options (opts)
|
10
|
+
# :runner_code<String>:: The code to run.
|
11
|
+
#
|
12
|
+
# ==== Notes
|
13
|
+
# If opts[:runner_code] matches a filename, that file will be read and
|
14
|
+
# the contents executed. Otherwise the code will be executed directly.
|
15
|
+
def self.start(opts={})
|
16
|
+
if opts[:runner_code]
|
17
|
+
if File.exists?(opts[:runner_code])
|
18
|
+
eval(File.read(opts[:runner_code]), TOPLEVEL_BINDING, __FILE__, __LINE__)
|
19
|
+
else
|
20
|
+
eval(opts[:runner_code], TOPLEVEL_BINDING, __FILE__, __LINE__)
|
21
|
+
end
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'thin'
|
2
|
+
module Merb
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
|
6
|
+
class Thin
|
7
|
+
# start a Thin server on given host and port.
|
8
|
+
|
9
|
+
# ==== Parameters
|
10
|
+
# opts<Hash>:: Options for Thin (see below).
|
11
|
+
#
|
12
|
+
# ==== Options (opts)
|
13
|
+
# :host<String>:: The hostname that Thin should serve.
|
14
|
+
# :port<Fixnum>:: The port Thin should bind to.
|
15
|
+
# :app<String>>:: The application name.
|
16
|
+
def self.start(opts={})
|
17
|
+
Merb.logger.warn!("Using Thin adapter")
|
18
|
+
if opts[:host].include?('/')
|
19
|
+
opts[:host] = "#{opts[:host]}-#{opts[:port]}"
|
20
|
+
end
|
21
|
+
server = ::Thin::Server.new(opts[:host], opts[:port], opts[:app])
|
22
|
+
::Thin::Logging.silent = true
|
23
|
+
server.start!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'rack/handler/webrick'
|
3
|
+
module Merb
|
4
|
+
module Rack
|
5
|
+
|
6
|
+
class WEBrick
|
7
|
+
# start WEBrick server on given host and port.
|
8
|
+
|
9
|
+
# ==== Parameters
|
10
|
+
# opts<Hash>:: Options for WEBrick (see below).
|
11
|
+
#
|
12
|
+
# ==== Options (opts)
|
13
|
+
# :host<String>:: The hostname that WEBrick should serve.
|
14
|
+
# :port<Fixnum>:: The port WEBrick should bind to.
|
15
|
+
# :app<String>>:: The application name.
|
16
|
+
def self.start(opts={})
|
17
|
+
Merb.logger.warn!("Using Webrick adapter")
|
18
|
+
|
19
|
+
options = {
|
20
|
+
:Port => opts[:port],
|
21
|
+
:BindAddress => opts[:host],
|
22
|
+
:Logger => Merb.logger,
|
23
|
+
:AccessLog => [
|
24
|
+
[Merb.logger, ::WEBrick::AccessLog::COMMON_LOG_FORMAT],
|
25
|
+
[Merb.logger, ::WEBrick::AccessLog::REFERER_LOG_FORMAT]
|
26
|
+
]
|
27
|
+
}
|
28
|
+
|
29
|
+
server = ::WEBrick::HTTPServer.new(options)
|
30
|
+
server.mount("/", ::Rack::Handler::WEBrick, opts[:app])
|
31
|
+
server.start
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Merb
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
|
5
|
+
class Application
|
6
|
+
# ==== Parameters
|
7
|
+
# options<Hash>::
|
8
|
+
# Options for creating a new application. Currently ignored.
|
9
|
+
def initialize(options={})
|
10
|
+
@static_server = ::Rack::File.new Merb.dir_for(:public)
|
11
|
+
if prefix = ::Merb::Config[:path_prefix]
|
12
|
+
@path_prefix = /^#{Regexp.escape(prefix)}/
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# ==== Parameters
|
17
|
+
# env<Hash>:: Environment variables to pass on to the application.
|
18
|
+
#
|
19
|
+
# ==== Returns
|
20
|
+
# Array[Array]::
|
21
|
+
# A 3 element tuple consisting of response status, headers and body.
|
22
|
+
def call(env)
|
23
|
+
strip_path_prefix(env) if @path_prefix # Strip out the path_prefix if one was set
|
24
|
+
path = env['PATH_INFO'] ? env['PATH_INFO'].chomp('/') : ""
|
25
|
+
cached_path = (path.empty? ? 'index' : path) + '.html'
|
26
|
+
Merb.logger.info "Request: #{path}"
|
27
|
+
if file_exist?(path) && env['REQUEST_METHOD'] =~ /GET|HEAD/ # Serve the file if it's there and the request method is GET or HEAD
|
28
|
+
serve_static(env)
|
29
|
+
elsif file_exist?(cached_path) && env['REQUEST_METHOD'] =~ /GET|HEAD/ # Serve the page cache if it's there and the request method is GET or HEAD
|
30
|
+
env['PATH_INFO'] = cached_path
|
31
|
+
serve_static(env)
|
32
|
+
else # No static file, let Merb handle it
|
33
|
+
if path =~ /favicon\.ico/
|
34
|
+
return [404, {"Content-Type"=>"text/html"}, "404 Not Found."]
|
35
|
+
end
|
36
|
+
begin
|
37
|
+
controller = ::Merb::Dispatcher.handle(env)
|
38
|
+
rescue Object => e
|
39
|
+
return [500, {"Content-Type"=>"text/html"}, e.message + "<br/>" + e.backtrace.join("<br/>")]
|
40
|
+
end
|
41
|
+
Merb.logger.info "\n\n"
|
42
|
+
Merb.logger.flush
|
43
|
+
[controller.status, controller.headers, controller.body]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# ==== Parameters
|
48
|
+
# path<String>:: The path to the file relative to the server root.
|
49
|
+
#
|
50
|
+
# ==== Returns
|
51
|
+
# Boolean:: True if file exists under the server root and is readable.
|
52
|
+
def file_exist?(path)
|
53
|
+
full_path = ::File.join(@static_server.root, ::Merb::Request.unescape(path))
|
54
|
+
::File.file?(full_path) && ::File.readable?(full_path)
|
55
|
+
end
|
56
|
+
|
57
|
+
# ==== Parameters
|
58
|
+
# env<Hash>:: Environment variables to pass on to the server.
|
59
|
+
def serve_static(env)
|
60
|
+
env["PATH_INFO"] = ::Merb::Request.unescape(env["PATH_INFO"])
|
61
|
+
@static_server.call(env)
|
62
|
+
end
|
63
|
+
|
64
|
+
# ==== Parameters
|
65
|
+
# env<Hash>:: Environment variables to pass on to the server.
|
66
|
+
def strip_path_prefix(env)
|
67
|
+
['PATH_INFO', 'REQUEST_URI'].each do |path_key|
|
68
|
+
if env[path_key] =~ @path_prefix
|
69
|
+
env[path_key].sub!(@path_prefix, '')
|
70
|
+
env[path_key] = '/' if env[path_key].empty?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|