ajax_scaffold_generator 3.1.5 → 3.1.6
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/CHANGELOG +14 -7
- data/MIT-LICENSE +20 -20
- data/README +5 -30
- data/ajax_scaffold_generator.rb +201 -201
- data/templates/add.gif +0 -0
- data/templates/ajax_scaffold.css +476 -479
- data/templates/ajax_scaffold.js +125 -125
- data/templates/controller.rb +135 -135
- data/templates/form.rhtml +3 -3
- data/templates/functional_test.rb +6 -6
- data/templates/indicator-small.gif +0 -0
- data/templates/indicator.gif +0 -0
- data/templates/lib_ajax_scaffold.rb +218 -218
- data/templates/partial_column_headings.rhtml +16 -16
- data/templates/partial_item.rhtml +22 -22
- data/templates/partial_new_edit.rhtml +39 -39
- data/templates/partial_pagination_links.rhtml +15 -15
- data/templates/rjs_cancel.rjs +11 -11
- data/templates/unit_test.rb +53 -53
- data/templates/view_component.rhtml +49 -49
- data/templates/warning.gif +0 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
3.1.6 =========
|
1
2
|
|
2
|
-
|
3
|
+
* Added two attributes to scaffold_column
|
4
|
+
:sanitize => Should the output of the column be sanitized of HTML elements (default: true)
|
5
|
+
:class_name => Class added to all TD and TH elements for this column
|
6
|
+
* Fixed bug that was causing short circuiting format_column and not doing standard formatting of dates and times
|
7
|
+
* Fixed bug with CSS image paths not working when the containing application was deployed in a subdirectory
|
8
|
+
|
9
|
+
3.1.5 =========
|
3
10
|
|
4
|
-
* Updated the functional and unit tests to patch some variable issues: <%= class_name %> used
|
11
|
+
* Updated the functional and unit tests to patch some variable issues: <%= class_name %> used
|
5
12
|
instead of <%= singular_name %>. (Nic Williams)
|
6
13
|
|
7
14
|
3.1.4 =========
|
@@ -31,7 +38,7 @@
|
|
31
38
|
|
32
39
|
3.1.1 =========
|
33
40
|
|
34
|
-
* Fixed two bugs with :eval and :sort_sql introspection in ScaffoldColumn. Should fix problems people have been having with
|
41
|
+
* Fixed two bugs with :eval and :sort_sql introspection in ScaffoldColumn. Should fix problems people have been having with
|
35
42
|
underscored table names.
|
36
43
|
* Made the code that gets the @sort_by for a component more robust so that invalid values in the session doesn't continue
|
37
44
|
to hose scaffolds.
|
@@ -41,20 +48,20 @@
|
|
41
48
|
* Added support for defining your own scaffold columns in models by assigning an array of ScaffoldColumn's to @scaffold_columns.
|
42
49
|
If @scaffold_columns is not defined it will be created defaulting to columns for model.content_columns. See more about
|
43
50
|
ScaffoldColumns in lib/ajax_scaffold.rb or by reading the documentation on the site. Model classes now must "require 'ajax_scaffold'"
|
44
|
-
to support this new functionality.
|
51
|
+
to support this new functionality.
|
45
52
|
* Added cancel as an action. There was enough inline code in _new_edit.rhtml that I thought, for consistency, it should be
|
46
53
|
refactored into a server-side method.
|
47
|
-
* Refactoring: All common server side code has been moved into lib/ajax_scaffold.rb.
|
54
|
+
* Refactoring: All common server side code has been moved into lib/ajax_scaffold.rb.
|
48
55
|
This replaces the previous helpers/ajax_scaffold_helper.rb with an include in the helpers to AjaxScaffold::Helper
|
49
56
|
* Changed CSS styling of sorted columns to a more subtle darker blue from the yellow
|
50
57
|
|
51
58
|
3.0.4 =========
|
52
59
|
|
53
|
-
* Pagination loading indicator was not being namespaced using the scaffold_id. Caused all pagination loaders to show when
|
60
|
+
* Pagination loading indicator was not being namespaced using the scaffold_id. Caused all pagination loaders to show when
|
54
61
|
any pagination links were clicked.
|
55
62
|
* Fixed more issues related to controllers in subdirectories. Relative path controller names caused problems as well so
|
56
63
|
all url hashes now have a leading / on all controller names
|
57
|
-
|
64
|
+
|
58
65
|
3.0.3 =========
|
59
66
|
|
60
67
|
* Fixed a bug where destroy.rjs was throwing element not found errors
|
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,7 @@
|
|
1
|
-
|
2
|
-
** For all documentation see the project website: http://www.ajaxscaffold.com
|
3
|
-
|
1
|
+
********************************************************************************
|
2
|
+
** For all documentation see the project website: http://www.ajaxscaffold.com **
|
3
|
+
********************************************************************************
|
4
4
|
|
5
|
-
|
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.
|
5
|
+
Ajax Scaffold generator by Richard White (rrwhite@gmail.com)
|
32
6
|
|
7
|
+
Released under the MIT license (included)
|
data/ajax_scaffold_generator.rb
CHANGED
@@ -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
|
data/templates/add.gif
CHANGED
Binary file
|