waves 0.7.3 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- 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/utilities/integer.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
# Added methods to Integer for commonly used "numeric phrases" like 6.days or 30.megabytes.
|
2
2
|
class Integer
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
3
|
+
def seconds ; self ; end
|
4
|
+
def minutes ; self * 60 ; end
|
5
|
+
def hours ; self * 60.minutes ; end
|
6
|
+
def days ; self * 24.hours ; end
|
7
|
+
def weeks ; self * 7.days ; end
|
8
|
+
def bytes ; self ; end
|
9
|
+
def kilobytes ; self * 1024 ; end
|
10
|
+
def megabytes ; self * 1024.kilobytes ; end
|
11
|
+
def gigabytes ; self * 1024.megabytes ; end
|
12
|
+
def terabytes ; self * 1024.gigabytes ; end
|
13
|
+
def petabytes ; self * 1024.terabytes ; end
|
14
|
+
def exabytes ; self * 1024.petabytes ; end
|
15
|
+
def zettabytes ; self * 1024.exabytes ; end
|
16
|
+
def yottabytes ; self * 1024.zettabytes ; end
|
17
|
+
end
|
data/lib/utilities/kernel.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
module Kernel
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
# Inspired by a question on comp.lang.ruby. Sort of like returning, except
|
20
|
-
# you don't need to pass in the returnee as an argument. The drawback is that,
|
21
|
-
# since this relies on instance_eval, you can't access in methods in the local
|
22
|
-
# scope. You can work around this by assigning values to variables, but in that
|
23
|
-
# case, you might be better off using returning.
|
24
|
-
#
|
25
|
-
# Our above example would look like this:
|
26
|
-
#
|
27
|
-
# with( Foo.new ) { bar = 'bar' }
|
28
|
-
#
|
29
|
-
def with( object, &block )
|
30
|
-
object.instance_eval(&block); object
|
31
|
-
end
|
32
|
-
|
2
|
+
#
|
3
|
+
# From Rails. This comes in handy when you want to return a value that you need to modify.
|
4
|
+
# So instead of the awkward:
|
5
|
+
#
|
6
|
+
# foo = Foo.new
|
7
|
+
# foo.bar = 'bar'
|
8
|
+
# foo
|
9
|
+
#
|
10
|
+
# You can just say
|
11
|
+
#
|
12
|
+
# returning Foo.new { |foo| foo.bar = 'bar' }
|
13
|
+
#
|
14
|
+
def returning( object, &block )
|
15
|
+
yield object; object
|
16
|
+
end
|
33
17
|
|
34
|
-
|
18
|
+
#
|
19
|
+
# Inspired by a question on comp.lang.ruby. Sort of like returning, except
|
20
|
+
# you don't need to pass in the returnee as an argument. The drawback is that,
|
21
|
+
# since this relies on instance_eval, you can't access in methods in the local
|
22
|
+
# scope. You can work around this by assigning values to variables, but in that
|
23
|
+
# case, you might be better off using returning.
|
24
|
+
#
|
25
|
+
# Our above example would look like this:
|
26
|
+
#
|
27
|
+
# with( Foo.new ) { bar = 'bar' }
|
28
|
+
#
|
29
|
+
def with( object, &block )
|
30
|
+
object.instance_eval(&block); object
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
data/lib/utilities/module.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
class Module
|
2
2
|
|
3
3
|
# This comes in handy when you are trying to do meta-programming with modules / classes
|
4
|
-
# that may be nested within other modules / classes. I think I've seen it defined in
|
4
|
+
# that may be nested within other modules / classes. I think I've seen it defined in
|
5
5
|
# facets, but I'm not relying on facets just for this one method.
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def basename
|
7
|
+
self.name.split('::').last || ''
|
8
|
+
end
|
9
|
+
|
10
|
+
# Just a convenience method for accessing a const within a Module
|
11
|
+
def []( cname )
|
12
|
+
const_get( cname.to_s.camel_case )
|
13
|
+
end
|
14
|
+
|
15
|
+
|
9
16
|
|
10
17
|
end
|
data/lib/utilities/object.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class Object
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
# This is an extremely powerful little function that will be built-in to Ruby 1.9.
|
3
|
+
# This version is from Mauricio Fernandez via ruby-talk. Works like instance_eval
|
4
|
+
# except that you can pass parameters to the block. This means you can define a block
|
5
|
+
# intended for use with instance_eval, pass it to another method, which can then
|
6
|
+
# invoke with parameters. This is used quite a bit by the Waves::Mapping code.
|
7
7
|
def instance_exec(*args, &block)
|
8
8
|
mname = "__instance_exec_#{Thread.current.object_id.abs}"
|
9
9
|
class << self; self end.class_eval{ define_method(mname, &block) }
|
data/lib/utilities/string.rb
CHANGED
@@ -1,41 +1,47 @@
|
|
1
1
|
# Waves extends String with a variety of methods for changing from singular to plural and back, and switching to different types of case and word separators. These methods are similar to those found in Rails and other frameworks, but some (all?) of the names are different. The names here were chosen for increased clarity and are hopefully easy to adjust to ...
|
2
|
-
#
|
3
|
-
# Notably, the inflector code here is not as comprehensive as the Rails code. This will be fixed in a future version of Waves.
|
4
2
|
|
5
3
|
class String
|
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
|
-
gsub(/(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
4
|
+
|
5
|
+
# Does a File.join on the two arguments joined by the /. Very handy
|
6
|
+
# for doing platform-safe paths without having to use File.join.
|
7
|
+
#
|
8
|
+
# I unfortunately don't recall where i first saw this ... see
|
9
|
+
# Symbol extension as well, allowing for :files / 'afilename.txt'
|
10
|
+
|
11
|
+
def / ( string )
|
12
|
+
File.join(self,string.to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def singular
|
16
|
+
Inflect::English.singular(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method(:singularize, :singular)
|
20
|
+
|
21
|
+
def plural
|
22
|
+
Inflect::English.plural(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method(:pluralize, :plural)
|
26
|
+
|
27
|
+
def lower_camel_case
|
28
|
+
gsub(/(_)(\w)/) { $2.upcase }
|
29
|
+
end
|
30
|
+
|
31
|
+
def camel_case
|
32
|
+
lower_camel_case.gsub(/^([a-z])/) { $1.upcase }
|
33
|
+
end
|
34
|
+
|
35
|
+
def snake_case
|
36
|
+
gsub(/\s+/,'').gsub(/([a-z\d])([A-Z])/){ "#{$1}_#{$2}"}.tr("-", "_").downcase
|
37
|
+
end
|
38
|
+
|
39
|
+
def title_case
|
40
|
+
gsub(/(^|\s)\s*([a-z])/) { $1 + $2.upcase }
|
41
|
+
end
|
42
|
+
|
43
|
+
def text
|
44
|
+
gsub(/[\_\-\.\:]/,' ')
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/utilities/symbol.rb
CHANGED
data/lib/views/base.rb
ADDED
data/lib/views/mixin.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
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
|
-
|
2
|
+
|
3
|
+
# Views in Waves are ultimately responsible for generating the response body. Views mirror controllers - both have full access to the request and response, and both may modify the response and even short-circuit the request processing and return a result by calling redirect or calling Response#finish.
|
4
|
+
#
|
5
|
+
# Views, like controllers, are classes with methods that are invoked by a mapping block (see Waves::Mapping). View instance methods take an assigns hash that are typically converted into instance variables accesible from within a template.
|
6
|
+
#
|
7
|
+
# Like controllers, a default implementation is provided by the +waves+ command when you first create your application. This default can be overridden to change the behaviors for all views, or you can explicitly define a View class to provide specific behavior for one view.
|
8
|
+
#
|
9
|
+
# The default implementation simply determines which template to render and renders it, returning the result as a string. This machinery is provided by the View mixin, so it is easy to create your own View implementations.
|
10
|
+
#
|
11
|
+
# = Templates
|
12
|
+
#
|
13
|
+
# Although you won't typically need to modify or define View classes, you will often create and modify templates. Templates can be evaluated using any registered Renderer. Two are presently packaged with Waves: Markaby and Erubis. Templates have access to the assigns hash passed to the view method as instance variables. These can be explicitly defined by the mapping file or whomever is invoking the view.
|
14
|
+
#
|
15
|
+
# *Example*
|
16
|
+
#
|
17
|
+
# # Find the story named 'home' and pass it as @story into the "story/show" template
|
18
|
+
# use( :story ) | controller { find( 'home' ) } | view { |x| show( :story => x ) }
|
19
|
+
#
|
20
|
+
# = Helpers
|
21
|
+
#
|
22
|
+
# Helper methods can be defined for any view template by simply defining them within the default Helper module in <tt>helpers/default.rb</tt> of the generated application. Helpers specific to a particular View class can be explicitly defined by creating a helper module that corresponds to the View class. For examples, for the +User+ View class, you would define a helper module in <tt>user.rb</tt> named +User+.
|
23
|
+
#
|
24
|
+
# The default helper class initially includes a wide-variety of helpers, including helpers for layouts, Textile formatting, rendering forms, and nested views, as well as helpers for accessing the request and response objects. More helpers will be added in future releases, but in many cases, there is no need to include all of them in your application.
|
25
|
+
#
|
26
|
+
# = Layouts
|
27
|
+
#
|
28
|
+
# Layouts are defined using the +Layout+ view class, and layout templates are placed in the +layout+ directory of the +templates+ directory. Layouts are explicitly set within a template using the +layout+ method.
|
29
|
+
#
|
30
|
+
# *Example*
|
31
|
+
#
|
32
|
+
# layout :default, :title => @story.title do
|
33
|
+
# h1 @story.title
|
34
|
+
# textile @story.content
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
#
|
38
|
+
# The layout method takes a name and an assigns hash that will be available within the layout template as instance variables. In this example, <tt>@title</tt> will be defined as <tt>@story.title</tt> within the layout template named 'default.'
|
39
|
+
#
|
40
|
+
# Any number of layouts may be included within a single view, and layouts may even be nested within layouts. This makes it possible to create large numbers of highly structured views that can be easily changed with minimal effort. For example, you might specify a layout associated with form elements. By incorporating this into your views as a +layout+ template, you can make changes across all your forms by changing this single template.
|
41
|
+
#
|
42
42
|
# = Nested Views
|
43
43
|
#
|
44
44
|
# It is easy to include one view inside another. A common use for this is to define one set of templates for reusable content 'fragments' (somewhat akin to partials in Rails) and another set that incorporate these fragments into specific layouts. Including a view from within another view is done, logically enough, using the +view+ method.
|
@@ -52,57 +52,59 @@ module Waves
|
|
52
52
|
#
|
53
53
|
# As always, the request and response objects, and a wide-variety of short-cut methods, are available within view templates via the Waves::ResponseMixin.
|
54
54
|
#
|
55
|
-
|
56
|
-
module Views
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
56
|
+
module Views
|
57
|
+
|
58
|
+
class NoTemplateError < Exception ; end
|
59
|
+
|
60
|
+
# A class method that returns the known Renderers, which is any module that is defined within Waves::Renderers and includes the Renderers::Mixin. You can define new Renderers simply be reopening Waves::Renderers and defining a module that mixes in Renderers::Mixin.
|
61
|
+
def Views.renderers
|
62
|
+
return [] if Renderers.constants.nil?
|
63
|
+
Renderers.constants.sort.inject([]) do |rx,cname|
|
64
|
+
( Module === (c=Renderers.const_get(cname)) &&
|
65
|
+
c < Renderers::Mixin ) ? ( rx << c ) : rx
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# The View mixin simply sets up the machinery for invoking a template, along with methods for accessing the request context and the standard interface for invoking a view method.
|
70
|
+
module Mixin
|
71
|
+
|
72
|
+
attr_reader :request
|
73
|
+
|
74
|
+
include Waves::ResponseMixin
|
75
|
+
|
76
|
+
def self.included( c )
|
77
|
+
def c.process( request, *args, &block )
|
78
|
+
self.new( request ).instance_exec( *args, &block )
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize( request )
|
83
|
+
@request = request
|
84
|
+
@layout = :default
|
85
|
+
end
|
86
|
+
|
87
|
+
# Return the first renderer for which a template file can be found.
|
88
|
+
# Uses Renderers::Mixin.filename to construct the filename for each renderer.
|
89
|
+
def renderer(path)
|
90
|
+
Views.renderers.find do |renderer|
|
91
|
+
File.exists?( renderer.filename( path ) )
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def render( path, context = {} )
|
96
|
+
context.merge!( :request => request )
|
97
|
+
template = renderer( path ) || renderer( :generic / File.basename(path) )
|
98
|
+
raise NoTemplateError.new( path ) if template.nil?
|
99
|
+
template.render( path, context )
|
100
|
+
end
|
101
|
+
|
102
|
+
def method_missing(name,*args)
|
103
|
+
render( "/#{self.class.basename.snake_case}/#{name}", *args )
|
104
|
+
end
|
68
105
|
|
69
|
-
|
70
|
-
module Mixin
|
71
|
-
|
72
|
-
attr_reader :request
|
73
|
-
|
74
|
-
include Waves::ResponseMixin
|
75
|
-
|
76
|
-
def self.included( c )
|
77
|
-
def c.process( request, *args, &block )
|
78
|
-
self.new( request ).instance_exec( *args, &block )
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def initialize( request )
|
83
|
-
@request = request
|
84
|
-
@layout = :default
|
85
|
-
end
|
86
|
-
|
87
|
-
def renderer(path)
|
88
|
-
Views.renderers.find do |renderer|
|
89
|
-
File.exists?( renderer.filename( path ) )
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def render( path, context = {} )
|
94
|
-
context.merge!( :request => request )
|
95
|
-
template = renderer( path ) || renderer( :generic / File.basename(path) )
|
96
|
-
raise NoTemplateError.new( path ) if template.nil?
|
97
|
-
template.render( path, context )
|
98
|
-
end
|
99
|
-
|
100
|
-
def method_missing(name,*args)
|
101
|
-
render( "/#{self.class.basename.snake_case}/#{name}", *args )
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
106
|
+
end
|
105
107
|
|
106
|
-
|
108
|
+
end
|
107
109
|
|
108
110
|
end
|