waves 0.7.3 → 0.7.5
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 +11 -19
- data/app/bin/waves-console +3 -5
- data/app/bin/waves-server +3 -5
- data/app/configurations/development.rb.erb +19 -11
- data/app/configurations/mapping.rb.erb +4 -5
- data/app/configurations/production.rb.erb +18 -13
- data/app/{doc/EMTPY → controllers/.gitignore} +0 -0
- data/app/{public/css/EMPTY → doc/.gitignore} +0 -0
- data/app/{public/flash/EMPTY → helpers/.gitignore} +0 -0
- data/app/lib/application.rb.erb +4 -51
- data/app/{public/images/EMPTY → lib/tasks/.gitignore} +0 -0
- data/app/{public/javascript/EMPTY → log/.gitignore} +0 -0
- data/app/{tmp/sessions/EMPTY → 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/layouts/default.mab +2 -2
- data/app/tmp/sessions/.gitignore +0 -0
- data/app/views/.gitignore +0 -0
- data/bin/waves +38 -27
- data/bin/waves-console +3 -25
- data/bin/waves-server +4 -45
- 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 +130 -102
- data/lib/dispatchers/base.rb +65 -50
- data/lib/dispatchers/default.rb +79 -52
- data/lib/foundations/default.rb +26 -0
- data/lib/foundations/simple.rb +30 -0
- data/lib/helpers/common.rb +60 -56
- data/lib/helpers/default.rb +13 -0
- data/lib/helpers/form.rb +39 -38
- data/lib/helpers/formatting.rb +11 -11
- data/lib/helpers/model.rb +12 -12
- data/lib/helpers/view.rb +13 -13
- data/lib/layers/default_errors.rb +29 -0
- data/lib/layers/mvc.rb +58 -0
- data/lib/layers/orm/active_record.rb +41 -0
- data/lib/layers/orm/active_record/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/active_record/tasks/schema.rb +30 -0
- data/lib/layers/orm/data_mapper.rb +42 -0
- data/lib/layers/orm/filebase.rb +22 -0
- data/lib/layers/orm/migration.rb +70 -0
- data/lib/layers/orm/sequel.rb +82 -0
- data/lib/layers/orm/sequel/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/sequel/tasks/schema.rb +24 -0
- data/lib/layers/simple.rb +39 -0
- data/lib/layers/simple_errors.rb +26 -0
- data/lib/mapping/mapping.rb +222 -120
- data/lib/mapping/pretty_urls.rb +42 -41
- data/lib/renderers/erubis.rb +54 -31
- data/lib/renderers/markaby.rb +28 -28
- data/lib/renderers/mixin.rb +49 -52
- data/lib/runtime/application.rb +66 -48
- data/lib/runtime/blackboard.rb +57 -0
- data/lib/runtime/configuration.rb +117 -101
- data/lib/runtime/console.rb +19 -20
- data/lib/runtime/debugger.rb +9 -0
- data/lib/runtime/logger.rb +43 -37
- data/lib/runtime/mime_types.rb +19 -19
- data/lib/runtime/request.rb +72 -46
- data/lib/runtime/response.rb +37 -37
- data/lib/runtime/response_mixin.rb +26 -23
- data/lib/runtime/response_proxy.rb +25 -24
- data/lib/runtime/server.rb +99 -80
- data/lib/runtime/session.rb +63 -53
- 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 +22 -0
- data/lib/utilities/inflect.rb +194 -0
- data/lib/utilities/integer.rb +15 -12
- data/lib/utilities/kernel.rb +32 -32
- data/lib/utilities/module.rb +11 -4
- data/lib/utilities/object.rb +5 -5
- data/lib/utilities/proc.rb +10 -0
- data/lib/utilities/string.rb +44 -38
- data/lib/utilities/symbol.rb +4 -4
- data/lib/views/base.rb +9 -0
- data/lib/views/mixin.rb +91 -89
- data/lib/waves.rb +29 -9
- metadata +52 -26
- data/app/configurations/default.rb.erb +0 -8
- data/app/controllers/default.rb.erb +0 -29
- data/app/helpers/default.rb.erb +0 -13
- data/app/lib/startup.rb.erb +0 -3
- data/app/lib/tasks/cluster.rb +0 -24
- data/app/lib/tasks/generate.rb +0 -15
- data/app/lib/tasks/schema.rb +0 -29
- data/app/models/default.rb.erb +0 -13
- data/app/schema/migrations/templates/empty.rb.erb +0 -9
- data/app/views/default.rb.erb +0 -13
data/lib/mapping/pretty_urls.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Waves
|
2
2
|
module Mapping
|
3
|
-
|
3
|
+
|
4
4
|
# A set of pre-packed mapping rules for dealing with pretty URLs (that use names instead
|
5
5
|
# of numbers to identify resources). There are two modules.
|
6
6
|
# - GetRules, which defines all the GET methods for dealing with named resources
|
7
7
|
# - RestRules, which defines add, update, and delete rules using a REST style interface
|
8
8
|
#
|
9
9
|
module PrettyUrls
|
10
|
-
|
10
|
+
|
11
11
|
#
|
12
12
|
# GetRules defines the following URL conventions:
|
13
13
|
#
|
@@ -16,78 +16,79 @@ module Waves
|
|
16
16
|
# /resource/name/editor # => display an edit page for the given resource
|
17
17
|
#
|
18
18
|
module GetRules
|
19
|
-
|
19
|
+
|
20
20
|
def self.included(target)
|
21
|
-
|
21
|
+
|
22
22
|
target.module_eval do
|
23
|
-
|
23
|
+
|
24
24
|
extend Waves::Mapping
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
|
26
|
+
name = '([\w\-\_\.\+\@]+)'; model = '([\w\-]+)'
|
27
|
+
|
28
28
|
# get all resources for the given model
|
29
|
-
path %r{^/#{model}/?$} do | model |
|
30
|
-
|
29
|
+
path %r{^/#{model}/?$}, :method => :get do | model |
|
30
|
+
resource( model.singular ) { controller { all } | view { |data| list( model => data ) } }
|
31
31
|
end
|
32
32
|
|
33
33
|
# get the given resource for the given model
|
34
|
-
path %r{^/#{model}/#{name}/?$} do | model, name |
|
35
|
-
|
36
|
-
view { |data| show( model => data ) }
|
34
|
+
path %r{^/#{model}/#{name}/?$}, :method => :get do | model, name |
|
35
|
+
resource( model ) { controller { find( name ) } | view { |data| show( model => data ) } }
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
# display an editor for the given resource / model
|
40
|
-
path %r{^/#{model}/#{name}/editor/?$} do | model, name |
|
41
|
-
|
42
|
-
view { |data| editor( model => data ) }
|
39
|
+
path %r{^/#{model}/#{name}/editor/?$}, :method => :get do | model, name |
|
40
|
+
resource( model ) { controller { find( name ) } | view { |data| editor( model => data ) } }
|
43
41
|
end
|
44
|
-
|
42
|
+
|
45
43
|
end
|
46
|
-
|
44
|
+
|
47
45
|
end
|
48
|
-
|
46
|
+
|
49
47
|
end
|
50
|
-
|
48
|
+
|
51
49
|
#
|
52
50
|
# RestRules defines the following URL conventions:
|
53
51
|
#
|
54
|
-
# POST /resources # => add a new resource
|
55
|
-
#
|
52
|
+
# POST /resources # => add a new resource
|
53
|
+
# PUT /resource/name # => update the given resource
|
56
54
|
# DELETE /resource/name # => delete the given resource
|
57
55
|
#
|
58
56
|
module RestRules
|
59
|
-
|
57
|
+
|
60
58
|
def self.included(target)
|
61
|
-
|
59
|
+
|
62
60
|
target.module_eval do
|
63
|
-
|
61
|
+
|
64
62
|
extend Waves::Mapping
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
|
64
|
+
name = '([\w\-\_\.\+\@]+)'; model = '([\w\-]+)'
|
65
|
+
|
68
66
|
# create a new resource for the given model
|
69
67
|
path %r{^/#{model}/?$}, :method => :post do | model |
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
resource( model.singular ) do
|
69
|
+
controller do
|
70
|
+
instance = create
|
71
|
+
redirect( "/#{model_name}/#{instance.name}/editor" )
|
72
|
+
end
|
73
|
+
end
|
73
74
|
end
|
74
75
|
|
75
|
-
#
|
76
|
-
path %r{^/#{model}/#{name}/?$}, :method => :
|
77
|
-
|
76
|
+
# update the given resource for the given model
|
77
|
+
path %r{^/#{model}/#{name}/?$}, :method => :put do | model, name |
|
78
|
+
resource( model ) { controller { update( name ); redirect( url ) } }
|
78
79
|
end
|
79
|
-
|
80
|
+
|
80
81
|
# delete the given resource for the given model
|
81
82
|
path %r{^/#{model}/#{name}/?$}, :method => :delete do | model, name |
|
82
|
-
|
83
|
+
resource( model ) { controller { delete( name ) } }
|
83
84
|
end
|
84
|
-
|
85
|
+
|
85
86
|
end
|
86
|
-
|
87
|
+
|
87
88
|
end
|
88
|
-
|
89
|
+
|
89
90
|
end
|
90
|
-
|
91
|
+
|
91
92
|
end
|
92
93
|
|
93
94
|
end
|
data/lib/renderers/erubis.rb
CHANGED
@@ -1,40 +1,63 @@
|
|
1
1
|
require 'erubis'
|
2
2
|
|
3
|
-
module Erubis
|
4
|
-
|
3
|
+
module Erubis # :nodoc:
|
4
|
+
|
5
5
|
# This is added to the Erubis Content class to allow the same helper methods
|
6
6
|
# to be used with both Markaby and Erubis.
|
7
7
|
class Context
|
8
|
-
|
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
|
+
|
9
32
|
end
|
10
|
-
|
33
|
+
|
11
34
|
end
|
12
|
-
|
35
|
+
|
13
36
|
module Waves
|
14
37
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
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
|
data/lib/renderers/markaby.rb
CHANGED
@@ -3,31 +3,31 @@ require 'markaby'
|
|
3
3
|
::Markaby::Builder.set( :indent, 2 )
|
4
4
|
|
5
5
|
module Waves
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
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
|
data/lib/renderers/mixin.rb
CHANGED
@@ -1,53 +1,50 @@
|
|
1
1
|
module Waves
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
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
|
data/lib/runtime/application.rb
CHANGED
@@ -1,53 +1,71 @@
|
|
1
1
|
# See the README for an overview.
|
2
2
|
module Waves
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Access the principal Waves application.
|
7
|
+
attr_reader :application
|
8
|
+
|
9
|
+
# Register a module as a Waves application.
|
10
|
+
# Also, initialize the database connection if necessary.
|
11
|
+
def << ( app )
|
12
|
+
@application = app if Module === app
|
13
|
+
# app.database if app.respond_to? 'database'
|
14
|
+
end
|
15
|
+
|
16
|
+
def instance ; Waves::Application.instance ; end
|
17
|
+
|
18
|
+
def method_missing(name,*args,&block)
|
19
|
+
instance.send(name,*args,&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
# An application in Waves is anything that provides access to the Waves
|
25
|
+
# runtime and the registered Waves applications. This includes both
|
26
|
+
# Waves::Server and Waves::Console. Waves::Application is *not* the actual
|
27
|
+
# application module(s) registered as Waves applications. To access the
|
28
|
+
# main Waves application, you can use +Waves+.+application+.
|
29
|
+
class Application
|
30
|
+
|
31
|
+
class << self; attr_accessor :instance; end
|
32
|
+
|
33
|
+
# Accessor for options passed to the application.
|
34
|
+
attr_reader :options
|
35
|
+
|
36
|
+
# Create a new Waves application instance.
|
37
|
+
def initialize( options={} )
|
38
|
+
@options = options
|
39
|
+
Dir.chdir options[:directory] if options[:directory]
|
40
|
+
Application.instance = self
|
41
|
+
Kernel.load( :lib / 'application.rb' ) if Waves.application.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def synchronize( &block )
|
45
|
+
( @mutex ||= Mutex.new ).synchronize( &block )
|
46
|
+
end
|
47
|
+
|
48
|
+
# The 'mode' of the application determines which configuration it will run under.
|
49
|
+
def mode
|
50
|
+
@mode ||= @options[:mode]||:development
|
51
|
+
end
|
52
|
+
|
53
|
+
# Debug is true if debug is set to true in the current configuration.
|
54
|
+
def debug? ; config.debug ; end
|
55
|
+
|
56
|
+
# Access the current configuration. *Example:* +Waves::Server.config+
|
57
|
+
def config
|
58
|
+
Waves.application.configurations[ mode ]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Access the mappings for the application.
|
62
|
+
def mapping ; Waves.application.configurations[ :mapping ] ; end
|
63
|
+
|
64
|
+
# Reload the modules specified in the current configuration.
|
65
|
+
def reload ; config.reloadable.each { |mod| mod.reload } ; end
|
66
|
+
|
67
|
+
# Returns the cache set for the current configuration
|
50
68
|
def cache ; config.cache ; end
|
51
|
-
|
69
|
+
end
|
52
70
|
|
53
|
-
end
|
71
|
+
end
|