ajax_scaffold_generator 1.0.0
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/MIT-LICENSE +20 -0
- data/USAGE +31 -0
- data/ajax_scaffold_generator.rb +201 -0
- data/templates/controller.rb +49 -0
- data/templates/form.rhtml +1 -0
- data/templates/form_scaffolding.rhtml +1 -0
- data/templates/functional_test.rb +71 -0
- data/templates/helper.rb +2 -0
- data/templates/layout.rhtml +14 -0
- data/templates/partial_edit.rhtml +13 -0
- data/templates/partial_error.rhtml +3 -0
- data/templates/partial_item.rhtml +16 -0
- data/templates/partial_new.rhtml +13 -0
- data/templates/script.js +47 -0
- data/templates/style.css +74 -0
- data/templates/view_list.rhtml +15 -0
- metadata +65 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2005 Maurycy Pawlowski-Wieronski
|
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/USAGE
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Description:
|
2
|
+
The ajax scaffold generator creates a controller to interact with a model.
|
3
|
+
If the model does not exist, it creates the model as well. Unlike the
|
4
|
+
standard scaffold, the ajax scaffold generator uses AJAX.
|
5
|
+
|
6
|
+
The generator takes a model name, an optional controller name, and a
|
7
|
+
list of views as arguments. Scaffolded actions and views are created
|
8
|
+
automatically. Any views left over generate empty stubs.
|
9
|
+
|
10
|
+
The scaffolded actions are:
|
11
|
+
index, list, new, edit, destroy
|
12
|
+
|
13
|
+
If a controller name is not given, the plural form of the model name
|
14
|
+
will be used. The model and controller names may be given in CamelCase
|
15
|
+
or under_score and should not be suffixed with 'Model' or 'Controller'.
|
16
|
+
Both model and controller names may be prefixed with a module like a
|
17
|
+
file path; see the Modules Example for usage.
|
18
|
+
|
19
|
+
Example:
|
20
|
+
./script/generate ajax_scaffold Account Bank debit credit
|
21
|
+
|
22
|
+
This will generate an Account model and BankController with a full test
|
23
|
+
suite and a basic user interface. Now create the accounts table in your
|
24
|
+
database and browse to http://localhost/bank/ -- voila, you're on Rails!
|
25
|
+
|
26
|
+
Modules Example:
|
27
|
+
./script/generate ajax_scaffold CreditCard 'admin/credit_card' suspend late_fee
|
28
|
+
|
29
|
+
This will generate a CreditCard model and CreditCardController controller
|
30
|
+
in the admin module.
|
31
|
+
|
@@ -0,0 +1,201 @@
|
|
1
|
+
class ScaffoldingSandbox
|
2
|
+
include ActionView::Helpers::ActiveRecordHelper
|
3
|
+
|
4
|
+
attr_accessor :form_action, :singular_name, :suffix, :model_instance
|
5
|
+
|
6
|
+
def sandbox_binding
|
7
|
+
binding
|
8
|
+
end
|
9
|
+
|
10
|
+
def default_input_block
|
11
|
+
Proc.new { |record, column| "<p><label for=\"#{record}_#{column.name}\">#{column.human_name}</label><br/>\n#{input(record, column.name)}</p>\n" }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ActionView::Helpers::InstanceTag
|
16
|
+
def to_input_field_tag(field_type, options={})
|
17
|
+
field_meth = "#{field_type}_field"
|
18
|
+
"<%= #{field_meth} '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+options.inspect} %>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_text_area_tag(options = {})
|
22
|
+
"<%= text_area '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_date_select_tag(options = {})
|
26
|
+
"<%= date_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_datetime_select_tag(options = {})
|
30
|
+
"<%= datetime_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class AjaxScaffoldGenerator < Rails::Generator::NamedBase
|
35
|
+
attr_reader :controller_name,
|
36
|
+
:controller_class_path,
|
37
|
+
:controller_file_path,
|
38
|
+
:controller_class_nesting,
|
39
|
+
:controller_class_nesting_depth,
|
40
|
+
:controller_class_name,
|
41
|
+
:controller_singular_name,
|
42
|
+
:controller_plural_name
|
43
|
+
alias_method :controller_file_name, :controller_singular_name
|
44
|
+
alias_method :controller_table_name, :controller_plural_name
|
45
|
+
|
46
|
+
def initialize(runtime_args, runtime_options = {})
|
47
|
+
super
|
48
|
+
|
49
|
+
@controller_name = args.shift
|
50
|
+
@controller_name ||= ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name
|
51
|
+
|
52
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
53
|
+
@controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
|
54
|
+
|
55
|
+
if @controller_class_nesting.empty?
|
56
|
+
@controller_class_name = @controller_class_name_without_nesting
|
57
|
+
else
|
58
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def manifest
|
63
|
+
record do |m|
|
64
|
+
# Check for class naming collisions.
|
65
|
+
m.class_collisions controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper"
|
66
|
+
|
67
|
+
# Controller, helper, views, and test directories.
|
68
|
+
m.directory File.join('app/controllers', controller_class_path)
|
69
|
+
m.directory File.join('app/helpers', controller_class_path)
|
70
|
+
m.directory File.join('app/views', controller_class_path, controller_file_name)
|
71
|
+
m.directory File.join('test/functional', controller_class_path)
|
72
|
+
|
73
|
+
# Depend on model generator but skip if the model exists.
|
74
|
+
m.dependency 'model', [singular_name], :collision => :skip
|
75
|
+
|
76
|
+
# Scaffolded forms.
|
77
|
+
m.complex_template 'form.rhtml',
|
78
|
+
File.join('app/views',
|
79
|
+
controller_class_path,
|
80
|
+
controller_file_name,
|
81
|
+
'_form.rhtml'),
|
82
|
+
:insert => 'form_scaffolding.rhtml',
|
83
|
+
:sandbox => lambda { create_sandbox },
|
84
|
+
:begin_mark => 'form',
|
85
|
+
:end_mark => 'eoform',
|
86
|
+
:mark_id => singular_name
|
87
|
+
|
88
|
+
# Scaffolded partials.
|
89
|
+
scaffold_partials.each do |action|
|
90
|
+
m.template "partial_#{action}.rhtml",
|
91
|
+
File.join('app/views',
|
92
|
+
controller_class_path,
|
93
|
+
controller_file_name,
|
94
|
+
"_#{action}.rhtml"),
|
95
|
+
:assigns => { :action => action }
|
96
|
+
end
|
97
|
+
|
98
|
+
# Scaffolded views.
|
99
|
+
scaffold_views.each do |action|
|
100
|
+
m.template "view_#{action}.rhtml",
|
101
|
+
File.join('app/views',
|
102
|
+
controller_class_path,
|
103
|
+
controller_file_name,
|
104
|
+
"#{action}.rhtml"),
|
105
|
+
:assigns => { :action => action }
|
106
|
+
end
|
107
|
+
|
108
|
+
# Controller class, functional test, helper, and views.
|
109
|
+
m.template 'controller.rb',
|
110
|
+
File.join('app/controllers',
|
111
|
+
controller_class_path,
|
112
|
+
"#{controller_file_name}_controller.rb")
|
113
|
+
|
114
|
+
m.template 'functional_test.rb',
|
115
|
+
File.join('test/functional',
|
116
|
+
controller_class_path,
|
117
|
+
"#{controller_file_name}_controller_test.rb")
|
118
|
+
|
119
|
+
m.template 'helper.rb',
|
120
|
+
File.join('app/helpers',
|
121
|
+
controller_class_path,
|
122
|
+
"#{controller_file_name}_helper.rb")
|
123
|
+
|
124
|
+
# Layout and stylesheet.
|
125
|
+
m.template 'layout.rhtml', "app/views/layouts/#{controller_file_name}.rhtml"
|
126
|
+
m.template 'script.js', "public/javascripts/#{controller_file_name}.js"
|
127
|
+
m.template 'style.css', 'public/stylesheets/scaffold.css'
|
128
|
+
|
129
|
+
# Unscaffolded views.
|
130
|
+
unscaffolded_actions.each do |action|
|
131
|
+
path = File.join('app/views',
|
132
|
+
controller_class_path,
|
133
|
+
controller_file_name,
|
134
|
+
"#{action}.rhtml")
|
135
|
+
|
136
|
+
m.template 'controller:view.rhtml', path,
|
137
|
+
:assigns => { :action => action, :path => path }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
protected
|
143
|
+
# Override with your own usage banner.
|
144
|
+
def banner
|
145
|
+
"Usage: #{$0} ajax_scaffold ModelName [ControllerName] [action, ...]"
|
146
|
+
end
|
147
|
+
|
148
|
+
def model_name
|
149
|
+
class_name.demodulize
|
150
|
+
end
|
151
|
+
|
152
|
+
def scaffold_actions
|
153
|
+
%w( edit destroy index list new )
|
154
|
+
end
|
155
|
+
|
156
|
+
def scaffold_partials
|
157
|
+
%w( edit error item new )
|
158
|
+
end
|
159
|
+
|
160
|
+
def scaffold_views
|
161
|
+
%w( list )
|
162
|
+
end
|
163
|
+
|
164
|
+
def unscaffolded_actions
|
165
|
+
args - scaffold_actions
|
166
|
+
end
|
167
|
+
|
168
|
+
def suffix
|
169
|
+
"_#{singular_name}" if options[:suffix]
|
170
|
+
end
|
171
|
+
|
172
|
+
def create_sandbox
|
173
|
+
sandbox = ScaffoldingSandbox.new
|
174
|
+
sandbox.singular_name = singular_name
|
175
|
+
|
176
|
+
begin
|
177
|
+
sandbox.model_instance = model_instance
|
178
|
+
sandbox.instance_variable_set("@#{singular_name}", sandbox.model_instance)
|
179
|
+
rescue ActiveRecord::StatementInvalid => e
|
180
|
+
logger.error "Before updating scaffolding from new DB schema, try creating a table for your model (#{class_name})"
|
181
|
+
raise SystemExit
|
182
|
+
end
|
183
|
+
|
184
|
+
sandbox.suffix = suffix
|
185
|
+
sandbox
|
186
|
+
end
|
187
|
+
|
188
|
+
def model_instance
|
189
|
+
base = class_nesting.split('::').inject(Object) do |base, nested|
|
190
|
+
break base.const_get(nested) if base.const_defined?(nested)
|
191
|
+
|
192
|
+
base.const_set(nested, Module.new)
|
193
|
+
end
|
194
|
+
|
195
|
+
unless base.const_defined?(@class_name_without_nesting)
|
196
|
+
base.const_set(@class_name_without_nesting, Class.new(ActiveRecord::Base))
|
197
|
+
end
|
198
|
+
|
199
|
+
class_name.constantize.new
|
200
|
+
end
|
201
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
verify :method => :post, :only => %w( destroy edit new )
|
3
|
+
|
4
|
+
<% unless suffix -%>
|
5
|
+
def index
|
6
|
+
list
|
7
|
+
render :action => 'list'
|
8
|
+
end
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
<% for action in unscaffolded_actions -%>
|
12
|
+
def <%= action %><%= suffix %>
|
13
|
+
end
|
14
|
+
|
15
|
+
<% end -%>
|
16
|
+
def list<%= suffix %>
|
17
|
+
@<%= plural_name %> = <%= model_name %>.find :all
|
18
|
+
end
|
19
|
+
|
20
|
+
def new<%= suffix %>
|
21
|
+
@<%= singular_name %> = <%= model_name %>.new params[:<%= singular_name %>]
|
22
|
+
|
23
|
+
if @<%= singular_name %>.save
|
24
|
+
@headers['<%= model_name %>ID'] = @<%= singular_name %>.id
|
25
|
+
@headers['Content-Type'] = 'text/html; charset=utf-8'
|
26
|
+
|
27
|
+
render :partial => 'item'
|
28
|
+
else
|
29
|
+
render :partial => 'error', :status => 500
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def edit<%= suffix %>
|
34
|
+
@<%= singular_name %> = <%= model_name %>.find params[:id]
|
35
|
+
|
36
|
+
if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
|
37
|
+
@headers['Content-Type'] = 'text/html; charset=utf-8'
|
38
|
+
|
39
|
+
render :partial => 'item'
|
40
|
+
else
|
41
|
+
render :partial => 'error', :status => 500
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy<%= suffix %>
|
46
|
+
<%= model_name %>.find(params[:id]).destroy
|
47
|
+
render :nothing => true
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= template_for_inclusion %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= all_input_tags(@model_instance, @singular_name, {}) %>
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.dirname(__FILE__) + '<%= "/.." * controller_class_nesting_depth %>/../test_helper'
|
2
|
+
require '<%= controller_file_path %>_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
8
|
+
fixtures :<%= table_name %>
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@controller = <%= controller_class_name %>Controller.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
end
|
15
|
+
|
16
|
+
<% for action in unscaffolded_actions -%>
|
17
|
+
def test_<%= action %>
|
18
|
+
get :<%= action %>
|
19
|
+
assert_response :success
|
20
|
+
assert_template '<%= action %>'
|
21
|
+
end
|
22
|
+
|
23
|
+
<% end -%>
|
24
|
+
<% unless suffix -%>
|
25
|
+
def test_index
|
26
|
+
get :index
|
27
|
+
assert_response :success
|
28
|
+
assert_template 'list'
|
29
|
+
end
|
30
|
+
|
31
|
+
<% end -%>
|
32
|
+
def test_list<%= suffix %>
|
33
|
+
get :list<%= suffix %>
|
34
|
+
|
35
|
+
assert_response :success
|
36
|
+
assert_template 'list<%= suffix %>'
|
37
|
+
|
38
|
+
assert_not_nil assigns(:<%= plural_name %>)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_new<%= suffix %>
|
42
|
+
num_<%= plural_name %> = <%= model_name %>.count
|
43
|
+
|
44
|
+
post :new<%= suffix %>, :<%= singular_name %> => {}
|
45
|
+
|
46
|
+
assert_response :success
|
47
|
+
assert_template '_item'
|
48
|
+
|
49
|
+
assert_equal num_<%= plural_name %> + 1, <%= model_name %>.count
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_edit<%= suffix %>
|
53
|
+
post :edit<%= suffix %>, :id => 1
|
54
|
+
|
55
|
+
assert_response :success
|
56
|
+
assert_template '_item'
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_destroy<%= suffix %>
|
60
|
+
assert_not_nil <%= model_name %>.find(1)
|
61
|
+
|
62
|
+
post :destroy<%= suffix %>, :id => 1
|
63
|
+
|
64
|
+
assert_response :success
|
65
|
+
assert_template nil
|
66
|
+
|
67
|
+
assert_raise(ActiveRecord::RecordNotFound) {
|
68
|
+
<%= model_name %>.find(1)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
data/templates/helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title><%= controller_class_name %>: <%%= controller.action_name %></title>
|
4
|
+
<%%= stylesheet_link_tag 'scaffold' %>
|
5
|
+
<%%= javascript_include_tag 'prototype' %>
|
6
|
+
<%%= javascript_include_tag 'effects' %>
|
7
|
+
<%%= javascript_include_tag '<%= singular_name %>' %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%%= @content_for_layout %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<div id="<%%= "edit_<%= singular_name %>_error_#{@<%= singular_name %>.id}" %>">
|
2
|
+
<%%= render :partial => 'error' %>
|
3
|
+
</div>
|
4
|
+
|
5
|
+
<%%= form_remote_tag :url => { :action => 'edit', :id => @<%= singular_name %> },
|
6
|
+
:update => { :success => "<%= singular_name %>_#{@<%= singular_name %>.id}", :failure => "edit_<%= singular_name %>_error_#{@<%= singular_name %>.id}" },
|
7
|
+
:success => "<%= plural_name %>Block.editSuccess(#{@<%= singular_name %>.id})",
|
8
|
+
:html => { :id => "edit_<%= singular_name %>_form_#{@<%= singular_name %>.id}" } %>
|
9
|
+
<%%= render :partial => 'form' %>
|
10
|
+
<%%= submit_tag "Update" %>
|
11
|
+
<%%= end_form_tag %>
|
12
|
+
|
13
|
+
<%%= link_to_function 'Cancel', "<%= plural_name %>Block.editCancel(#{@<%= singular_name %>.id})" %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div id="<%= singular_name %>_<%%= @<%= singular_name %>.id %>">
|
2
|
+
|
3
|
+
<%% for column in <%= model_name %>.content_columns %>
|
4
|
+
<p><b><%%= column.human_name %>:</b> <%%=h @<%= singular_name %>.send(column.name) %></p>
|
5
|
+
<%% end %>
|
6
|
+
|
7
|
+
<%%= link_to_function 'Edit', "<%= plural_name %>Block.edit(#{@<%= singular_name %>.id})" %>
|
8
|
+
<%%= link_to_remote 'Destroy',
|
9
|
+
:url => { :action => 'destroy', :id => @<%= singular_name %> },
|
10
|
+
:complete => visual_effect(:fade, "<%= singular_name %>_#{@<%= singular_name %>.id}"),
|
11
|
+
:confirm => "Are you sure you want to delete this item?" %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div id="edit_<%= singular_name %>_dialog_<%%= @<%= singular_name %>.id %>" style="display: none">
|
15
|
+
<%%= render :partial => 'edit' %>
|
16
|
+
</div>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<div id="add_<%= singular_name %>_error">
|
2
|
+
<%%= render :partial => 'error' %>
|
3
|
+
</div>
|
4
|
+
|
5
|
+
<%%= form_remote_tag :url => { :action => 'new' },
|
6
|
+
:success => '<%= plural_name %>Block.addSuccess(request)',
|
7
|
+
:failure => '<%= plural_name %>Block.addFailure(request)',
|
8
|
+
:html => { :id => 'add_<%= singular_name %>_form' } %>
|
9
|
+
<%%= render :partial => 'form' %>
|
10
|
+
<%%= submit_tag "Create" %>
|
11
|
+
<%%= end_form_tag %>
|
12
|
+
|
13
|
+
<%%= link_to_function 'Cancel', '<%= plural_name %>Block.addCancel()' %>
|
data/templates/script.js
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
var <%= plural_name %>Block = {
|
2
|
+
edit: function(id) {
|
3
|
+
Element.hide('<%= singular_name %>_' + id);
|
4
|
+
Element.show('edit_<%= singular_name %>_dialog_' + id);
|
5
|
+
},
|
6
|
+
|
7
|
+
editSuccess: function(id) {
|
8
|
+
this.editCancel(id);
|
9
|
+
|
10
|
+
new Effect.Highlight('<%= singular_name %>_' + id);
|
11
|
+
},
|
12
|
+
|
13
|
+
editCancel: function(id) {
|
14
|
+
$('edit_<%= singular_name %>_error_' + id).innerHTML = '';
|
15
|
+
|
16
|
+
Element.show('<%= singular_name %>_' + id);
|
17
|
+
Element.hide('edit_<%= singular_name %>_dialog_' + id);
|
18
|
+
},
|
19
|
+
|
20
|
+
add: function() {
|
21
|
+
Element.hide('add_<%= singular_name %>');
|
22
|
+
Element.show('add_<%= singular_name %>_dialog');
|
23
|
+
Form.reset('add_<%= singular_name %>_form');
|
24
|
+
},
|
25
|
+
|
26
|
+
addSuccess: function(request) {
|
27
|
+
this.addCancel();
|
28
|
+
|
29
|
+
new Insertion.Bottom('<%= plural_name %>', request.responseText);
|
30
|
+
new Effect.Highlight('<%= singular_name %>_' + this.getNewId(request));
|
31
|
+
},
|
32
|
+
|
33
|
+
addFailure: function(request) {
|
34
|
+
$('add_<%= singular_name %>_error').innerHTML = request.responseText;
|
35
|
+
},
|
36
|
+
|
37
|
+
addCancel: function() {
|
38
|
+
$('add_<%= singular_name %>_error').innerHTML = '';
|
39
|
+
|
40
|
+
Element.show('add_<%= singular_name %>');
|
41
|
+
Element.hide('add_<%= singular_name %>_dialog');
|
42
|
+
},
|
43
|
+
|
44
|
+
getNewId: function(request) {
|
45
|
+
return request.getResponseHeader('<%= model_name %>ID');
|
46
|
+
}
|
47
|
+
}
|
data/templates/style.css
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
.fieldWithErrors {
|
20
|
+
padding: 2px;
|
21
|
+
background-color: red;
|
22
|
+
display: table;
|
23
|
+
}
|
24
|
+
|
25
|
+
#ErrorExplanation {
|
26
|
+
width: 400px;
|
27
|
+
border: 2px solid 'red';
|
28
|
+
padding: 7px;
|
29
|
+
padding-bottom: 12px;
|
30
|
+
margin-bottom: 20px;
|
31
|
+
background-color: #f0f0f0;
|
32
|
+
}
|
33
|
+
|
34
|
+
#ErrorExplanation h2 {
|
35
|
+
text-align: left;
|
36
|
+
font-weight: bold;
|
37
|
+
padding: 5px 5px 5px 15px;
|
38
|
+
font-size: 12px;
|
39
|
+
margin: -7px;
|
40
|
+
background-color: #c00;
|
41
|
+
color: #fff;
|
42
|
+
}
|
43
|
+
|
44
|
+
#ErrorExplanation p {
|
45
|
+
color: #333;
|
46
|
+
margin-bottom: 0;
|
47
|
+
padding: 5px;
|
48
|
+
}
|
49
|
+
|
50
|
+
#ErrorExplanation ul li {
|
51
|
+
font-size: 12px;
|
52
|
+
list-style: square;
|
53
|
+
}
|
54
|
+
|
55
|
+
div.uploadStatus {
|
56
|
+
margin: 5px;
|
57
|
+
}
|
58
|
+
|
59
|
+
div.progressBar {
|
60
|
+
margin: 5px;
|
61
|
+
}
|
62
|
+
|
63
|
+
div.progressBar div.border {
|
64
|
+
background-color: #fff;
|
65
|
+
border: 1px solid grey;
|
66
|
+
width: 100%;
|
67
|
+
}
|
68
|
+
|
69
|
+
div.progressBar div.background {
|
70
|
+
background-color: #333;
|
71
|
+
height: 18px;
|
72
|
+
width: 0%;
|
73
|
+
}
|
74
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h1>Listing <%= plural_name %></h1>
|
2
|
+
|
3
|
+
<div id="add_<%= singular_name %>">
|
4
|
+
<%%= link_to_function 'New <%= singular_name %>', "<%= plural_name %>Block.add()" %>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div id="add_<%= singular_name %>_dialog" style="display: none">
|
8
|
+
<%%= render :partial => 'new' %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div id="<%= plural_name %>">
|
12
|
+
<%% for @<%= singular_name %> in @<%= plural_name %>%>
|
13
|
+
<%%= render :partial => 'item' %>
|
14
|
+
<%% end -%>
|
15
|
+
</div>
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: ajax_scaffold_generator
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2005-11-30 00:00:00 +01:00
|
8
|
+
summary: "[Rails] Ajax scaffold."
|
9
|
+
require_paths:
|
10
|
+
- "."
|
11
|
+
email: maurycypw@gmail.com
|
12
|
+
homepage: http://www.rubyonrails.org/show/Generators
|
13
|
+
rubyforge_project:
|
14
|
+
description: "This is the generator for a Ruby on Rails framework, that creates scaffold for
|
15
|
+
AJAX applications."
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: false
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
-
|
23
|
+
- ">"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.0
|
26
|
+
version:
|
27
|
+
platform: ruby
|
28
|
+
signing_key:
|
29
|
+
cert_chain:
|
30
|
+
authors:
|
31
|
+
- Maurycy Pawlowski-Wieronski
|
32
|
+
files:
|
33
|
+
- MIT-LICENSE
|
34
|
+
- USAGE
|
35
|
+
- ajax_scaffold_generator.rb
|
36
|
+
- templates/controller.rb
|
37
|
+
- templates/form.rhtml
|
38
|
+
- templates/form_scaffolding.rhtml
|
39
|
+
- templates/functional_test.rb
|
40
|
+
- templates/helper.rb
|
41
|
+
- templates/layout.rhtml
|
42
|
+
- templates/partial_edit.rhtml
|
43
|
+
- templates/partial_error.rhtml
|
44
|
+
- templates/partial_item.rhtml
|
45
|
+
- templates/partial_new.rhtml
|
46
|
+
- templates/script.js
|
47
|
+
- templates/style.css
|
48
|
+
- templates/view_list.rhtml
|
49
|
+
test_files: []
|
50
|
+
rdoc_options: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
requirements: []
|
55
|
+
dependencies:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rails
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
60
|
+
requirements:
|
61
|
+
-
|
62
|
+
- ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.10.0
|
65
|
+
version:
|