doozer 0.2.2 → 0.2.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/VERSION +1 -1
- data/doozer.gemspec +2 -2
- data/lib/doozer/route.rb +48 -0
- data/lib/doozer/scripts/console.rb +1 -1
- data/lib/doozer/scripts/migrate.rb +3 -3
- data/lib/doozer/version.rb +1 -1
- data/lib/doozer/view_helpers.rb +2 -1
- data/templates/skeleton/config/boot.rb +2 -8
- data/templates/skeleton/config/routes.rb +60 -17
- data/templates/skeleton/script/console +3 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/doozer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{doozer}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["grippy"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-26}
|
13
13
|
s.default_executable = %q{doozer}
|
14
14
|
s.description = %q{This GEM provides a small, barebones framework for creating MVC Rack applications.}
|
15
15
|
s.email = %q{gmelton@whorde.com}
|
data/lib/doozer/route.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'doozer/app'
|
2
|
+
require 'doozer/view_helpers'
|
2
3
|
|
3
4
|
module Doozer
|
4
5
|
module Routing
|
@@ -19,6 +20,8 @@ module Doozer
|
|
19
20
|
# init magic routes :conrtoller/:action or just /:action with predefined :controller
|
20
21
|
# Routes.init_magic_routes
|
21
22
|
|
23
|
+
Routes.init_view_helpers
|
24
|
+
|
22
25
|
# sort routes here
|
23
26
|
@@parts.sort! do |a, b| a[1].length <=> b[1].length end
|
24
27
|
@@parts.reverse!
|
@@ -186,6 +189,13 @@ module Doozer
|
|
186
189
|
## loop route/methods pairs
|
187
190
|
# save new path for action controller
|
188
191
|
end
|
192
|
+
|
193
|
+
def self.init_view_helpers
|
194
|
+
for k, route in @@dict
|
195
|
+
Doozer::ViewHelpers.module_eval(route.url_helper_method)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
189
199
|
end
|
190
200
|
|
191
201
|
class Route
|
@@ -287,6 +297,44 @@ module Doozer
|
|
287
297
|
end
|
288
298
|
return hashish
|
289
299
|
end
|
300
|
+
|
301
|
+
# Parses route tokens and returns a helper method which evntually module_eval'd into Doozer::ViewHelpers
|
302
|
+
def url_helper_method
|
303
|
+
method_name=[@name]
|
304
|
+
# method_name.push(@format) if @format != :html
|
305
|
+
method_name.push('url')
|
306
|
+
signature = []
|
307
|
+
signature.push('(')
|
308
|
+
if not @tokens.empty?
|
309
|
+
t = []
|
310
|
+
for token in @tokens
|
311
|
+
if token.index('.')
|
312
|
+
t.push(token.split('.')[0])
|
313
|
+
else
|
314
|
+
t.push(token)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
signature.push(t.join(', '))
|
318
|
+
end
|
319
|
+
signature.push(')')
|
320
|
+
|
321
|
+
url_method = []
|
322
|
+
url_method.push("url({:name=>:#{@name}")
|
323
|
+
if not @tokens.empty?
|
324
|
+
t = []
|
325
|
+
for token in @tokens
|
326
|
+
if token.index('.')
|
327
|
+
token = token.split('.')[0]
|
328
|
+
end
|
329
|
+
t.push(" :#{token.to_sym}=>#{token}")
|
330
|
+
end
|
331
|
+
url_method.push(",#{t.join(',')}")
|
332
|
+
end
|
333
|
+
url_method.push("})")
|
334
|
+
method = """def #{method_name.join('_')}#{signature.join('')}; #{url_method} end"""
|
335
|
+
return method
|
336
|
+
end
|
337
|
+
|
290
338
|
end
|
291
339
|
end
|
292
340
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
#assumes boot.rb has already been loaded into the console
|
2
2
|
Doozer::Initializer.console(@env)
|
@@ -86,9 +86,9 @@ Doozer::Initializer.boot(@env)
|
|
86
86
|
# need to grab all the current migrations. assumes there isn't a migration with 000_*_.rb
|
87
87
|
migrations = [nil].concat( Dir.glob(File.join(APP_PATH,'db/*_*.rb')) )
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
printf "Loading migration files\n"
|
90
|
+
printf "Version: #{@version}\n"
|
91
|
+
printf "Direction: #{@direction}\n"
|
92
92
|
|
93
93
|
if @version > 0
|
94
94
|
file = migrations[@version]
|
data/lib/doozer/version.rb
CHANGED
data/lib/doozer/view_helpers.rb
CHANGED
@@ -165,9 +165,10 @@ module Doozer
|
|
165
165
|
props.join("&")
|
166
166
|
end
|
167
167
|
|
168
|
-
# Safe encodes a string by entity
|
168
|
+
# Safe encodes a string by entity encoding all less then and greater then signs
|
169
169
|
#
|
170
170
|
def h(s)
|
171
|
+
s.gsub!(/&/,'&')
|
171
172
|
s.gsub!(/</,'<')
|
172
173
|
s.gsub!(/>/,'>')
|
173
174
|
return s
|
@@ -1,4 +1,4 @@
|
|
1
|
-
DOOZER_GEM_VERSION='0.
|
1
|
+
DOOZER_GEM_VERSION='0.2.5'
|
2
2
|
|
3
3
|
require 'date'
|
4
4
|
require 'rubygems'
|
@@ -7,11 +7,5 @@ begin
|
|
7
7
|
gem 'doozer', "= #{DOOZER_GEM_VERSION}"
|
8
8
|
require 'doozer'
|
9
9
|
rescue Gem::LoadError
|
10
|
-
|
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
|
10
|
+
raise "grippy-doozer-#{DOOZER_GEM_VERSION} gem not installed"
|
17
11
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
2
|
Drawing
|
3
|
-
name, path w/ symbols, options={controller, action, status, formats, app=>HelloWorld.new}
|
3
|
+
name, path w/ symbols, options={controller, action, status, formats, optional( layout, app=>HelloWorld.new)}
|
4
4
|
|
5
5
|
Name - This is the symbol you name your route. Urls generation is mapped to this key.
|
6
6
|
Path - This is the url path. May contain token symbols which are exposed to the controller
|
@@ -8,40 +8,83 @@ Options -
|
|
8
8
|
controller,
|
9
9
|
action,
|
10
10
|
status,
|
11
|
-
formats=>[:xml, json, etc]
|
12
|
-
|
11
|
+
formats=>[:xml, json, etc],
|
12
|
+
layout
|
13
|
+
|
13
14
|
Supports the following conventions:
|
14
|
-
root '' :controller=>'something'
|
15
|
-
articles '/articles' :controller=>'article', :action=>'list'
|
16
|
-
article '/article/:id' :controller=>'article', :action=>'show'
|
15
|
+
:root '' :controller=>'something'
|
16
|
+
:articles '/articles' :controller=>'article', :action=>'list'
|
17
|
+
:article '/article/:id' :controller=>'article', :action=>'show'
|
17
18
|
|
18
19
|
Formats
|
19
|
-
Adding formats
|
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
|
20
|
+
Adding formats symbols automatically creates new routes for the formats symbols provided.
|
21
|
+
The appropriate content-type is returned with the response.
|
22
|
+
You can access the format with @format in your controllers.
|
23
|
+
Supported formats are: :json, :js, :xml, :rss, :atom
|
24
|
+
All routes default to :html format
|
24
25
|
|
25
26
|
Example:
|
26
27
|
|
27
28
|
map.add :format_example, '/format_example', {:controller=>'index', :action=>'format_example', :status=>200, :formats=>[:json, :xml]}
|
28
29
|
|
29
30
|
Automatically creates routes for :html, :json, and :xml with the appropriate content types
|
30
|
-
|
31
|
+
|
31
32
|
:html format (default)
|
32
33
|
map.add :format_example, '/format_example', {:controller=>'index', :action=>'format_example', :status=>200}
|
34
|
+
|
33
35
|
:json format
|
34
36
|
map.add :format_example_json, '/format_example.json', {:controller=>'index', :action=>'format_example', :status=>200}
|
37
|
+
|
35
38
|
:xml format
|
36
39
|
map.add :format_example_xml, '/format_example.xml', {:controller=>'index', :action=>'format_example', :status=>200}
|
40
|
+
|
41
|
+
Layouts
|
37
42
|
|
43
|
+
All routes use the layouts/default.format.erb view. You can override this by passing the layout symbol in the options hash like this:
|
44
|
+
map.add :layout_example, '/layout_example', {:controller=>'index', :action=>'layout_example', :status=>200, :layout=>'other'}
|
45
|
+
|
46
|
+
View/Layouts with Formats
|
47
|
+
|
48
|
+
If you define non-html formats you need to be aware of a few caveats.
|
49
|
+
|
50
|
+
map.add :layout_format_example,
|
51
|
+
'/layout_format_example',
|
52
|
+
{:controller=>'index', :action=>'layout_format_example', :status=>200, :layout=>'other', :formats=>[:json]}
|
53
|
+
|
54
|
+
When calling the above route with json format:
|
55
|
+
You will need to have a layouts/other.json.erb file along with an index/layout_format_example.json.erb file to render the view
|
56
|
+
|
57
|
+
See Doozer::Controller#render for more examples on how to override this from controllers actions.
|
58
|
+
|
59
|
+
Controller/View Helpers
|
60
|
+
Route url generation is accessible in the following ways:
|
61
|
+
Defauls method for generating route urls:
|
62
|
+
url({:name=>:some_route ... :key=>'some value'})
|
63
|
+
-or-
|
64
|
+
Magic helper methods for generating route urls. The param order is taken right from the order of the parsed route tokens.
|
65
|
+
|
66
|
+
route_name_url - default html, no params
|
67
|
+
route_name_url(param1, params2) - default html, w/ params
|
68
|
+
route_name_format_url(param1, params2) - non html w/ params
|
69
|
+
|
70
|
+
Example:
|
71
|
+
some_route_url
|
72
|
+
some_route_json_url(param1, param2, param3)
|
73
|
+
|
74
|
+
In addition, you can also wrap the urls with a link tag like this:
|
75
|
+
link('anchor text', route_args, link_args)
|
76
|
+
Example:
|
77
|
+
link('homepage', {:name=>:index}, {:class=>'link_css', :id=>'home'})
|
78
|
+
-or-
|
79
|
+
link('homepage', index_url, {:class=>'link_css', :id=>'home'})
|
38
80
|
|
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
81
|
|
43
|
-
|
44
|
-
|
82
|
+
Not Currently Supported...
|
83
|
+
Magic Routes
|
84
|
+
This route automatically creates routes for all actions on controller 'something_not_called_fubar'
|
85
|
+
fubar/:action :controller=>'something_not_called_fubar'
|
86
|
+
This creates routes for all controller actions residing in the application.
|
87
|
+
:controller/:action
|
45
88
|
|
46
89
|
Additional Rackup Apps
|
47
90
|
You can create additional rackup apps and assign them to a route
|
@@ -1,14 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'irb'
|
3
3
|
APP_PATH = Dir.pwd
|
4
|
-
|
4
|
+
boot = File.join(APP_PATH, 'config/boot')
|
5
|
+
require boot
|
5
6
|
|
6
7
|
@env = (ARGV.length > 0) ? ARGV[0] : 'development'
|
7
8
|
ARGV.delete(@env) if ARGV.include?(@env)
|
8
9
|
@env = @env.to_sym
|
9
10
|
printf "[Doozer #{Doozer::Version::STRING}]\n"
|
10
11
|
# see http://ruby-doc.org/core/ for more options
|
11
|
-
IRB.conf[:LOAD_MODULES] = ["irb/completion", "#{DOOZER_PATH}/doozer/scripts/console"]
|
12
|
+
IRB.conf[:LOAD_MODULES] = ["irb/completion", boot, "#{DOOZER_PATH}/doozer/scripts/console"]
|
12
13
|
IRB.conf[:USE_READLINE] = true
|
13
14
|
IRB.load_modules()
|
14
15
|
IRB.parse_opts()
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doozer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- grippy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-26 00:00:00 -07:00
|
13
13
|
default_executable: doozer
|
14
14
|
dependencies: []
|
15
15
|
|