trestle_generator 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/USAGE CHANGED
@@ -1,18 +1,18 @@
1
1
  Description:
2
- The trestle generator (an adaptation of the Rails scaffold generator)
3
- creates a controller to interact with a model. If the model does not exist,
4
- it creates the model as well. The generated code is equivalent to the
5
- "scaffold :model" declaration, making it easy to migrate when you wish to
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. Trestled actions and views are created
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 trestled actions are:
12
+ The trestle actions are:
13
13
  index, new, edit, destroy
14
14
 
15
- The trestled views are:
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
@@ -1,10 +1,10 @@
1
1
  class <%= controller_class_name %>Controller < ApplicationController
2
- verify :only => [ :edit<%= suffix %>, :destroy<%= suffix %> ],
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 untrestled_actions -%>
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 untrestled_actions -%>
16
+ <% for action in nontrestle_actions -%>
17
17
  def test_<%= action %>
18
- get :<%= action %>
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 :<%= suffix || 'index' %>
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 :destroy<%= suffix %>, :id => 1
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 :destroy<%= suffix %>, :id => 1
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 :edit<%= suffix %>, :id => 1
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 :edit<%= suffix %>, :id => 1
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 :<%= suffix || 'index' %>
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 :<%= suffix || 'index' %>, :id => 1
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 :new<%= suffix %>
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 :new<%= suffix %>, :<%= singular_name %> => {}
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
- # Scaffolded forms.
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
- # Scaffolded views.
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
- # Untrestled views.
122
- untrestled_actions.each do |action|
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 untrestled_actions
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.0
7
- date: 2006-01-03
8
- summary: "[Rails] An adaptation of the scaffold generator that produces production-ready
9
- controllers that are safe from state-changing HTTP GET requests and that have
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: "The name of this RubyGem points out that nobody intentionally sends a train
17
- across a gorge with nothing but a scaffold to support it. That�s what a trestle
18
- is for! Why use the trestle generator instead of the scaffold generator? The
19
- trestle generator produces code that is closer to production-quality in two
20
- respects: SAFETY The trestle generator uses the HTTP POST method for actions
21
- that change data. Well-behaved web applications protect themselves against
22
- errant HTTP GET requests (such as come from Google Web Accelerator and the
23
- like). The scaffold generator fails to do this. USABILITY The trestle
24
- generator produces controllers with just four actions (index, new, edit, and
25
- destroy). Controllers produced by the scaffold generator have eight actions.
26
- Fewer actions exposed to the outside world is better if the behavior of these
27
- actions is in line with the semantics of HTTP GET and HTTP POST. The net effect
28
- is that you will not have to throw away or tweak as much trestle-generated code
29
- as you do scaffold-generated code. Less work for you means your application gets
30
- built sooner. Tobias L�tke�s postback_generator RubyGem has the same idea. The
31
- scaffold generator produces a controller with the following public interface for
32
- a database table named �people�: /people - lists existing person records
33
- /people/list - lists existing person records /people/new - shows an empty
34
- person form /people/create - creates a new person record from request
35
- 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 public interface produced by the trestle
40
- generator: /people - lists existing person records /people/new - HTTP GET
41
- shows an empty person form; HTTP POST creates a new person record from request
42
- parameters /people/99 - shows the person record having ID 99 /people/99/edit -
43
- HTTP GET shows a person form for the person record having ID 99; HTTP POST
44
- updates the person record having ID 99 using request parameters
45
- /people/99/destroy - HTTP GET redirects to /people/99/edit with a notice that
46
- the user must click the form�s Destroy button to destroy a record; HTTP POST
47
- deletes the person record having ID 99 after prompting the user for confirmation
48
- Notice the hierarchical nature of trestle URLs. Because the ID comes before the
49
- verb, there are fewer illegal variations that with scaffold URLs. This
50
- encourages the user to use the Up One Level button on the Google Toolbar that
51
- clips one element off the end of the current URL. Scaffold URLs do not play
52
- nicely with the Up One Level button."
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