waves 0.7.3 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/app/Rakefile +11 -19
  2. data/app/bin/waves-console +3 -5
  3. data/app/bin/waves-server +3 -5
  4. data/app/configurations/development.rb.erb +19 -11
  5. data/app/configurations/mapping.rb.erb +4 -5
  6. data/app/configurations/production.rb.erb +18 -13
  7. data/app/{doc/EMTPY → controllers/.gitignore} +0 -0
  8. data/app/{public/css/EMPTY → doc/.gitignore} +0 -0
  9. data/app/{public/flash/EMPTY → helpers/.gitignore} +0 -0
  10. data/app/lib/application.rb.erb +4 -51
  11. data/app/{public/images/EMPTY → lib/tasks/.gitignore} +0 -0
  12. data/app/{public/javascript/EMPTY → log/.gitignore} +0 -0
  13. data/app/{tmp/sessions/EMPTY → models/.gitignore} +0 -0
  14. data/app/public/css/.gitignore +0 -0
  15. data/app/public/flash/.gitignore +0 -0
  16. data/app/public/images/.gitignore +0 -0
  17. data/app/public/javascript/.gitignore +0 -0
  18. data/app/schema/migrations/.gitignore +0 -0
  19. data/app/startup.rb +5 -0
  20. data/app/templates/layouts/default.mab +2 -2
  21. data/app/tmp/sessions/.gitignore +0 -0
  22. data/app/views/.gitignore +0 -0
  23. data/bin/waves +38 -27
  24. data/bin/waves-console +3 -25
  25. data/bin/waves-server +4 -45
  26. data/lib/commands/waves-console.rb +21 -0
  27. data/lib/commands/waves-server.rb +55 -0
  28. data/lib/controllers/base.rb +11 -0
  29. data/lib/controllers/mixin.rb +130 -102
  30. data/lib/dispatchers/base.rb +65 -50
  31. data/lib/dispatchers/default.rb +79 -52
  32. data/lib/foundations/default.rb +26 -0
  33. data/lib/foundations/simple.rb +30 -0
  34. data/lib/helpers/common.rb +60 -56
  35. data/lib/helpers/default.rb +13 -0
  36. data/lib/helpers/form.rb +39 -38
  37. data/lib/helpers/formatting.rb +11 -11
  38. data/lib/helpers/model.rb +12 -12
  39. data/lib/helpers/view.rb +13 -13
  40. data/lib/layers/default_errors.rb +29 -0
  41. data/lib/layers/mvc.rb +58 -0
  42. data/lib/layers/orm/active_record.rb +41 -0
  43. data/lib/layers/orm/active_record/migrations/empty.rb.erb +9 -0
  44. data/lib/layers/orm/active_record/tasks/schema.rb +30 -0
  45. data/lib/layers/orm/data_mapper.rb +42 -0
  46. data/lib/layers/orm/filebase.rb +22 -0
  47. data/lib/layers/orm/migration.rb +70 -0
  48. data/lib/layers/orm/sequel.rb +82 -0
  49. data/lib/layers/orm/sequel/migrations/empty.rb.erb +9 -0
  50. data/lib/layers/orm/sequel/tasks/schema.rb +24 -0
  51. data/lib/layers/simple.rb +39 -0
  52. data/lib/layers/simple_errors.rb +26 -0
  53. data/lib/mapping/mapping.rb +222 -120
  54. data/lib/mapping/pretty_urls.rb +42 -41
  55. data/lib/renderers/erubis.rb +54 -31
  56. data/lib/renderers/markaby.rb +28 -28
  57. data/lib/renderers/mixin.rb +49 -52
  58. data/lib/runtime/application.rb +66 -48
  59. data/lib/runtime/blackboard.rb +57 -0
  60. data/lib/runtime/configuration.rb +117 -101
  61. data/lib/runtime/console.rb +19 -20
  62. data/lib/runtime/debugger.rb +9 -0
  63. data/lib/runtime/logger.rb +43 -37
  64. data/lib/runtime/mime_types.rb +19 -19
  65. data/lib/runtime/request.rb +72 -46
  66. data/lib/runtime/response.rb +37 -37
  67. data/lib/runtime/response_mixin.rb +26 -23
  68. data/lib/runtime/response_proxy.rb +25 -24
  69. data/lib/runtime/server.rb +99 -80
  70. data/lib/runtime/session.rb +63 -53
  71. data/lib/tasks/cluster.rb +26 -0
  72. data/lib/tasks/gem.rb +31 -0
  73. data/lib/tasks/generate.rb +80 -0
  74. data/lib/utilities/hash.rb +22 -0
  75. data/lib/utilities/inflect.rb +194 -0
  76. data/lib/utilities/integer.rb +15 -12
  77. data/lib/utilities/kernel.rb +32 -32
  78. data/lib/utilities/module.rb +11 -4
  79. data/lib/utilities/object.rb +5 -5
  80. data/lib/utilities/proc.rb +10 -0
  81. data/lib/utilities/string.rb +44 -38
  82. data/lib/utilities/symbol.rb +4 -4
  83. data/lib/views/base.rb +9 -0
  84. data/lib/views/mixin.rb +91 -89
  85. data/lib/waves.rb +29 -9
  86. metadata +52 -26
  87. data/app/configurations/default.rb.erb +0 -8
  88. data/app/controllers/default.rb.erb +0 -29
  89. data/app/helpers/default.rb.erb +0 -13
  90. data/app/lib/startup.rb.erb +0 -3
  91. data/app/lib/tasks/cluster.rb +0 -24
  92. data/app/lib/tasks/generate.rb +0 -15
  93. data/app/lib/tasks/schema.rb +0 -29
  94. data/app/models/default.rb.erb +0 -13
  95. data/app/schema/migrations/templates/empty.rb.erb +0 -9
  96. data/app/views/default.rb.erb +0 -13
@@ -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
- name = '([\w\-\_\.\+\@]+)'; model = '([\w\-]+)'
27
-
25
+
26
+ name = '([\w\-\_\.\+\@]+)'; model = '([\w\-]+)'
27
+
28
28
  # get all resources for the given model
29
- path %r{^/#{model}/?$} do | model |
30
- use( model.singular ) | controller { all } | view { |data| list( model => data ) }
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
- use(model) | controller { find( name ) } |
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
- use(model) | controller { find( name ) } |
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 using the POST variables
55
- # POST /resource/name # => update the given resource using the POST variables
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
- name = '([\w\-\_\.\+\@]+)'; model = '([\w\-]+)'
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
- use( model.singular )
71
- instance = controller { create }
72
- redirect( "/#{model.singular}/#{instance.name}/editor" )
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
- # add / update the given resource for the given model
76
- path %r{^/#{model}/#{name}/?$}, :method => :post do | model, name |
77
- use(model) | controller { update( name ) }; redirect( url )
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
- use( model ) | controller { delete( name ) }
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
@@ -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
- def <<(s) ; s ; end
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
- module Renderers
16
-
17
- class Erubis
18
-
19
- include Renderers::Mixin
20
-
21
- extension :erb
22
-
23
- def self.render( path, assigns )
24
- eruby = ::Erubis::Eruby.new( template( path ) )
25
- helper = helper( path )
26
- context = ::Erubis::Context.new
27
- context.meta_eval { include( helper ) ; }
28
- context.instance_eval do
29
- assigns.each do |key,val|
30
- instance_variable_set("@#{key}",val)
31
- end
32
- end
33
- eruby.evaluate( context )
34
- end
35
-
36
- end
37
-
38
- end
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
@@ -3,31 +3,31 @@ require 'markaby'
3
3
  ::Markaby::Builder.set( :indent, 2 )
4
4
 
5
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
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
@@ -1,53 +1,50 @@
1
1
  module Waves
2
-
3
- module Renderers
4
-
5
- extend Autoload
6
- autoload :renderers
7
-
8
- # The renderers mixin provides a number of methods to simplify writing new renderers.
9
- # Just include this in your Renderer class and write your render method.
10
- module Mixin
11
-
12
- # Adds the following methods to the target class:
13
- #
14
- # - extension: allows you to set or get the extension used by this renderer.
15
- #
16
- # Renderers::Markaby.extension 'foo' # tell Waves to use .foo as Markaby extension
17
- #
18
- # - filename: generate a filename for the template based on a logical path.
19
- # - template: read the template from the file corresponding to the given logical path.
20
- # - helper: return a helper module that corresponds to the given logical path.
21
- #
22
- def self.included(target)
23
- class << target
24
-
25
- def extension(*args)
26
- return @extension if args.length == 0
27
- @extension = args.first
28
- end
29
-
30
- def filename(path)
31
- :templates / "#{path}.#{self.extension}"
32
- end
33
-
34
- def render(path,args=nil)
35
- end
36
-
37
- def template( path )
38
- File.read( filename( path ) )
39
- end
40
-
41
- def helper( path )
42
- Waves.application.helpers[
43
- File.basename( File.dirname( path ) ).camel_case ]
44
- end
45
- end
46
- end
47
-
48
-
49
- end
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
@@ -1,53 +1,71 @@
1
1
  # See the README for an overview.
2
2
  module Waves
3
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
- # 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
- end
17
-
18
- # An application in Waves is anything that provides access to the Waves
19
- # runtime and the registered Waves applications. This includes both
20
- # Waves::Server and Waves::Console. Waves::Application is *not* the actual
21
- # application module(s) registered as Waves applications. To access the
22
- # main Waves application, you can use +Waves+.+application+.
23
- class Application
24
-
25
- # Accessor for options passed to the application. Valid options include
26
- attr_reader :options
27
-
28
- # Create a new Waves application instance.
29
- def initialize( options={} )
30
- @options = options
31
- Dir.chdir options[:directory] if options[:directory]
32
- end
33
-
34
- # The 'mode' of the application determines which configuration it will run under.
35
- def mode ; @mode ||= @options[:mode]||:development ; end
36
-
37
- # Debug is true if debug is set to true in the current configuration.
38
- def debug? ; config.debug ; end
39
-
40
- # Access the current configuration. *Example:* +Waves::Server.config+
41
- def config ; Waves.application.configurations[ mode ] ; end
42
-
43
- # Access the mappings for the application.
44
- def mapping ; Waves.application.configurations[ :mapping ] ; end
45
-
46
- # Reload the modules specified in the current configuration.
47
- def reload ; config.reloadable.each { |mod| mod.reload } ; end
48
-
49
- # Returns the cache set for the current configuration
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
- end
69
+ end
52
70
 
53
- end
71
+ end