ajax_scaffold_generator 3.1.4 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,8 +1,13 @@
1
1
 
2
2
  3.1.4 =========
3
3
 
4
+ * Updated the functional and unit tests to patch some variable issues: <%= class_name %> used
5
+ instead of <%= singular_name %>. (Nic Williams)
6
+
7
+ 3.1.4 =========
8
+
4
9
  * Removed some vestigal CSS styling of textarea's that was setting the height
5
- * Added unit and functional tests (Thanks to Nic Williams)
10
+ * Added unit and functional tests (Nic Williams)
6
11
  * Fixed bug with CamelCased model names not being converted to underscored names correctly
7
12
 
8
13
  3.1.3 =========
data/MIT-LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2006 Richard White
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2006 Richard White
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README CHANGED
@@ -1,32 +1,32 @@
1
- *******************************************************************************************
2
- ** For all documentation see the project website: http://www.ajaxscaffold.com **
3
- *******************************************************************************************
4
-
5
- Description:
6
- The ajax scaffold generator creates a controller to interact with a model.
7
- If the model does not exist, it creates the model as well. Unlike the
8
- standard scaffold, the ajax scaffold generator uses AJAX.
9
-
10
- The generator takes a model name, an optional controller name, and a
11
- list of views as arguments. Scaffolded actions and views are created
12
- automatically. Any views left over generate empty stubs.
13
-
14
- If a controller name is not given, the plural form of the model name
15
- will be used. The model and controller names may be given in CamelCase
16
- or under_score and should not be suffixed with 'Model' or 'Controller'.
17
- Both model and controller names may be prefixed with a module like a
18
- file path; see the Modules Example for usage.
19
-
20
- Example:
21
- ./script/generate ajax_scaffold Account Bank debit credit
22
-
23
- This will generate an Account model and BankController with a full test
24
- suite and a basic user interface. Now create the accounts table in your
25
- database and browse to http://localhost/bank/ -- voila, you're on Rails!
26
-
27
- Modules Example:
28
- ./script/generate ajax_scaffold CreditCard 'admin/credit_card' suspend late_fee
29
-
30
- This will generate a CreditCard model and CreditCardController controller
31
- in the admin module.
32
-
1
+ *******************************************************************************************
2
+ ** For all documentation see the project website: http://www.ajaxscaffold.com **
3
+ *******************************************************************************************
4
+
5
+ Description:
6
+ The ajax scaffold generator creates a controller to interact with a model.
7
+ If the model does not exist, it creates the model as well. Unlike the
8
+ standard scaffold, the ajax scaffold generator uses AJAX.
9
+
10
+ The generator takes a model name, an optional controller name, and a
11
+ list of views as arguments. Scaffolded actions and views are created
12
+ automatically. Any views left over generate empty stubs.
13
+
14
+ If a controller name is not given, the plural form of the model name
15
+ will be used. The model and controller names may be given in CamelCase
16
+ or under_score and should not be suffixed with 'Model' or 'Controller'.
17
+ Both model and controller names may be prefixed with a module like a
18
+ file path; see the Modules Example for usage.
19
+
20
+ Example:
21
+ ./script/generate ajax_scaffold Account Bank debit credit
22
+
23
+ This will generate an Account model and BankController with a full test
24
+ suite and a basic user interface. Now create the accounts table in your
25
+ database and browse to http://localhost/bank/ -- voila, you're on Rails!
26
+
27
+ Modules Example:
28
+ ./script/generate ajax_scaffold CreditCard 'admin/credit_card' suspend late_fee
29
+
30
+ This will generate a CreditCard model and CreditCardController controller
31
+ in the admin module.
32
+
@@ -1,201 +1,201 @@
1
- require "rails_generator/generators/components/scaffold/scaffold_generator"
2
-
3
- class AjaxScaffoldingSandbox < ScaffoldingSandbox
4
- def default_input_block
5
- Proc.new { |record, column| "<div class=\"form-element\">\n <label for=\"#{record}_#{column.name}\">#{column.human_name}</label>\n #{input(record, column.name)}\n</div>\n" }
6
- end
7
-
8
- def all_input_tags(record, record_name, options)
9
- input_block = options[:input_block] || default_input_block
10
-
11
- if !options[:exclude].blank?
12
- filtered_content_columns = record.class.content_columns.reject { |column| options[:exclude].include?(column.name) }
13
- else
14
- filtered_content_columns = record.class.content_columns
15
- end
16
-
17
- filtered_content_columns.collect{ |column| input_block.call(record_name, column) }.join("\n")
18
- end
19
-
20
- end
21
-
22
- class ActionView::Helpers::InstanceTag
23
- alias_method :base_to_input_field_tag, :to_input_field_tag
24
-
25
- def to_input_field_tag(field_type, options={})
26
- options[:class] = 'text-input'
27
- base_to_input_field_tag field_type, options
28
- end
29
-
30
- def to_boolean_select_tag(options = {})
31
- options = options.stringify_keys
32
- add_default_name_and_id(options)
33
- tag_text = "<%= select \"#{@object_name}\", \"#{@method_name}\", [[\"True\", true], [\"False\", false]], { :selected => @#{@object_name}.#{@method_name} } %>"
34
- end
35
-
36
- end
37
-
38
- class AjaxScaffoldGenerator < ScaffoldGenerator
39
-
40
- alias_method :base_controller_file_path, :controller_file_path
41
-
42
- def controller_file_path
43
- "/" + base_controller_file_path
44
- end
45
-
46
- def manifest
47
-
48
- record do |m|
49
-
50
- # Check for class naming collisions.
51
- m.class_collisions controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper"
52
- m.class_collisions class_path, class_name, "#{singular_name}Test"
53
-
54
- # Model, controller, helper, views, and test directories.
55
- m.directory File.join('test/unit', class_path)
56
- m.directory File.join('test/fixtures', class_path)
57
- m.directory File.join('app/controllers', controller_class_path)
58
- m.directory File.join('app/helpers', controller_class_path)
59
- m.directory File.join('app/views', controller_class_path, controller_file_name)
60
- m.directory File.join('app/views/layouts', controller_class_path)
61
- m.directory File.join('public/images')
62
- m.directory File.join('test/functional', controller_class_path)
63
-
64
- # Model class, unit test, and fixtures.
65
- m.template 'model.rb', File.join('app/models', "#{singular_name}.rb")
66
- m.template 'unit_test.rb', File.join('test/unit', "#{singular_name}_test.rb")
67
- m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
68
-
69
- # Scaffolded forms.
70
- m.complex_template 'form.rhtml',
71
- File.join('app/views',
72
- controller_class_path,
73
- controller_file_name,
74
- '_form.rhtml'),
75
- :insert => 'form_scaffolding.rhtml',
76
- :sandbox => lambda { create_sandbox },
77
- :begin_mark => 'form',
78
- :end_mark => 'eoform',
79
- :mark_id => singular_name
80
-
81
- # Scaffolded partials.
82
- m.template "partial_item.rhtml",
83
- File.join('app/views',
84
- controller_class_path,
85
- controller_file_name,
86
- "_#{singular_name}.rhtml")
87
-
88
- scaffold_partials.each do |name|
89
- m.template "partial_#{name}.rhtml",
90
- File.join('app/views',
91
- controller_class_path,
92
- controller_file_name,
93
- "_#{name}.rhtml")
94
- end
95
-
96
- # Scaffolded views.
97
- scaffold_views.each do |action|
98
- m.template "view_#{action}.rhtml",
99
- File.join('app/views',
100
- controller_class_path,
101
- controller_file_name,
102
- "#{action}.rhtml"),
103
- :assigns => { :action => action }
104
- end
105
-
106
- # RJS templates
107
- scaffold_rjs_templates.each do |template|
108
- m.template "rjs_#{template}.rjs",
109
- File.join('app/views',
110
- controller_class_path,
111
- controller_file_name,
112
- "#{template}.rjs")
113
- end
114
-
115
- # Libraries
116
- scaffold_lib.each do |filename|
117
- m.template "lib_#{filename}.rb",
118
- File.join('lib',
119
- "#{filename}.rb")
120
- end
121
-
122
- # Controller class, functional test, helper, and views.
123
- m.template 'controller.rb',
124
- File.join('app/controllers',
125
- controller_class_path,
126
- "#{controller_file_name}_controller.rb")
127
-
128
- m.template 'functional_test.rb',
129
- File.join('test/functional',
130
- controller_class_path,
131
- "#{controller_file_name}_controller_test.rb")
132
-
133
- m.template 'helper.rb',
134
- File.join('app/helpers',
135
- controller_class_path,
136
- "#{controller_file_name}_helper.rb")
137
-
138
- # Layout and stylesheet.
139
- m.template 'layout.rhtml',
140
- File.join('app/views/layouts',
141
- controller_class_path,
142
- "#{controller_file_name}.rhtml")
143
-
144
- m.template 'ajax_scaffold.css', "public/stylesheets/ajax_scaffold.css"
145
-
146
- scaffold_javascripts.each do |javascript|
147
- m.template javascript, "public/javascripts/#{javascript}"
148
- end
149
-
150
- scaffold_images.each do |image|
151
- m.template image, "public/images/#{image}"
152
- end
153
-
154
- end
155
- end
156
-
157
- protected
158
- # Override with your own usage banner.
159
- def banner
160
- "Usage: #{$0} ajax_scaffold ModelName [ControllerName]"
161
- end
162
-
163
- def scaffold_views
164
- %w( list component )
165
- end
166
-
167
- def scaffold_rjs_templates
168
- %w( create destroy edit new update cancel )
169
- end
170
-
171
- def scaffold_partials
172
- %w( form_messages messages column_headings new_edit pagination_links )
173
- end
174
-
175
- def scaffold_lib
176
- %w( ajax_scaffold )
177
- end
178
-
179
- def scaffold_images
180
- %w( indicator.gif indicator-small.gif add.gif error.gif warning.gif information.gif arrow_down.gif arrow_up.gif )
181
- end
182
-
183
- def scaffold_javascripts
184
- %w( ajax_scaffold.js rico_corner.js )
185
- end
186
-
187
- def create_sandbox
188
- sandbox = AjaxScaffoldingSandbox.new
189
- sandbox.singular_name = singular_name
190
- begin
191
- sandbox.model_instance = model_instance
192
- sandbox.instance_variable_set("@#{singular_name}", sandbox.model_instance)
193
- rescue ActiveRecord::StatementInvalid => e
194
- logger.error "Before updating scaffolding from new DB schema, try creating a table for your model (#{class_name})"
195
- raise SystemExit
196
- end
197
- sandbox.suffix = suffix
198
- sandbox
199
- end
200
-
201
- end
1
+ require "rails_generator/generators/components/scaffold/scaffold_generator"
2
+
3
+ class AjaxScaffoldingSandbox < ScaffoldingSandbox
4
+ def default_input_block
5
+ Proc.new { |record, column| "<div class=\"form-element\">\n <label for=\"#{record}_#{column.name}\">#{column.human_name}</label>\n #{input(record, column.name)}\n</div>\n" }
6
+ end
7
+
8
+ def all_input_tags(record, record_name, options)
9
+ input_block = options[:input_block] || default_input_block
10
+
11
+ if !options[:exclude].blank?
12
+ filtered_content_columns = record.class.content_columns.reject { |column| options[:exclude].include?(column.name) }
13
+ else
14
+ filtered_content_columns = record.class.content_columns
15
+ end
16
+
17
+ filtered_content_columns.collect{ |column| input_block.call(record_name, column) }.join("\n")
18
+ end
19
+
20
+ end
21
+
22
+ class ActionView::Helpers::InstanceTag
23
+ alias_method :base_to_input_field_tag, :to_input_field_tag
24
+
25
+ def to_input_field_tag(field_type, options={})
26
+ options[:class] = 'text-input'
27
+ base_to_input_field_tag field_type, options
28
+ end
29
+
30
+ def to_boolean_select_tag(options = {})
31
+ options = options.stringify_keys
32
+ add_default_name_and_id(options)
33
+ tag_text = "<%= select \"#{@object_name}\", \"#{@method_name}\", [[\"True\", true], [\"False\", false]], { :selected => @#{@object_name}.#{@method_name} } %>"
34
+ end
35
+
36
+ end
37
+
38
+ class AjaxScaffoldGenerator < ScaffoldGenerator
39
+
40
+ alias_method :base_controller_file_path, :controller_file_path
41
+
42
+ def controller_file_path
43
+ "/" + base_controller_file_path
44
+ end
45
+
46
+ def manifest
47
+
48
+ record do |m|
49
+
50
+ # Check for class naming collisions.
51
+ m.class_collisions controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper"
52
+ m.class_collisions class_path, class_name, "#{singular_name}Test"
53
+
54
+ # Model, controller, helper, views, and test directories.
55
+ m.directory File.join('test/unit', class_path)
56
+ m.directory File.join('test/fixtures', class_path)
57
+ m.directory File.join('app/controllers', controller_class_path)
58
+ m.directory File.join('app/helpers', controller_class_path)
59
+ m.directory File.join('app/views', controller_class_path, controller_file_name)
60
+ m.directory File.join('app/views/layouts', controller_class_path)
61
+ m.directory File.join('public/images')
62
+ m.directory File.join('test/functional', controller_class_path)
63
+
64
+ # Model class, unit test, and fixtures.
65
+ m.template 'model.rb', File.join('app/models', "#{singular_name}.rb")
66
+ m.template 'unit_test.rb', File.join('test/unit', "#{singular_name}_test.rb")
67
+ m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
68
+
69
+ # Scaffolded forms.
70
+ m.complex_template 'form.rhtml',
71
+ File.join('app/views',
72
+ controller_class_path,
73
+ controller_file_name,
74
+ '_form.rhtml'),
75
+ :insert => 'form_scaffolding.rhtml',
76
+ :sandbox => lambda { create_sandbox },
77
+ :begin_mark => 'form',
78
+ :end_mark => 'eoform',
79
+ :mark_id => singular_name
80
+
81
+ # Scaffolded partials.
82
+ m.template "partial_item.rhtml",
83
+ File.join('app/views',
84
+ controller_class_path,
85
+ controller_file_name,
86
+ "_#{singular_name}.rhtml")
87
+
88
+ scaffold_partials.each do |name|
89
+ m.template "partial_#{name}.rhtml",
90
+ File.join('app/views',
91
+ controller_class_path,
92
+ controller_file_name,
93
+ "_#{name}.rhtml")
94
+ end
95
+
96
+ # Scaffolded views.
97
+ scaffold_views.each do |action|
98
+ m.template "view_#{action}.rhtml",
99
+ File.join('app/views',
100
+ controller_class_path,
101
+ controller_file_name,
102
+ "#{action}.rhtml"),
103
+ :assigns => { :action => action }
104
+ end
105
+
106
+ # RJS templates
107
+ scaffold_rjs_templates.each do |template|
108
+ m.template "rjs_#{template}.rjs",
109
+ File.join('app/views',
110
+ controller_class_path,
111
+ controller_file_name,
112
+ "#{template}.rjs")
113
+ end
114
+
115
+ # Libraries
116
+ scaffold_lib.each do |filename|
117
+ m.template "lib_#{filename}.rb",
118
+ File.join('lib',
119
+ "#{filename}.rb")
120
+ end
121
+
122
+ # Controller class, functional test, helper, and views.
123
+ m.template 'controller.rb',
124
+ File.join('app/controllers',
125
+ controller_class_path,
126
+ "#{controller_file_name}_controller.rb")
127
+
128
+ m.template 'functional_test.rb',
129
+ File.join('test/functional',
130
+ controller_class_path,
131
+ "#{controller_file_name}_controller_test.rb")
132
+
133
+ m.template 'helper.rb',
134
+ File.join('app/helpers',
135
+ controller_class_path,
136
+ "#{controller_file_name}_helper.rb")
137
+
138
+ # Layout and stylesheet.
139
+ m.template 'layout.rhtml',
140
+ File.join('app/views/layouts',
141
+ controller_class_path,
142
+ "#{controller_file_name}.rhtml")
143
+
144
+ m.template 'ajax_scaffold.css', "public/stylesheets/ajax_scaffold.css"
145
+
146
+ scaffold_javascripts.each do |javascript|
147
+ m.template javascript, "public/javascripts/#{javascript}"
148
+ end
149
+
150
+ scaffold_images.each do |image|
151
+ m.template image, "public/images/#{image}"
152
+ end
153
+
154
+ end
155
+ end
156
+
157
+ protected
158
+ # Override with your own usage banner.
159
+ def banner
160
+ "Usage: #{$0} ajax_scaffold ModelName [ControllerName]"
161
+ end
162
+
163
+ def scaffold_views
164
+ %w( list component )
165
+ end
166
+
167
+ def scaffold_rjs_templates
168
+ %w( create destroy edit new update cancel )
169
+ end
170
+
171
+ def scaffold_partials
172
+ %w( form_messages messages column_headings new_edit pagination_links )
173
+ end
174
+
175
+ def scaffold_lib
176
+ %w( ajax_scaffold )
177
+ end
178
+
179
+ def scaffold_images
180
+ %w( indicator.gif indicator-small.gif add.gif error.gif warning.gif information.gif arrow_down.gif arrow_up.gif )
181
+ end
182
+
183
+ def scaffold_javascripts
184
+ %w( ajax_scaffold.js rico_corner.js )
185
+ end
186
+
187
+ def create_sandbox
188
+ sandbox = AjaxScaffoldingSandbox.new
189
+ sandbox.singular_name = singular_name
190
+ begin
191
+ sandbox.model_instance = model_instance
192
+ sandbox.instance_variable_set("@#{singular_name}", sandbox.model_instance)
193
+ rescue ActiveRecord::StatementInvalid => e
194
+ logger.error "Before updating scaffolding from new DB schema, try creating a table for your model (#{class_name})"
195
+ raise SystemExit
196
+ end
197
+ sandbox.suffix = suffix
198
+ sandbox
199
+ end
200
+
201
+ end