trestle_generator 1.0.0 → 1.0.1
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/USAGE +8 -8
- data/templates/controller.rb +2 -2
- data/templates/functional_test.rb +11 -11
- data/trestle_generator.rb +5 -5
- metadata +45 -42
data/USAGE
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
Description:
|
2
|
-
The trestle generator (
|
3
|
-
creates a controller to interact with a model. If the
|
4
|
-
it creates the model as well. The generated code is
|
5
|
-
"scaffold :model" declaration, making it easy to migrate
|
6
|
-
customize your controller and views.
|
2
|
+
The trestle generator (a drop-in replacement for the Rails scaffold
|
3
|
+
generator) creates a controller and views to interact with a model. If the
|
4
|
+
model does not exist, it creates the model as well. The generated code is
|
5
|
+
equivalent to the "scaffold :model" declaration, making it easy to migrate
|
6
|
+
when you wish to customize your controller and views.
|
7
7
|
|
8
8
|
The generator takes a model name, an optional controller name, and a
|
9
|
-
list of views as arguments.
|
9
|
+
list of views as arguments. Trestle actions and views are created
|
10
10
|
automatically. Any views left over generate empty stubs.
|
11
11
|
|
12
|
-
The
|
12
|
+
The trestle actions are:
|
13
13
|
index, new, edit, destroy
|
14
14
|
|
15
|
-
The
|
15
|
+
The trestle views are:
|
16
16
|
_index_without_id, _index_with_id, new, edit
|
17
17
|
|
18
18
|
If a controller name is not given, the plural form of the model name
|
data/templates/controller.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
-
verify :only => [
|
2
|
+
verify :only => [ 'destroy<%= suffix %>', 'edit<%= suffix %>' ],
|
3
3
|
:params => :id,
|
4
4
|
:add_flash => { :notice => 'Missing <%= singular_name %> ID.' },
|
5
5
|
:redirect_to => { :action => '<%= suffix || 'index' %>' }
|
6
6
|
|
7
|
-
<% for action in
|
7
|
+
<% for action in nontrestle_actions -%>
|
8
8
|
def <%= action %><%= suffix %>
|
9
9
|
end
|
10
10
|
|
@@ -13,16 +13,16 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
|
13
13
|
@response = ActionController::TestResponse.new
|
14
14
|
end
|
15
15
|
|
16
|
-
<% for action in
|
16
|
+
<% for action in nontrestle_actions -%>
|
17
17
|
def test_<%= action %>
|
18
|
-
get
|
18
|
+
get '<%= action %>'
|
19
19
|
assert_response :success
|
20
20
|
assert_template '<%= action %>'
|
21
21
|
end
|
22
22
|
|
23
23
|
<% end -%>
|
24
24
|
def test_<%= suffix || 'index' %>
|
25
|
-
get
|
25
|
+
get '<%= suffix || 'index' %>'
|
26
26
|
assert_response :success
|
27
27
|
assert_template '<%= plural_name %>/_<%= suffix || 'index' %>_without_id'
|
28
28
|
end
|
@@ -30,7 +30,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
|
30
30
|
def test_destroy<%= suffix %>_using_get
|
31
31
|
assert_not_nil <%= model_name %>.find(1)
|
32
32
|
|
33
|
-
get
|
33
|
+
get 'destroy<%= suffix %>', :id => 1
|
34
34
|
assert_response :redirect
|
35
35
|
assert_redirected_to :action => 'edit<%= suffix %>'
|
36
36
|
|
@@ -40,7 +40,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
|
40
40
|
def test_destroy<%= suffix %>_using_post
|
41
41
|
assert_not_nil <%= model_name %>.find(1)
|
42
42
|
|
43
|
-
post
|
43
|
+
post 'destroy<%= suffix %>', :id => 1
|
44
44
|
assert_response :redirect
|
45
45
|
assert_redirected_to :action => '<%= suffix || 'index' %>'
|
46
46
|
|
@@ -48,7 +48,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_edit<%= suffix %>_using_get
|
51
|
-
get
|
51
|
+
get 'edit<%= suffix %>', :id => 1
|
52
52
|
|
53
53
|
assert_response :success
|
54
54
|
assert_template 'edit<%= suffix %>'
|
@@ -58,13 +58,13 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_edit<%= suffix %>_using_post
|
61
|
-
post
|
61
|
+
post 'edit<%= suffix %>', :id => 1
|
62
62
|
assert_response :redirect
|
63
63
|
assert_redirected_to :action => '<%= suffix || 'index' %>', :id => 1
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_<%= suffix || 'index' %>_without_id
|
67
|
-
get
|
67
|
+
get '<%= suffix || 'index' %>'
|
68
68
|
|
69
69
|
assert_response :success
|
70
70
|
assert_template '<%= plural_name %>/_<%= suffix || 'index' %>_without_id'
|
@@ -73,7 +73,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_<%= suffix || 'index' %>_with_id
|
76
|
-
get
|
76
|
+
get '<%= suffix || 'index' %>', :id => 1
|
77
77
|
|
78
78
|
assert_response :success
|
79
79
|
assert_template '<%= plural_name %>/_<%= suffix || 'index' %>_with_id'
|
@@ -83,7 +83,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_new<%= suffix %>_using_get
|
86
|
-
get
|
86
|
+
get 'new<%= suffix %>'
|
87
87
|
|
88
88
|
assert_response :success
|
89
89
|
assert_template 'new<%= suffix %>'
|
@@ -94,7 +94,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
|
94
94
|
def test_new<%= suffix %>_using_post
|
95
95
|
num_<%= plural_name %> = <%= model_name %>.count
|
96
96
|
|
97
|
-
post
|
97
|
+
post 'new<%= suffix %>', :<%= singular_name %> => {}
|
98
98
|
|
99
99
|
assert_response :redirect
|
100
100
|
assert_redirected_to :action => '<%= suffix || 'index' %>'
|
data/trestle_generator.rb
CHANGED
@@ -75,7 +75,7 @@ class TrestleGenerator < Rails::Generator::NamedBase
|
|
75
75
|
# Depend on model generator but skip if the model exists.
|
76
76
|
m.dependency 'model', [singular_name], :collision => :skip
|
77
77
|
|
78
|
-
#
|
78
|
+
# Trestle forms.
|
79
79
|
m.complex_template "form.rhtml",
|
80
80
|
File.join('app/views',
|
81
81
|
controller_class_path,
|
@@ -87,7 +87,7 @@ class TrestleGenerator < Rails::Generator::NamedBase
|
|
87
87
|
:end_mark => 'eoform',
|
88
88
|
:mark_id => singular_name
|
89
89
|
|
90
|
-
#
|
90
|
+
# Trestle views.
|
91
91
|
trestle_views.each do |action|
|
92
92
|
m.template "view_#{action}.rhtml",
|
93
93
|
File.join('app/views',
|
@@ -118,8 +118,8 @@ class TrestleGenerator < Rails::Generator::NamedBase
|
|
118
118
|
m.template 'style.css', 'public/stylesheets/trestle.css'
|
119
119
|
|
120
120
|
|
121
|
-
#
|
122
|
-
|
121
|
+
# Non-trestle views.
|
122
|
+
nontrestle_actions.each do |action|
|
123
123
|
path = File.join('app/views',
|
124
124
|
controller_class_path,
|
125
125
|
controller_file_name,
|
@@ -153,7 +153,7 @@ class TrestleGenerator < Rails::Generator::NamedBase
|
|
153
153
|
class_name.demodulize
|
154
154
|
end
|
155
155
|
|
156
|
-
def
|
156
|
+
def nontrestle_actions
|
157
157
|
args - trestle_actions
|
158
158
|
end
|
159
159
|
|
metadata
CHANGED
@@ -3,53 +3,56 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: trestle_generator
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2006-01-
|
8
|
-
summary: "[Rails]
|
9
|
-
controllers that are safe from state-changing HTTP GET requests
|
10
|
-
streamlined URLs."
|
6
|
+
version: 1.0.1
|
7
|
+
date: 2006-01-10
|
8
|
+
summary: "[Rails] A drop-in replacement for the scaffold generator that produces
|
9
|
+
production-ready controllers that are safe from state-changing HTTP GET requests
|
10
|
+
and that have streamlined URLs."
|
11
11
|
require_paths:
|
12
12
|
- templates
|
13
13
|
email: nils@alumni.rice.edu
|
14
14
|
homepage: http://www.rubyforge.org/projects/trestle
|
15
15
|
rubyforge_project: trestle
|
16
|
-
description: "
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
that change data. Well-behaved web applications
|
22
|
-
errant HTTP GET requests
|
23
|
-
like
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
is that you will not have to throw away or tweak as much
|
29
|
-
as you do scaffold-generated code. Less work for you
|
30
|
-
built sooner. Tobias L�tke�s postback_generator
|
31
|
-
|
32
|
-
|
33
|
-
/people/list -
|
34
|
-
person form /people/create -
|
35
|
-
parameters /people/show/99 -
|
36
|
-
/people/edit/99 -
|
37
|
-
/people/update/99 -
|
38
|
-
parameters /people/destroy/99 -
|
39
|
-
for HTTP GET! Contrast this with the
|
40
|
-
|
41
|
-
shows an empty person form
|
42
|
-
parameters /people/99 - shows the person record having
|
43
|
-
|
44
|
-
updates the person record having ID 99 using request
|
45
|
-
/people/99/destroy -
|
46
|
-
the user must click the form�s Destroy button to destroy a record
|
47
|
-
deletes the person record having ID 99 after prompting
|
48
|
-
Notice the hierarchical nature of trestle URLs.
|
49
|
-
verb,
|
50
|
-
|
51
|
-
|
52
|
-
|
16
|
+
description: "Don�t drive your train across a gorge with nothing but a scaffold underneath it.
|
17
|
+
Use a trestle instead! The trestle generator is drop-in replacement for the
|
18
|
+
Rails scaffold generator. Unlike scaffolding, trestle controllers protect your
|
19
|
+
models from state-changing HTTP GET requests. They also have streamlined URLs
|
20
|
+
that make your application more usable. SAFETY The trestle generator requires
|
21
|
+
the HTTP POST method for actions that change data. Well-behaved web applications
|
22
|
+
protect themselves against errant HTTP GET requests such as come from Google Web
|
23
|
+
Accelerator and the like. Scaffolded controllers fail to do this. USABILITY
|
24
|
+
Trestle controllers have just four actions (index, new, edit, and destroy). The
|
25
|
+
scaffold generator produces controllers that have eight actions. Fewer actions
|
26
|
+
exposed to the outside world is better if the behavior of these actions is in
|
27
|
+
line with the semantics of HTTP GET and HTTP POST. The net effect of this design
|
28
|
+
improvement is that you will not have to throw away or tweak as much
|
29
|
+
trestle-generated code as you do scaffold-generated code. Less work for you
|
30
|
+
means your application gets built sooner. Tobias L�tke�s postback_generator
|
31
|
+
RubyGem had the same idea, but trestle goes further. A scaffold for a database
|
32
|
+
table named �people� has the following HTTP interface: /people - Lists existing
|
33
|
+
person records /people/list - Lists existing person records /people/new -
|
34
|
+
Shows an empty person form /people/create - Creates a new person record from
|
35
|
+
request parameters /people/show/99 - Shows the person record having ID 99
|
36
|
+
/people/edit/99 - Shows a person form for the person record having ID 99
|
37
|
+
/people/update/99 - Updates the person record having ID 99 using request
|
38
|
+
parameters /people/destroy/99 - Deletes the person record having ID 99, even
|
39
|
+
for HTTP GET! Contrast this with the HTTP interface of the equivalent trestle
|
40
|
+
controller: /people - GET or POST lists existing person records /people/new -
|
41
|
+
GET shows an empty person form /people/new - POST creates a new person record
|
42
|
+
from request parameters /people/99 - GET or POST shows the person record having
|
43
|
+
ID 99 /people/99/edit - GET shows a person form for the person record having ID
|
44
|
+
99 /people/99/edit - POST updates the person record having ID 99 using request
|
45
|
+
parameters /people/99/destroy - GET redirects to /people/99/edit with a notice
|
46
|
+
that the user must click the form�s Destroy button in order to destroy a record
|
47
|
+
/people/99/destroy - POST deletes the person record having ID 99 after prompting
|
48
|
+
the user for confirmation Notice the hierarchical nature of trestle URLs.
|
49
|
+
Because the ID comes before the verb, the user can click the Up One Level button
|
50
|
+
on the Google Toolbar to explore the application. (The Up One Level button clips
|
51
|
+
one element off the end of the current URL.) Scaffold URLs do not play nicely
|
52
|
+
with the Up One Level button. Trestle controllers are pain relief to users who
|
53
|
+
like the Up One Level button. But for a user who likes to type URLs in by hand,
|
54
|
+
it also shows a friendly notice if his request is missing an ID. This is one
|
55
|
+
more way to improve usability."
|
53
56
|
autorequire:
|
54
57
|
default_executable:
|
55
58
|
bindir: bin
|