doozer 0.2.0

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.
Files changed (104) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +57 -0
  5. data/Rakefile +62 -0
  6. data/VERSION +1 -0
  7. data/bin/doozer +6 -0
  8. data/doozer.gemspec +156 -0
  9. data/lib/doozer.rb +35 -0
  10. data/lib/doozer/active_support/array.rb +14 -0
  11. data/lib/doozer/active_support/class.rb +221 -0
  12. data/lib/doozer/active_support/date_time.rb +23 -0
  13. data/lib/doozer/active_support/object.rb +43 -0
  14. data/lib/doozer/active_support/time.rb +32 -0
  15. data/lib/doozer/app.rb +294 -0
  16. data/lib/doozer/configs.rb +146 -0
  17. data/lib/doozer/controller.rb +340 -0
  18. data/lib/doozer/exceptions.rb +12 -0
  19. data/lib/doozer/extend.rb +10 -0
  20. data/lib/doozer/initializer.rb +104 -0
  21. data/lib/doozer/lib.rb +32 -0
  22. data/lib/doozer/logger.rb +12 -0
  23. data/lib/doozer/orm/active_record.rb +28 -0
  24. data/lib/doozer/orm/data_mapper.rb +22 -0
  25. data/lib/doozer/orm/sequel.rb +21 -0
  26. data/lib/doozer/partial.rb +99 -0
  27. data/lib/doozer/plugins/paginate/init.rb +2 -0
  28. data/lib/doozer/plugins/paginate/lib/paginate.rb +32 -0
  29. data/lib/doozer/plugins/paginate/lib/paginate/collection.rb +60 -0
  30. data/lib/doozer/plugins/paginate/lib/paginate/finder.rb +116 -0
  31. data/lib/doozer/plugins/paginate/lib/paginate/view_helpers.rb +37 -0
  32. data/lib/doozer/rackup/server.ru +35 -0
  33. data/lib/doozer/rackup/test.rb +20 -0
  34. data/lib/doozer/redirect.rb +12 -0
  35. data/lib/doozer/route.rb +292 -0
  36. data/lib/doozer/scripts/cluster.rb +126 -0
  37. data/lib/doozer/scripts/console.rb +2 -0
  38. data/lib/doozer/scripts/migrate.rb +108 -0
  39. data/lib/doozer/scripts/task.rb +60 -0
  40. data/lib/doozer/scripts/test.rb +23 -0
  41. data/lib/doozer/version.rb +8 -0
  42. data/lib/doozer/view_helpers.rb +251 -0
  43. data/lib/doozer/watcher.rb +369 -0
  44. data/lib/generator/generator.rb +548 -0
  45. data/templates/skeleton/Rakefile +3 -0
  46. data/templates/skeleton/app/controllers/application_controller.rb +2 -0
  47. data/templates/skeleton/app/controllers/index_controller.rb +7 -0
  48. data/templates/skeleton/app/helpers/application_helper.rb +17 -0
  49. data/templates/skeleton/app/views/global/_header.html.erb +7 -0
  50. data/templates/skeleton/app/views/global/_navigation.html.erb +6 -0
  51. data/templates/skeleton/app/views/index/index.html.erb +108 -0
  52. data/templates/skeleton/app/views/layouts/default.html.erb +23 -0
  53. data/templates/skeleton/config/app.yml +31 -0
  54. data/templates/skeleton/config/boot.rb +17 -0
  55. data/templates/skeleton/config/database.yml +25 -0
  56. data/templates/skeleton/config/environment.rb +11 -0
  57. data/templates/skeleton/config/rack.rb +30 -0
  58. data/templates/skeleton/config/routes.rb +69 -0
  59. data/templates/skeleton/script/cluster +4 -0
  60. data/templates/skeleton/script/console +15 -0
  61. data/templates/skeleton/script/migrate +4 -0
  62. data/templates/skeleton/script/task +4 -0
  63. data/templates/skeleton/script/test +4 -0
  64. data/templates/skeleton/static/404.html +16 -0
  65. data/templates/skeleton/static/500.html +16 -0
  66. data/templates/skeleton/static/css/style.css +32 -0
  67. data/templates/skeleton/static/favicon.ico +0 -0
  68. data/templates/skeleton/static/js/application.js +1 -0
  69. data/templates/skeleton/static/js/jquery-1.3.min.js +19 -0
  70. data/templates/skeleton/static/robots.txt +5 -0
  71. data/templates/skeleton/test/fixtures/setup.rb +6 -0
  72. data/templates/skeleton/test/setup.rb +33 -0
  73. data/test/doozer_test.rb +7 -0
  74. data/test/project/Rakefile +3 -0
  75. data/test/project/app/controllers/application_controller.rb +2 -0
  76. data/test/project/app/controllers/index_controller.rb +7 -0
  77. data/test/project/app/helpers/application_helper.rb +17 -0
  78. data/test/project/app/views/global/_header.html.erb +7 -0
  79. data/test/project/app/views/global/_navigation.html.erb +6 -0
  80. data/test/project/app/views/index/index.html.erb +108 -0
  81. data/test/project/app/views/layouts/default.html.erb +23 -0
  82. data/test/project/config/app.yml +31 -0
  83. data/test/project/config/boot.rb +17 -0
  84. data/test/project/config/database.yml +25 -0
  85. data/test/project/config/environment.rb +11 -0
  86. data/test/project/config/rack.rb +30 -0
  87. data/test/project/config/routes.rb +72 -0
  88. data/test/project/script/cluster +4 -0
  89. data/test/project/script/console +15 -0
  90. data/test/project/script/migrate +4 -0
  91. data/test/project/script/task +4 -0
  92. data/test/project/script/test +4 -0
  93. data/test/project/static/404.html +16 -0
  94. data/test/project/static/500.html +16 -0
  95. data/test/project/static/css/style.css +32 -0
  96. data/test/project/static/favicon.ico +0 -0
  97. data/test/project/static/js/application.js +1 -0
  98. data/test/project/static/js/jquery-1.3.min.js +19 -0
  99. data/test/project/static/robots.txt +5 -0
  100. data/test/project/test/fixtures/setup.rb +6 -0
  101. data/test/project/test/setup.rb +33 -0
  102. data/test/routing_test.rb +66 -0
  103. data/test/test_helper.rb +26 -0
  104. metadata +169 -0
@@ -0,0 +1,3 @@
1
+ require 'rake'
2
+ Dir['tasks/**/*.rake'].each { |t| load t }
3
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ class ApplicationController < Doozer::Controller
2
+ end
@@ -0,0 +1,7 @@
1
+ class IndexController < ApplicationController
2
+
3
+ def index
4
+ meta({:description=>"meta description goes here"})
5
+ end
6
+
7
+ end
@@ -0,0 +1,17 @@
1
+ # This is the default ApplicationHelper.
2
+ # Place methods here which are global to your application.
3
+ # By default all controllers include this file.
4
+ #
5
+ # To load a helper file into a controller:
6
+ #
7
+ # Example:
8
+ #
9
+ # -files: app_root/app/helpers/helper1_helper.rb, app_root/app/helpers/helper2_helper.rb
10
+ #
11
+ # -declare inside controller: self.require_view_helpers=[:helper1, :helper2]
12
+ #
13
+ # By default all helpers are automatically included into the base partial class.
14
+ # Be care to avoid methods with the same names between helper modules.
15
+ # The helpers are included alphabetically by file name
16
+ module ApplicationHelper
17
+ end
@@ -0,0 +1,7 @@
1
+ <div id="hdr">
2
+ <%=partial('global/navigation')%>
3
+ <span class="big"><%=link('Home', {:name=>:index})%></span>
4
+ </div>
5
+ <%#=img("/images/doozers.jpg", {:class=>'img'})%>
6
+
7
+
@@ -0,0 +1,6 @@
1
+ <div class="nav">
2
+ <p>
3
+ <span><%#=link('about us', {:name=>:about_us})%></span> |
4
+ <span><%#=link('contact', {:name=>:contact})%></span> |
5
+ </p>
6
+ </div>
@@ -0,0 +1,108 @@
1
+ <h2><span>Project Details</span></h2>
2
+ <p><span>Doozer is a <%=link('Rackup', 'http://rack.rubyforge.org/') %> application.</span></p>
3
+
4
+ <ul>
5
+ <li><span>Bare bones, lightweight, MVC framework.</span></li>
6
+ <li><span>Map routes to controller actions or completely separate applications.</span></li>
7
+ <li><span>ORM agnostic. use activerecord, data mapper, or sequel</span></li>
8
+ <li><span>Easy to define static directories</span></li>
9
+ <li><span>View Helpers for controllers</span></li>
10
+ <li><span>Layouts and Partials</span></li>
11
+ </ul>
12
+
13
+ <h3>Intro</h3>
14
+ <h4>Inspiration</h4>
15
+
16
+ <h3>Requirements</h3>
17
+ <h4>Rackup</h4>
18
+ <p>Rackup and its dependencies:</p>
19
+
20
+ <h3>File Structure</h3>
21
+ <p>This should look similar to rails</p>
22
+ <h4>Layout</h4>
23
+
24
+ <h3>Configs</h3>
25
+ <h4>Static</h4>
26
+ <h4>ORM</h4>
27
+ <h4>Clusters</h4>
28
+ <p>This needs to change names to something better. Maybe Server?</p>
29
+ <h3>Environment</h3>
30
+ <h4>Load Hooks</h4>
31
+ <h4>Settings</h4>
32
+
33
+ <h3>Load Order</h3>
34
+
35
+ <h3>Routes</h3>
36
+ <h4>Parameters</h4>
37
+ <h4>Magic</h4>
38
+ <p>A magic route is similar to "/:controller/:action" in rails.</p>
39
+ <p>Right now, these are tuned off in favor of explicitly having to declare them. Formats aren't extended to them yet. :()</p>
40
+ <h4>Bypassing Controllers</h4>
41
+ <p>You can declare a Rackup compatible app to call instead of a Doozer::Controller.</p>
42
+ <p>See config/routes.rb for more info.</p>
43
+ <h4>Layouts</h4>
44
+ <p>By default all html routes use the default.html.erb layout generated with the initial scaffolding.</p>
45
+ <p>Declare a route layout of :layout=>:view_name to override the default behavior.</p>
46
+
47
+
48
+ <h3>App</h3>
49
+ <h4>Security</h4>
50
+ <h5>Post Requests</h5>
51
+ <h6>Authenticity Token</h6>
52
+
53
+ <h4>Model</h4>
54
+ <h4>View</h4>
55
+ <h5>Route Tokens</h5>
56
+ <h4>Controller</h4>
57
+ <h5>Callbacks</h5>
58
+ As a controller is initialized, rendered, and finalized, you have the ability to influence the call stack.
59
+
60
+ <h6>after_initialize</h6>
61
+ <p>This is called after the controller is matched to the route and intialized.
62
+ <p>Use this hook to customize which actions shouldn't call before_filter and after_filter.</p>
63
+ <code>
64
+ @before_filter={:exclude=>[:action1, :action2]}
65
+ @after_filter={:exclude=>[:action1, :action2]}
66
+ </code>
67
+ <h6>before_filter</h6>
68
+ <p>By default all actions call this method. You can override it in your controller class by declaring:</p>
69
+ <code>
70
+ def before_filter
71
+ #code goes here....
72
+ end
73
+ </code>
74
+ <h6>after_filter</h6>
75
+ <p>By default all actions call this method. You can override it in your controller class by declaring:</p>
76
+ <code>
77
+ def after_filter
78
+ #code goes here....
79
+ end
80
+ </code>
81
+ <h5>Params</h5>
82
+ <h5>Route Tokens</h5>
83
+ <p>All route tokens are available as instance variables.</p>
84
+ <p>A route token of :id is available in an action and it's view as @id. You must pass this variable into a partial as a local variable.</p>
85
+
86
+ <h3>View Helpers</h3>
87
+ <h4>Redirects</h4>
88
+ <h4>Flash</h4>
89
+ <h4>Partial</h4>
90
+ <h4>Layout</h4>
91
+ <h4>Session</h4>
92
+
93
+ <h3>Generators</h3>
94
+ <h4>MVC Files</h4>
95
+
96
+ <h3>Scaffold</h3>
97
+ <h4>Building Project</h4>
98
+
99
+ <h3>Static</h3>
100
+
101
+ <h3>Testing</h3>
102
+
103
+ <h3>Tasks</h3>
104
+
105
+ <h3>App Start</h3>
106
+ <h4>Config</h4>
107
+ <h4>Start Command</h4>
108
+ <h5>Environments</h5>
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>Doozer! Build Something</title>
6
+ <%=metatags()%>
7
+ <link rel="icon" href="/favicon.ico" />
8
+ <%=stylesheet('/css/style.css')%>
9
+ <%=javascript('/js/jquery-1.3.min.js')%>
10
+ <%=javascript('/js/application.js')%>
11
+ </head>
12
+ <body>
13
+ <%=partial('global/header')%>
14
+ <%if @flash[:info]%>
15
+ <div class="msg info"><%=@flash[:info]%></div>
16
+ <%end%>
17
+ <%if @flash[:error]%>
18
+ <div class="msg error"><%=@flash[:error]%></div>
19
+ <%end%>
20
+ <%=@view[:body]%>
21
+ </body>
22
+ </html>
23
+ <%=@view[:timestamp]%>
@@ -0,0 +1,31 @@
1
+ development:
2
+ name: app_name_development
3
+ base_url: http://localhost:9292/
4
+ static_urls: ["/favicon.ico", "/robots.txt", "/css", "/images", "/html", "/js"]
5
+ static_root: static
6
+ 404: static/404.html
7
+ 500: static/500.html
8
+
9
+ deployment:
10
+ name: app_name_production
11
+ base_url: http://example.com/
12
+ static_urls: ["/favicon.ico", "/robots.txt", "/css", "/images", "/html", "/js"]
13
+ static_root: static
14
+ 404: static/404.html
15
+ 500: static/500.html
16
+
17
+ # test automatically loads the app with 127.0.0.1:5000
18
+ test:
19
+ name: app_name_test
20
+ base_url: http://localhost:5000
21
+ static_urls: ["/favicon.ico", "/robots.txt", "/css", "/images", "/html", "/js"]
22
+ static_root: static
23
+ 404: static/404.html
24
+ 500: static/500.html
25
+
26
+ # this is the default server to use when starting up the app clusters
27
+ # add multiple ip:port csv values. all are loaded for production.
28
+ # only the first is loaded for development
29
+ clusters:
30
+ server: mongrel
31
+ apps: ["127.0.0.1:9292"]
@@ -0,0 +1,17 @@
1
+ DOOZER_GEM_VERSION='0.1.5'
2
+
3
+ require 'date'
4
+ require 'rubygems'
5
+
6
+ begin
7
+ gem 'doozer', "= #{DOOZER_GEM_VERSION}"
8
+ require 'doozer'
9
+ rescue Gem::LoadError
10
+ # "grippy-doozer-#{DOOZER_GEM_VERSION} gem not installed. checking different gem name..."
11
+ begin
12
+ gem 'grippy-doozer', "= #{DOOZER_GEM_VERSION}"
13
+ require 'doozer'
14
+ rescue Gem::LoadError
15
+ raise "grippy-doozer-#{DOOZER_GEM_VERSION} gem not installed"
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ # uncomment once orm gem is installed
2
+ # name of the orm gem you'd like to use: active_record || data_mapper || sequel
3
+ # orm: active_record
4
+
5
+ # uncomment once schema is created
6
+ development:
7
+ # adapter: mysql
8
+ # database: app_development
9
+ # username: root
10
+ # password:
11
+ # host: localhost
12
+
13
+ deployment:
14
+ # adapter: mysql
15
+ # database: app_production
16
+ # username: root
17
+ # password:
18
+ # host: localhost
19
+
20
+ test:
21
+ # adapter: mysql
22
+ # database: app_test
23
+ # username: root
24
+ # password:
25
+ # host: localhost
@@ -0,0 +1,11 @@
1
+ # This file is loaded right after orm is initialized and right before app, controllers and models
2
+ # place code here which is used throughout the application
3
+ printf "Loading Environment... \n"
4
+
5
+ Doozer::Initializer.after_orm do | config |
6
+ # require 'doozer/plugins/paginate/init'
7
+ end
8
+
9
+ Doozer::Initializer.before_rackup do | config |
10
+ # p "Before rackup, horray for rackup!"
11
+ end
@@ -0,0 +1,30 @@
1
+ # By default doozer maps everything against "/"
2
+ #
3
+ # This file is required inside the main doozer/rackup/server.ru config.
4
+ # Make sure everything inside the stack method conforms to the Rack::Builder spec.
5
+ #
6
+ # You can map urls to differnt rack applications by plugging them in here...
7
+ # Example on how to hook up another rack app to the stack
8
+ class HelloWorld
9
+ def call(env)
10
+ [200, {"Content-Type" => "text/html"}, "Hello World!!!\n"]
11
+ end
12
+ end
13
+
14
+ # map additional rack apps here..
15
+ def stack
16
+ # map your apps here...
17
+ map "/hello" do
18
+ run HelloWorld.new
19
+ end
20
+
21
+ map "/lobster" do
22
+ require 'rack/lobster'
23
+ use Rack::ShowExceptions
24
+ use Rack::Auth::Basic, "Lobster 2.0" do |username, password|
25
+ 'secret' == password
26
+ end
27
+ run Rack::Lobster.new
28
+ end
29
+
30
+ end
@@ -0,0 +1,69 @@
1
+ """
2
+ Drawing
3
+ name, path w/ symbols, options={controller, action, status, formats, app=>HelloWorld.new}
4
+
5
+ Name - This is the symbol you name your route. Urls generation is mapped to this key.
6
+ Path - This is the url path. May contain token symbols which are exposed to the controller
7
+ Options -
8
+ controller,
9
+ action,
10
+ status,
11
+ formats=>[:xml, json, etc]
12
+
13
+ Supports the following conventions:
14
+ root '' :controller=>'something'
15
+ articles '/articles' :controller=>'article', :action=>'list'
16
+ article '/article/:id' :controller=>'article', :action=>'show'
17
+
18
+ Formats
19
+ Adding formats symbolzes automatically creates new routes for the formats symbols provided.
20
+ The appropriate content-type is returned with the response.
21
+ You can access the format with @format in your controllers.
22
+ Supported formats are: :json, :js, :xml, :rss, :atom
23
+ All routes default to :html format
24
+
25
+ Example:
26
+
27
+ map.add :format_example, '/format_example', {:controller=>'index', :action=>'format_example', :status=>200, :formats=>[:json, :xml]}
28
+
29
+ Automatically creates routes for :html, :json, and :xml with the appropriate content types
30
+
31
+ :html format (default)
32
+ map.add :format_example, '/format_example', {:controller=>'index', :action=>'format_example', :status=>200}
33
+ :json format
34
+ map.add :format_example_json, '/format_example.json', {:controller=>'index', :action=>'format_example', :status=>200}
35
+ :xml format
36
+ map.add :format_example_xml, '/format_example.xml', {:controller=>'index', :action=>'format_example', :status=>200}
37
+
38
+
39
+ Magic Routes
40
+ This route automatically creates routes for all actions on controller 'something_not_called_fubar'
41
+ fubar/:action :controller=>'something_not_called_fubar'
42
+
43
+ This creates routes for all controller actions residing in the application.
44
+ :controller/:action
45
+
46
+ Additional Rackup Apps
47
+ You can create additional rackup apps and assign them to a route
48
+
49
+ Just require the file here and then instantiate the class when you map the route.
50
+ Make sure the rackup app adheres to the rack spec.
51
+
52
+ Example:
53
+
54
+ require 'lib/rackup_upload'
55
+ Doozer::Routing::Routes.draw do | map |
56
+ map.add :upload, '', {:controller=>'upload', :action=>'process', :status=>200, :app=>RackupUpload.new}
57
+ end
58
+ """
59
+
60
+ Doozer::Routing::Routes.draw do | map |
61
+
62
+ """
63
+ :name,
64
+ :path w/ tokens,
65
+ :options={:controller, :action, :status, :formats=>[:json, :xml, :js, etc], :app=>Class.new}
66
+ """
67
+ map.add :index, '', {:controller=>'index', :action=>'index', :status=>200}
68
+
69
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = Dir.pwd
3
+ require File.join(APP_PATH, 'config/boot')
4
+ require File.join(DOOZER_PATH, 'doozer/scripts/cluster')
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'irb'
3
+ APP_PATH = Dir.pwd
4
+ require File.join(APP_PATH, 'config/boot')
5
+
6
+ @env = (ARGV.length > 0) ? ARGV[0] : 'development'
7
+ ARGV.delete(@env) if ARGV.include?(@env)
8
+ @env = @env.to_sym
9
+ printf "[Doozer #{Doozer::Version::STRING}]\n"
10
+ # see http://ruby-doc.org/core/ for more options
11
+ IRB.conf[:LOAD_MODULES] = ["irb/completion", "#{DOOZER_PATH}/doozer/scripts/console"]
12
+ IRB.conf[:USE_READLINE] = true
13
+ IRB.load_modules()
14
+ IRB.parse_opts()
15
+ IRB.start()
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = Dir.pwd
3
+ require File.join(APP_PATH, 'config/boot')
4
+ require File.join(DOOZER_PATH, 'doozer/scripts/migrate')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = Dir.pwd
3
+ require File.join(APP_PATH, 'config/boot')
4
+ require File.join(DOOZER_PATH, 'doozer/scripts/task')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = Dir.pwd
3
+ require File.join(APP_PATH, 'config/boot')
4
+ require File.join(DOOZER_PATH, 'doozer/scripts/test')
@@ -0,0 +1,16 @@
1
+ <html>
2
+ <head>
3
+ <title>Page Not Found</title>
4
+ </head>
5
+ <body>
6
+ Sorry, we couldn't find the page you were looking for.
7
+ <pre>
8
+ _
9
+ | |
10
+ _ | | ___ ___ _____ ____ ____
11
+ / || | / _ \ / _ \(___ )/ _ ) / ___)
12
+ ( (_| || |_| || |_| |/ __/( (/ / | |
13
+ \____| \___/ \___/(_____)\____)|_|
14
+ </pre>
15
+ </body>
16
+ </html>
@@ -0,0 +1,16 @@
1
+ <html>
2
+ <head>
3
+ <title>Internal Server Error</title>
4
+ </head>
5
+ <body>
6
+ It appears we've been hit with a case of Fragile munching. There was an internal server error. We've been notified and are looking into it.
7
+ <pre>
8
+ _
9
+ | |
10
+ _ | | ___ ___ _____ ____ ____
11
+ / || | / _ \ / _ \(___ )/ _ ) / ___)
12
+ ( (_| || |_| || |_| |/ __/( (/ / | |
13
+ \____| \___/ \___/(_____)\____)|_|
14
+ </pre>
15
+ </body>
16
+ </html>