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
data/app/Rakefile CHANGED
@@ -1,22 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
- if File.exist?(waves_src = File.join(File.dirname(__FILE__), 'waves'))
3
- $:.unshift(File.join(waves_src, 'lib'))
4
- end
2
+ #
3
+ # Warning: This file is clobbered when you update your
4
+ # application with the waves script. Accordingly, you may
5
+ # wish to keep your tasks in .rb or .rake files in lib/tasks
6
+ require 'startup'
7
+ Waves::Console.load(:mode => ENV['mode'])
5
8
 
6
- begin
7
- require 'waves'
8
- Waves::Console.load
9
- %w( schema cluster generate ).each { |task| require "lib/tasks/#{task}.rb" }
10
- rescue LoadError
11
- puts "Can't find waves gem or ./waves/lib directory. try rake symlink waves=/path/to/waves/"
12
- end
9
+ # load tasks from waves framework
10
+ %w( cluster generate gem ).each { |task| require "tasks/#{task}.rb" }
11
+
12
+ # load tasks from this app's lib/tasks
13
+ Dir["lib/tasks/*.{rb,rake}"].each { |task| require task }
13
14
 
14
- desc "Create lib and bin symlinks using waves=<path>"
15
- task :symlink do
16
- waves = ENV['waves']
17
- system "mkdir waves"
18
- libdir = File.join(waves, 'lib')
19
- bindir = File.join(waves, 'bin')
20
- system(cmd = "ln -s #{libdir} waves/") && puts(cmd)
21
- system(cmd = "ln -s #{bindir} waves/") && puts(cmd)
22
- end
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- if File.exist?(waves_src = File.join(File.dirname(__FILE__), '..', 'waves'))
3
- $:.unshift(File.join(waves_src, 'lib'))
4
- end
5
-
6
- load File.join(waves_src, 'bin', 'waves-console')
2
+ require 'rubygems'
3
+ require 'startup'
4
+ require 'commands/waves-console'
data/app/bin/waves-server CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- if File.exist?(waves_src = File.join(File.dirname(__FILE__), '..', 'waves'))
3
- $:.unshift(File.join(waves_src, 'lib'))
4
- end
5
-
6
- load File.join(waves_src, 'bin', 'waves-server')
2
+ require 'rubygems'
3
+ require 'startup'
4
+ require 'commands/waves-server'
@@ -1,22 +1,30 @@
1
- module <%= name %>
1
+ module <%= @name %>
2
+
2
3
  module Configurations
4
+
3
5
  class Development < Default
4
-
6
+
7
+ database :adapter => 'sqlite', :database => '<%= @name.downcase %>'
8
+
9
+ reloadable [ <%= @name %> ]
10
+
11
+ log :level => :debug
12
+
5
13
  host '127.0.0.1'
6
14
 
7
15
  port 3000
8
16
 
9
- reloadable [ <%= name %> ]
10
-
11
- log :level => :debug
17
+ handler ::Rack::Handler::Mongrel, :Host => host, :Port => port
18
+ # handler ::Rack::Handler::WEBrick, :BindAddress => host, :Port => port
19
+ # handler ::Rack::Handler::Thin, :Host => host, :Port => port
12
20
 
13
21
  application do
14
- use Rack::ShowExceptions
15
- run Waves::Dispatchers::Default.new
16
- end
17
-
22
+ use ::Rack::ShowExceptions
23
+ run ::Waves::Dispatchers::Default.new
24
+ end
25
+
18
26
  end
19
- end
20
- end
21
27
 
28
+ end
22
29
 
30
+ end
@@ -1,9 +1,8 @@
1
- module <%= name %>
2
-
1
+ module <%= @name %>
2
+
3
3
  module Configurations
4
-
4
+
5
5
  module Mapping
6
- extend Waves::Mapping
7
6
  # your custom rules go here
8
7
  include Waves::Mapping::PrettyUrls::RestRules
9
8
  include Waves::Mapping::PrettyUrls::GetRules
@@ -11,4 +10,4 @@ module <%= name %>
11
10
 
12
11
  end
13
12
 
14
- end
13
+ end
@@ -1,25 +1,30 @@
1
- module <%= name %>
1
+ module <%= @name %>
2
2
 
3
3
  module Configurations
4
-
4
+
5
5
  class Production < Default
6
-
6
+
7
+ database :host => 'localhost', :adapter => 'mysql', :database => '<%= @name.downcase %>',
8
+ :user => 'root', :password => ''
9
+
10
+ reloadable []
11
+
12
+ log :level => :error,
13
+ :output => ( :log / "waves.#{$$}" ),
14
+ :rotation => :weekly
15
+
7
16
  host '0.0.0.0'
8
17
 
9
18
  port 80
10
19
 
11
- reloadable []
12
-
13
- log :level => :error,
14
- :output => ( :log / "waves.#{$$}" ),
15
- :rotation => :weekly
20
+ handler ::Rack::Handler::Mongrel, :Host => host, :Port => port
21
+ # handler ::Rack::Handler::WEBrick, :BindAddress => host, :Port => port
22
+ # handler ::Rack::Handler::Thin, :Host => host, :Port => port
16
23
 
17
24
  application do
18
- run Waves::Dispatchers::Default.new
19
- end
20
-
21
- end
25
+ run ::Waves::Dispatchers::Default.new
26
+ end
22
27
 
28
+ end
23
29
  end
24
-
25
30
  end
File without changes
File without changes
File without changes
@@ -1,52 +1,5 @@
1
- require 'sequel'
2
- module <%= name %>
3
-
4
- extend Autocreate; extend Autoload; extend Reloadable
5
- autoload true; directories :lib
6
-
7
- [ :Configurations, :Models, :Views, :Controllers, :Helpers ].each do | name |
8
- autocreate( name, Module.new ) do
9
-
10
- # dynamically access module constants
11
- def self.[]( cname )
12
- eval("#{name}::#{cname.to_s.camel_case}")
13
- end
14
-
15
- # first try to load and only create if that fails
16
- # which means install autoload *after* autocreate
17
- extend Autocreate; extend Autoload
18
-
19
- # autoload any files in appropriately named directories
20
- # exampe: models/blog.rb for Blog
21
- autoload true; directories name.to_s.snake_case
22
-
23
- # autocreate declarations ...
24
- case name
25
- # don't autocreate configs
26
- when :Configurations then nil
27
- # set the dataset for Models
28
- when :Models
29
- autocreate true, eval("<%= name %>::Models::Default") do
30
- set_dataset <%= name %>.database[ basename.snake_case.plural.intern ]
31
- end
32
- # everything else just use the exemplar
33
- else
34
- autocreate true, eval("<%= name %>::#{name}::Default")
35
- end
36
-
37
- end
38
-
39
- end
40
-
41
- # accessor methods for modules and other key application objects ...
42
- class << self
43
- def config ; Waves::Server.config rescue nil || Waves::Console.config ; end
44
- def database ; @database ||= Sequel.open( config.database ) ; end
45
- def configurations ; <%= name %>::Configurations ; end
46
- def controllers ; <%= name %>::Controllers ; end
47
- def models ; <%= name %>::Models ; end
48
- def helpers ; <%= name %>::Helpers ; end
49
- def views ; <%= name %>::Views ; end
50
- end
51
-
1
+ require 'layers/orm/sequel'
2
+ module <%= @name %>
3
+ include Waves::Foundations::Default
4
+ include Waves::Layers::ORM::Sequel
52
5
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/app/startup.rb ADDED
@@ -0,0 +1,5 @@
1
+ lambda {
2
+ waves = ( ( WAVES if defined? WAVES ) || ENV['WAVES'] || File.join(File.dirname(__FILE__), 'waves') )
3
+ $:.unshift(File.join( waves, "lib" )) if File.exist? waves
4
+ }.call
5
+ require 'waves'
@@ -5,10 +5,10 @@ html do
5
5
  head do
6
6
  title @title
7
7
  end
8
-
8
+
9
9
  body do
10
10
  layout_content
11
11
  end
12
12
 
13
13
  end
14
-
14
+
File without changes
File without changes
data/bin/waves CHANGED
@@ -1,38 +1,49 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- unless ARGV.length == 1
4
- $stderr.puts "Usage: waves {name}"
5
- exit 1
2
+ require 'rubygems'
3
+ require 'choice'
4
+ require 'rakegen'
5
+
6
+ # if we're in the waves source, prepend it to the load path
7
+ waves_lib = File.expand_path( "#{File.dirname(__FILE__)}/../../waves/lib" )
8
+ $:.unshift waves_lib if File.exist?(waves_lib)
9
+ require 'waves'
10
+
11
+ begin
12
+ require 'utilities/string'
13
+ rescue LoadError
14
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'utilities', 'string')
6
15
  end
7
16
 
8
- require 'rubygems'
9
- require 'erubis'
10
- require 'extensions/all'
11
- require File.join(File.dirname(__FILE__), '..', 'lib', 'utilities', 'string')
17
+ Choice.options do
18
+ banner 'Usage: waves path/to/app [-h]'
19
+ option :help do
20
+ long '--help'
21
+ desc 'Show this message'
22
+ end
23
+
24
+ end
12
25
 
13
- puts "** Creating new Waves application ..."
14
26
  app_path = ARGV[0]
15
27
  app_name = File.basename(app_path)
16
- template = File.join( File.dirname(__FILE__),'..','app')
17
- system "cp -R #{template} #{app_path}"
18
-
19
- # get rid of placeholder files left over from gem install
20
- Dir["#{app_path}/**/EMPTY"].each { |path| system "rm #{path}" }
21
-
22
- # next, process all template files ...
23
- Dir["#{app_path}/**/*.erb"].each do |path|
24
- unless path =~ %r{^#{app_path}/(schema/migrations/templates|templates)}
25
- name = app_name.camel_case
26
- File.write( path.gsub(/\.erb$/,''),
27
- Erubis::Eruby.new( File.read( path ) ).result( binding ) )
28
- system "rm #{path}"
29
- end
28
+ if app_name =~ /[^\w\d_]/
29
+ raise ArgumentError, <<-TEXT
30
+ Unusable name: \"#{app_name}\"
31
+ Application names may contain only letters, numbers, and underscores."
32
+ TEXT
33
+ end
34
+
35
+ template = "#{WAVES}/app"
36
+
37
+ generator = Rakegen.new("waves:app") do |gen|
38
+ gen.source = template
39
+ gen.target = app_path
40
+ gen.template_assigns = {:name => app_name.camel_case}
41
+ gen.executables = %w{ bin/waves-console bin/waves-server}
30
42
  end
31
43
 
32
- # make the scripts executable
33
- system "chmod ug+x #{app_path}/bin/waves-*"
44
+ puts "** Creating new Waves application ..."
34
45
 
35
- # finally, change the lib/application.rb file
36
- system "mv #{app_path}/lib/application.rb #{app_path}/lib/#{app_name}.rb"
46
+ Rake::Task["waves:app"].invoke
37
47
 
38
48
  puts "** Application created!"
49
+
data/bin/waves-console CHANGED
@@ -1,26 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'waves'
3
- require 'choice'
4
-
5
- Choice.options do
6
- header 'Run a waves application server.'
7
- header ''
8
- option :mode do
9
- short '-c'
10
- long '--config=CONFIG'
11
- desc 'Configuration to use.'
12
- desc 'Defaults to development.'
13
- cast Symbol
14
- end
15
- separator ''
16
- option :directory do
17
- short '-D'
18
- long '--dir=DIR'
19
- desc 'Directory containing the application.'
20
- desc 'Defaults to the current directory.'
21
- end
22
- separator ''
23
- end
24
-
25
- Waves::Console.load( Choice.choices )
26
- require 'irb'; IRB.start
2
+ require 'rubygems'
3
+ require 'startup'
4
+ require 'commands/waves-console'
data/bin/waves-server CHANGED
@@ -1,45 +1,4 @@
1
- require 'waves'
2
- require 'choice'
3
-
4
- Choice.options do
5
- header 'Run a waves application server.'
6
- header ''
7
- option :port do
8
- short '-p'
9
- long '--port=PORT'
10
- desc 'Port to listen on.'
11
- desc 'Defaults to value given in configuration.'
12
- cast Integer
13
- end
14
- separator ''
15
- option :host do
16
- short '-h'
17
- long '--host=HOST'
18
- desc 'Host or IP address of the host to bind.'
19
- desc 'Defaults to value given in configuration.'
20
- end
21
- separator ''
22
- option :mode do
23
- short '-c'
24
- long '--config=CONFIG'
25
- desc 'Configuration to use.'
26
- desc 'Defaults to development.'
27
- cast Symbol
28
- end
29
- separator ''
30
- option :directory do
31
- short '-D'
32
- long '--dir=DIR'
33
- desc 'Directory containing the application.'
34
- desc 'Defaults to the current directory.'
35
- end
36
- separator ''
37
- option :daemon do
38
- short '-d'
39
- long '--daemon'
40
- desc 'Run as a daemon.'
41
- end
42
- separator ''
43
- end
44
-
45
- Waves::Server.run( Choice.choices )
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'startup'
4
+ require 'commands/waves-server'
@@ -0,0 +1,21 @@
1
+ require 'choice'
2
+
3
+ Choice.options do
4
+ header 'Run waves in console mode.'
5
+ header ''
6
+ option :mode do
7
+ short '-c'
8
+ long '--config=CONFIG'
9
+ desc 'Configuration to use.'
10
+ desc 'Defaults to development.'
11
+ cast Symbol
12
+ end
13
+ separator ''
14
+ end
15
+
16
+ console = Waves::Console.load( Choice.choices )
17
+ Object.send(:define_method, :waves) { console }
18
+ require 'irb'
19
+ require 'irb/completion'
20
+ ARGV.clear
21
+ IRB.start