waves-stable 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/Rakefile +72 -0
- data/app/bin/waves-console +4 -0
- data/app/bin/waves-server +4 -0
- data/app/configurations/development.rb.erb +31 -0
- data/app/configurations/mapping.rb.erb +14 -0
- data/app/configurations/production.rb.erb +31 -0
- data/app/controllers/.gitignore +0 -0
- data/app/doc/.gitignore +0 -0
- data/app/helpers/.gitignore +0 -0
- data/app/lib/application.rb.erb +5 -0
- data/app/lib/tasks/.gitignore +0 -0
- data/app/log/.gitignore +0 -0
- data/app/models/.gitignore +0 -0
- data/app/public/css/.gitignore +0 -0
- data/app/public/flash/.gitignore +0 -0
- data/app/public/images/.gitignore +0 -0
- data/app/public/javascript/.gitignore +0 -0
- data/app/schema/migrations/.gitignore +0 -0
- data/app/startup.rb +5 -0
- data/app/templates/errors/not_found_404.mab +2 -0
- data/app/templates/errors/server_error_500.mab +2 -0
- data/app/templates/layouts/default.mab +14 -0
- data/app/tmp/sessions/.gitignore +0 -0
- data/app/views/.gitignore +0 -0
- data/bin/waves +84 -0
- data/bin/waves-console +4 -0
- data/bin/waves-server +4 -0
- data/doc/HISTORY +44 -0
- data/doc/LICENSE +22 -0
- data/lib/commands/waves-console.rb +21 -0
- data/lib/commands/waves-server.rb +55 -0
- data/lib/controllers/base.rb +11 -0
- data/lib/controllers/mixin.rb +165 -0
- data/lib/dispatchers/base.rb +67 -0
- data/lib/dispatchers/default.rb +81 -0
- data/lib/foundations/default.rb +27 -0
- data/lib/foundations/simple.rb +30 -0
- data/lib/helpers/asset_helper.rb +67 -0
- data/lib/helpers/common.rb +66 -0
- data/lib/helpers/default.rb +13 -0
- data/lib/helpers/form.rb +40 -0
- data/lib/helpers/formatting.rb +30 -0
- data/lib/helpers/model.rb +33 -0
- data/lib/helpers/number_helper.rb +25 -0
- data/lib/helpers/tag_helper.rb +58 -0
- data/lib/helpers/url_helper.rb +77 -0
- data/lib/helpers/view.rb +24 -0
- data/lib/layers/default_errors.rb +26 -0
- data/lib/layers/inflect/english.rb +24 -0
- data/lib/layers/inflect/english/rules.rb +88 -0
- data/lib/layers/inflect/english/string.rb +24 -0
- data/lib/layers/mvc.rb +54 -0
- data/lib/layers/orm/active_record.rb +92 -0
- data/lib/layers/orm/active_record/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/active_record/tasks/generate.rb +28 -0
- data/lib/layers/orm/active_record/tasks/schema.rb +22 -0
- data/lib/layers/orm/data_mapper.rb +38 -0
- data/lib/layers/orm/filebase.rb +22 -0
- data/lib/layers/orm/migration.rb +79 -0
- data/lib/layers/orm/sequel.rb +86 -0
- data/lib/layers/orm/sequel/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/sequel/tasks/generate.rb +28 -0
- data/lib/layers/orm/sequel/tasks/schema.rb +16 -0
- data/lib/layers/simple.rb +32 -0
- data/lib/layers/simple_errors.rb +23 -0
- data/lib/mapping/mapping.rb +289 -0
- data/lib/mapping/pretty_urls.rb +96 -0
- data/lib/renderers/erubis.rb +63 -0
- data/lib/renderers/haml.rb +45 -0
- data/lib/renderers/markaby.rb +33 -0
- data/lib/renderers/mixin.rb +50 -0
- data/lib/runtime/application.rb +69 -0
- data/lib/runtime/blackboard.rb +57 -0
- data/lib/runtime/configuration.rb +185 -0
- data/lib/runtime/console.rb +20 -0
- data/lib/runtime/debugger.rb +9 -0
- data/lib/runtime/logger.rb +59 -0
- data/lib/runtime/mime_types.rb +22 -0
- data/lib/runtime/request.rb +78 -0
- data/lib/runtime/response.rb +40 -0
- data/lib/runtime/response_mixin.rb +38 -0
- data/lib/runtime/response_proxy.rb +30 -0
- data/lib/runtime/server.rb +107 -0
- data/lib/runtime/session.rb +66 -0
- data/lib/tasks/cluster.rb +26 -0
- data/lib/tasks/gem.rb +31 -0
- data/lib/tasks/generate.rb +80 -0
- data/lib/utilities/hash.rb +31 -0
- data/lib/utilities/inflect.rb +110 -0
- data/lib/utilities/integer.rb +24 -0
- data/lib/utilities/module.rb +21 -0
- data/lib/utilities/object.rb +25 -0
- data/lib/utilities/proc.rb +16 -0
- data/lib/utilities/string.rb +49 -0
- data/lib/utilities/symbol.rb +10 -0
- data/lib/utilities/tempfile.rb +9 -0
- data/lib/views/base.rb +9 -0
- data/lib/views/mixin.rb +110 -0
- data/lib/waves.rb +84 -0
- data/samples/blog/Rakefile +14 -0
- data/samples/blog/bin/waves-console +3 -0
- data/samples/blog/bin/waves-server +3 -0
- data/samples/blog/configurations/development.rb +31 -0
- data/samples/blog/configurations/mapping.rb +23 -0
- data/samples/blog/configurations/production.rb +30 -0
- data/samples/blog/doc/EMTPY +0 -0
- data/samples/blog/lib/application.rb +5 -0
- data/samples/blog/models/comment.rb +14 -0
- data/samples/blog/models/entry.rb +14 -0
- data/samples/blog/public/css/site.css +2 -0
- data/samples/blog/public/javascript/site.js +13 -0
- data/samples/blog/schema/migrations/001_initial_schema.rb +17 -0
- data/samples/blog/schema/migrations/002_add_comments.rb +18 -0
- data/samples/blog/schema/migrations/templates/empty.rb.erb +9 -0
- data/samples/blog/startup.rb +6 -0
- data/samples/blog/templates/comment/add.mab +10 -0
- data/samples/blog/templates/comment/list.mab +6 -0
- data/samples/blog/templates/entry/editor.mab +13 -0
- data/samples/blog/templates/entry/list.mab +11 -0
- data/samples/blog/templates/entry/show.mab +9 -0
- data/samples/blog/templates/entry/summary.mab +5 -0
- data/samples/blog/templates/errors/not_found_404.mab +2 -0
- data/samples/blog/templates/errors/server_error_500.mab +2 -0
- data/samples/blog/templates/layouts/default.mab +17 -0
- data/verify/app_generation/helpers.rb +24 -0
- data/verify/app_generation/startup.rb +39 -0
- data/verify/blackboard/blackboard_verify.rb +92 -0
- data/verify/blackboard/helpers.rb +5 -0
- data/verify/configurations/attributes.rb +37 -0
- data/verify/configurations/helpers.rb +1 -0
- data/verify/configurations/rack_integration.rb +29 -0
- data/verify/controllers/base.rb +37 -0
- data/verify/controllers/helpers.rb +13 -0
- data/verify/controllers/interface.rb +51 -0
- data/verify/core/helpers.rb +3 -0
- data/verify/core/utilities.rb +177 -0
- data/verify/foundations/default.rb +86 -0
- data/verify/foundations/default_application/Rakefile +14 -0
- data/verify/foundations/default_application/bin/waves-console +3 -0
- data/verify/foundations/default_application/bin/waves-server +3 -0
- data/verify/foundations/default_application/configurations/development.rb +26 -0
- data/verify/foundations/default_application/configurations/mapping.rb +14 -0
- data/verify/foundations/default_application/configurations/production.rb +30 -0
- data/verify/foundations/default_application/controllers/default.rb +15 -0
- data/verify/foundations/default_application/controllers/loaded.rb +15 -0
- data/verify/foundations/default_application/defaultapplication.db +0 -0
- data/verify/foundations/default_application/helpers/loaded.rb +10 -0
- data/verify/foundations/default_application/lib/application.rb +5 -0
- data/verify/foundations/default_application/models/default.rb +13 -0
- data/verify/foundations/default_application/models/loaded.rb +13 -0
- data/verify/foundations/default_application/schema/migrations/templates/empty.rb.erb +9 -0
- data/verify/foundations/default_application/startup.rb +7 -0
- data/verify/foundations/default_application/templates/errors/not_found_404.mab +2 -0
- data/verify/foundations/default_application/templates/errors/server_error_500.mab +2 -0
- data/verify/foundations/default_application/templates/layouts/default.mab +14 -0
- data/verify/foundations/default_application/views/default.rb +7 -0
- data/verify/foundations/default_application/views/loaded.rb +15 -0
- data/verify/foundations/helpers.rb +1 -0
- data/verify/foundations/simple.rb +25 -0
- data/verify/helpers.rb +76 -0
- data/verify/layers/data_mapper/association_verify.rb +87 -0
- data/verify/layers/default_errors.rb +29 -0
- data/verify/layers/helpers.rb +1 -0
- data/verify/layers/migration.rb +33 -0
- data/verify/layers/sequel/model.rb +41 -0
- data/verify/mapping/always.rb +19 -0
- data/verify/mapping/filters.rb +65 -0
- data/verify/mapping/handle.rb +24 -0
- data/verify/mapping/helpers.rb +7 -0
- data/verify/mapping/matches.rb +27 -0
- data/verify/mapping/named.rb +29 -0
- data/verify/mapping/options.rb +17 -0
- data/verify/mapping/path.rb +40 -0
- data/verify/mapping/response_proxy.rb +50 -0
- data/verify/mapping/threaded.rb +25 -0
- data/verify/requests/helpers.rb +16 -0
- data/verify/requests/request.rb +73 -0
- data/verify/requests/response.rb +59 -0
- data/verify/requests/session.rb +54 -0
- data/verify/views/helpers.rb +1 -0
- data/verify/views/rendering.rb +34 -0
- data/verify/views/templates/foo.erb +0 -0
- data/verify/views/templates/moo.erb +0 -0
- data/verify/views/templates/moo.mab +0 -0
- metadata +439 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'erubis'
|
|
2
|
+
|
|
3
|
+
module Erubis # :nodoc:
|
|
4
|
+
|
|
5
|
+
# This is added to the Erubis Content class to allow the same helper methods
|
|
6
|
+
# to be used with both Markaby and Erubis.
|
|
7
|
+
class Context
|
|
8
|
+
include Waves::Helpers::UrlHelper
|
|
9
|
+
include Waves::Helpers::TagHelper
|
|
10
|
+
include Waves::Helpers::AssetHelper
|
|
11
|
+
include Waves::Helpers::NumberHelper
|
|
12
|
+
|
|
13
|
+
def <<(s)
|
|
14
|
+
eval("_buf", @binding).concat s # add to rendered output
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def capture
|
|
18
|
+
eval("_context.push(_buf); _buf = ''", @binding) #ignore output from that eval, will be added via "<<"
|
|
19
|
+
result = Erubis::Eruby.new(yield).result @binding
|
|
20
|
+
eval("_buf = _context.pop", @binding)
|
|
21
|
+
result
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def render(eruby)
|
|
25
|
+
unless @binding
|
|
26
|
+
@binding = binding
|
|
27
|
+
eval("_buf = ''; _context = []", @binding)
|
|
28
|
+
end
|
|
29
|
+
eruby.result @binding
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
module Waves
|
|
37
|
+
|
|
38
|
+
module Renderers
|
|
39
|
+
|
|
40
|
+
class Erubis
|
|
41
|
+
|
|
42
|
+
include Renderers::Mixin
|
|
43
|
+
|
|
44
|
+
extension :erb
|
|
45
|
+
|
|
46
|
+
def self.render( path, assigns )
|
|
47
|
+
eruby = ::Erubis::Eruby.new( template( path ) )
|
|
48
|
+
helper = helper( path )
|
|
49
|
+
context = ::Erubis::Context.new
|
|
50
|
+
context.meta_eval { include( helper ) ; }
|
|
51
|
+
context.instance_eval do
|
|
52
|
+
assigns.each do |key,val|
|
|
53
|
+
instance_variable_set("@#{key}",val)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
context.render(eruby)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'haml'
|
|
2
|
+
|
|
3
|
+
module Waves
|
|
4
|
+
|
|
5
|
+
module Renderers
|
|
6
|
+
|
|
7
|
+
class Scope
|
|
8
|
+
include Waves::Helpers::Common
|
|
9
|
+
include Waves::Helpers::Model
|
|
10
|
+
include Waves::Helpers::TagHelper
|
|
11
|
+
include Waves::Helpers::UrlHelper
|
|
12
|
+
include Waves::Helpers::View
|
|
13
|
+
|
|
14
|
+
def <<(s)
|
|
15
|
+
eval("@haml_buffer", @binding).push_text s # add to rendered output
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def capture(&block)
|
|
19
|
+
capture_haml(nil, &block)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Haml
|
|
25
|
+
|
|
26
|
+
include Renderers::Mixin
|
|
27
|
+
|
|
28
|
+
extension :haml
|
|
29
|
+
|
|
30
|
+
def self.render( path, assigns )
|
|
31
|
+
engine = ::Haml::Engine.new( template( path ) )
|
|
32
|
+
scope = Scope.new
|
|
33
|
+
helper = helper( path )
|
|
34
|
+
scope.meta_eval { include( helper ) }
|
|
35
|
+
scope.instance_eval do
|
|
36
|
+
assigns.each { |key,val| instance_variable_set("@#{key}",val) unless key == :request }
|
|
37
|
+
end
|
|
38
|
+
engine.render(scope, assigns)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'markaby'
|
|
2
|
+
|
|
3
|
+
::Markaby::Builder.set( :indent, 2 )
|
|
4
|
+
|
|
5
|
+
module Waves
|
|
6
|
+
|
|
7
|
+
module Renderers
|
|
8
|
+
|
|
9
|
+
class Markaby
|
|
10
|
+
|
|
11
|
+
include Renderers::Mixin
|
|
12
|
+
|
|
13
|
+
extension :mab
|
|
14
|
+
|
|
15
|
+
# capture needed here for content fragments, otherwise
|
|
16
|
+
# you'll just get the last tag's output ...
|
|
17
|
+
# def self.capture( template )
|
|
18
|
+
# "capture { #{template} }"
|
|
19
|
+
# end
|
|
20
|
+
|
|
21
|
+
def self.render( path, assigns )
|
|
22
|
+
builder = ::Markaby::Builder.new( assigns )
|
|
23
|
+
helper = helper( path )
|
|
24
|
+
builder.meta_eval { include( helper ) }
|
|
25
|
+
builder.instance_eval( template( path ) )
|
|
26
|
+
builder.to_s
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module Waves
|
|
2
|
+
|
|
3
|
+
module Renderers # :nodoc:
|
|
4
|
+
|
|
5
|
+
# The renderers mixin provides a number of methods to simplify writing new renderers.
|
|
6
|
+
# Just include this in your Renderer class and write your render method.
|
|
7
|
+
module Mixin
|
|
8
|
+
|
|
9
|
+
# Adds the following methods to the target class:
|
|
10
|
+
#
|
|
11
|
+
# - extension: allows you to set or get the extension used by this renderer.
|
|
12
|
+
#
|
|
13
|
+
# Renderers::Markaby.extension 'foo' # tell Waves to use .foo as Markaby extension
|
|
14
|
+
#
|
|
15
|
+
# - filename: generate a filename for the template based on a logical path.
|
|
16
|
+
# - template: read the template from the file corresponding to the given logical path.
|
|
17
|
+
# - helper: return a helper module that corresponds to the given logical path.
|
|
18
|
+
#
|
|
19
|
+
def self.included(target)
|
|
20
|
+
class << target
|
|
21
|
+
|
|
22
|
+
def extension(*args)
|
|
23
|
+
return @extension if args.length == 0
|
|
24
|
+
@extension = args.first
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def filename(path)
|
|
28
|
+
:templates / "#{path}.#{self.extension}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def render(path,args=nil)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def template( path )
|
|
35
|
+
File.read( filename( path ) )
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def helper( path )
|
|
39
|
+
Waves.application.helpers[
|
|
40
|
+
File.basename( File.dirname( path ) ).camel_case ]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# See the README for an overview.
|
|
2
|
+
module Waves
|
|
3
|
+
|
|
4
|
+
class << self
|
|
5
|
+
|
|
6
|
+
# Access the principal Waves application.
|
|
7
|
+
attr_reader :application
|
|
8
|
+
|
|
9
|
+
# Register a module as a Waves application.
|
|
10
|
+
def << ( app )
|
|
11
|
+
@application = app if Module === app
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def instance ; Waves::Application.instance ; end
|
|
15
|
+
|
|
16
|
+
def method_missing(name,*args,&block)
|
|
17
|
+
instance.send(name,*args,&block)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# An application in Waves is anything that provides access to the Waves
|
|
23
|
+
# runtime and the registered Waves applications. This includes both
|
|
24
|
+
# Waves::Server and Waves::Console. Waves::Application is *not* the actual
|
|
25
|
+
# application module(s) registered as Waves applications. To access the
|
|
26
|
+
# main Waves application, you can use +Waves+.+application+.
|
|
27
|
+
class Application
|
|
28
|
+
|
|
29
|
+
class << self; attr_accessor :instance; end
|
|
30
|
+
|
|
31
|
+
# Accessor for options passed to the application.
|
|
32
|
+
attr_reader :options
|
|
33
|
+
|
|
34
|
+
# Create a new Waves application instance.
|
|
35
|
+
def initialize( options={} )
|
|
36
|
+
@options = options
|
|
37
|
+
Dir.chdir options[:directory] if options[:directory]
|
|
38
|
+
Application.instance = self
|
|
39
|
+
Kernel.load( :lib / 'application.rb' ) if Waves.application.nil?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def synchronize( &block )
|
|
43
|
+
( @mutex ||= Mutex.new ).synchronize( &block )
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The 'mode' of the application determines which configuration it will run under.
|
|
47
|
+
def mode
|
|
48
|
+
@mode ||= @options[:mode]||:development
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Debug is true if debug is set to true in the current configuration.
|
|
52
|
+
def debug? ; config.debug ; end
|
|
53
|
+
|
|
54
|
+
# Access the current configuration. *Example:* +Waves::Server.config+
|
|
55
|
+
def config
|
|
56
|
+
Waves.application.configurations[ mode ]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Access the mappings for the application.
|
|
60
|
+
def mapping ; Waves.application.configurations[ :mapping ] ; end
|
|
61
|
+
|
|
62
|
+
# Reload the modules specified in the current configuration.
|
|
63
|
+
def reload ; config.reloadable.each { |mod| mod.reload } ; end
|
|
64
|
+
|
|
65
|
+
# Returns the cache set for the current configuration
|
|
66
|
+
def cache ; config.cache ; end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Waves
|
|
2
|
+
|
|
3
|
+
# Encapsulates the blackboard associated with a given request. The scope of the blackboard is
|
|
4
|
+
# the same as the request object it gets attached to.
|
|
5
|
+
#
|
|
6
|
+
# The Waves blackboard is a very simple shared storaged usable during the request processing.
|
|
7
|
+
# It is available within:
|
|
8
|
+
# - mappings
|
|
9
|
+
# - controllers
|
|
10
|
+
# - helpers
|
|
11
|
+
#
|
|
12
|
+
# Adding a value:
|
|
13
|
+
# blackboard.value1 = 1
|
|
14
|
+
# blackboard[:value2] = 2
|
|
15
|
+
#
|
|
16
|
+
# Retrieving values
|
|
17
|
+
# blackboard.value1
|
|
18
|
+
# blackboard[:value2]
|
|
19
|
+
#
|
|
20
|
+
# see also blackboard_verify.rb
|
|
21
|
+
|
|
22
|
+
class Blackboard
|
|
23
|
+
|
|
24
|
+
# Create a new blackboard object using the given request.
|
|
25
|
+
def initialize( request )
|
|
26
|
+
@request = request
|
|
27
|
+
@data = {}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Access a given data element of the blackboard using the given key.
|
|
31
|
+
def [](key)
|
|
32
|
+
@data[key]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Set the given data element of the blackboard using the given key and value.
|
|
36
|
+
def []=(key,val)
|
|
37
|
+
@data[key] = val
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def each(&block)
|
|
41
|
+
@data.each(&block)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# also allow things like
|
|
45
|
+
# blackboard.test1 instead of blackboard[:test1]
|
|
46
|
+
# blackboard.test1 = 2 instead of blackboard[:test1] = 2
|
|
47
|
+
def method_missing(name,*args)
|
|
48
|
+
if (name.to_s =~ /=$/)
|
|
49
|
+
self[name.to_s.gsub('=', '')] = args[0]
|
|
50
|
+
else
|
|
51
|
+
self[name.to_s]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
module Waves
|
|
2
|
+
|
|
3
|
+
# Waves configurations are Ruby code. This means you can use a Ruby expression as
|
|
4
|
+
# the value of a configuration attribute, extend and inherit your configurations, and
|
|
5
|
+
# add your own attributes. You can even use it as a repository
|
|
6
|
+
# for your application configuration.
|
|
7
|
+
#
|
|
8
|
+
# You can access configuration attributes using the attribute name as a method, with the value as the argument.
|
|
9
|
+
#
|
|
10
|
+
# == Example
|
|
11
|
+
#
|
|
12
|
+
# module Blog
|
|
13
|
+
# module Configurations
|
|
14
|
+
# class Development < Default
|
|
15
|
+
# host '127.0.0.1'
|
|
16
|
+
# port 2000
|
|
17
|
+
# reloadable [ Blog ]
|
|
18
|
+
# log :level => :debug
|
|
19
|
+
# application do
|
|
20
|
+
# use Rack::ShowExceptions
|
|
21
|
+
# run Waves::Dispatchers::Default.new
|
|
22
|
+
# end
|
|
23
|
+
# end
|
|
24
|
+
# end
|
|
25
|
+
# end
|
|
26
|
+
#
|
|
27
|
+
# There are three forms for accessing attributes:
|
|
28
|
+
#
|
|
29
|
+
# Waves.config.port # generic form - gets the value for current config
|
|
30
|
+
# Blog.configurations[:development].port # gets the value for a specified config
|
|
31
|
+
# Blog::Configurations::Development.port # Access a specific config constant directly
|
|
32
|
+
#
|
|
33
|
+
# Configuration data is inheritable, as shown in the example above. Typically, you
|
|
34
|
+
# would set data common to all configurations in the Default class, from which
|
|
35
|
+
# your variations inherit.
|
|
36
|
+
#
|
|
37
|
+
# You may define your own heritable attributes using the +attribute+ class method:
|
|
38
|
+
#
|
|
39
|
+
# class Default < Waves::Configurations::Default
|
|
40
|
+
# attribute 'theme' # define an attribute named "theme"
|
|
41
|
+
# theme 'ultra' # set an inheritable default
|
|
42
|
+
# end
|
|
43
|
+
#
|
|
44
|
+
# Certain attributes are reserved for internal use by Waves:
|
|
45
|
+
#
|
|
46
|
+
# - application: configure the application for use with Rack
|
|
47
|
+
# - database: initialization parameters needed by the ORM layer
|
|
48
|
+
# - reloadable: an array of module names to reload; see below for more
|
|
49
|
+
# - log: takes a hash of parameters; see below for more
|
|
50
|
+
# - host: the host to bind the server to (string)
|
|
51
|
+
# - port: the port for the server to listen on (number)
|
|
52
|
+
# - ports: used by the cluster:start task for clustering servers (array of numbers)
|
|
53
|
+
# - debug: true if running in "debug" mode, which automatically reloads code
|
|
54
|
+
#
|
|
55
|
+
# == Configuring The Rack Application
|
|
56
|
+
#
|
|
57
|
+
# One of the really nice features of Rack is the ability to install "middleware"
|
|
58
|
+
# components to optimize the way you handle requests. Waves exposes this ability
|
|
59
|
+
# directly to the application developer via the +application+ configuration method.
|
|
60
|
+
#
|
|
61
|
+
# *Example*
|
|
62
|
+
#
|
|
63
|
+
# # Typical debugging configuration
|
|
64
|
+
# application do
|
|
65
|
+
# use Rack::ShowExceptions
|
|
66
|
+
# run Waves::Dispatchers::Default.new
|
|
67
|
+
# end
|
|
68
|
+
#
|
|
69
|
+
# == Configuring Database Access
|
|
70
|
+
#
|
|
71
|
+
# The ORM layers provided with Waves use the +database+ attribute for connection initialization.
|
|
72
|
+
# Most ORMs take a hash for this purpose, with keys that may vary depending on the ORM and backend.
|
|
73
|
+
#
|
|
74
|
+
# # Sequel with a MySQL db
|
|
75
|
+
# database :host => 'localhost', :adapter => 'mysql', :database => 'blog',
|
|
76
|
+
# :user => 'root', :password => 'guess'
|
|
77
|
+
#
|
|
78
|
+
# # Sequel with an SQLite db
|
|
79
|
+
# database :adapter => 'sqlite', :database => 'blog'
|
|
80
|
+
#
|
|
81
|
+
# See the documentation for each ORM layer for details.
|
|
82
|
+
#
|
|
83
|
+
# == Configuring Code Reloading
|
|
84
|
+
#
|
|
85
|
+
# The +reloadable+ attribute takes an array of modules. Before every request, the default Waves
|
|
86
|
+
# dispatcher calls +reload+ on each listed module. The module should remove any reloadable constants
|
|
87
|
+
# currently defined in its namespace.
|
|
88
|
+
#
|
|
89
|
+
# In a Waves application built on the Default foundation, +reload+ functionality is provided
|
|
90
|
+
# by AutoCode for the Configurations, Controllers, Helpers, Models, and Views modules.
|
|
91
|
+
#
|
|
92
|
+
# Listing only your application module will work in most cases:
|
|
93
|
+
#
|
|
94
|
+
# reloadable [ Blog ]
|
|
95
|
+
#
|
|
96
|
+
# As an alternative, you could reload only some of the modules within your application:
|
|
97
|
+
#
|
|
98
|
+
# reloadable [ Blog::Models, Blog::Controllers ]
|
|
99
|
+
#
|
|
100
|
+
# == Configuring Logging
|
|
101
|
+
#
|
|
102
|
+
# The +log+ configuration attribute takes hash with these keys:
|
|
103
|
+
# - :level - The log filter level. Uses Ruby's built in Logger class.
|
|
104
|
+
# - :output - A filename or IO object. Should be a filename if running as a daemon.
|
|
105
|
+
#
|
|
106
|
+
# *Examples*
|
|
107
|
+
#
|
|
108
|
+
# log :level => :info, :output => $stderr
|
|
109
|
+
# log :level => :error, :output => 'log/blog.log'
|
|
110
|
+
#
|
|
111
|
+
|
|
112
|
+
module Configurations
|
|
113
|
+
|
|
114
|
+
class Base
|
|
115
|
+
# Set the given attribute with the given value. Typically, you wouldn't
|
|
116
|
+
# use this directly.
|
|
117
|
+
def self.[]=( name, val )
|
|
118
|
+
meta_def("_#{name}") { val }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Get the value of the given attribute. Typically, you wouldn't
|
|
122
|
+
# use this directly.
|
|
123
|
+
def self.[]( name ) ; send "_#{name}" ; end
|
|
124
|
+
|
|
125
|
+
# Define a new attribute. After calling this, you can get and set the value
|
|
126
|
+
# using the attribute name as the method
|
|
127
|
+
def self.attribute( name )
|
|
128
|
+
meta_def(name) do |*args|
|
|
129
|
+
raise ArgumentError.new('Too many arguments.') if args.length > 1
|
|
130
|
+
args.length == 1 ? self[ name ] = args.first : self[ name ]
|
|
131
|
+
end
|
|
132
|
+
self[ name ] = nil
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# The Default configuration defines sensible defaults for attributes required by Waves.
|
|
138
|
+
# debug true
|
|
139
|
+
# synchronize? true
|
|
140
|
+
# session :duration => 30.minutes, :path => '/tmp/sessions'
|
|
141
|
+
# log :level => :info, :output => $stderr
|
|
142
|
+
# reloadable []
|
|
143
|
+
class Default < Base
|
|
144
|
+
|
|
145
|
+
%w( host port ports log reloadable database session debug root synchronize? ).
|
|
146
|
+
each { |name| attribute(name) }
|
|
147
|
+
|
|
148
|
+
# Set the Rack handler, along with any specific options
|
|
149
|
+
# that need to be passed to the handler's #run method.
|
|
150
|
+
#
|
|
151
|
+
# When accessing the value
|
|
152
|
+
# (calling with no arguments), returns an array of the handler and options.
|
|
153
|
+
def self.handler(*args)
|
|
154
|
+
if args.length > 0
|
|
155
|
+
@rack_handler, @rack_handler_options = args
|
|
156
|
+
else
|
|
157
|
+
[ @rack_handler, @rack_handler_options ]
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Provides access to the Waves::MimeTypes class via the configuration. You
|
|
162
|
+
# can override #mime_types to return your own MIME types repository class.
|
|
163
|
+
def self.mime_types
|
|
164
|
+
Waves::MimeTypes
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Defines the application for use with Rack. Treat this method like an
|
|
168
|
+
# instance of Rack::Builder
|
|
169
|
+
def self.application( &block )
|
|
170
|
+
if block_given?
|
|
171
|
+
self['application'] = Rack::Builder.new( &block )
|
|
172
|
+
else
|
|
173
|
+
self['application']
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
debug true ; synchronize? true
|
|
178
|
+
session :duration => 30.minutes, :path => '/tmp/sessions'
|
|
179
|
+
log :level => :info, :output => $stderr
|
|
180
|
+
reloadable []
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
|