ajax_scaffold_generator 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -20
- data/{USAGE → README} +28 -31
- data/ajax_scaffold_generator.rb +123 -201
- data/templates/add.gif +0 -0
- data/templates/controller.rb +61 -49
- data/templates/error.gif +0 -0
- data/templates/form.rhtml +5 -1
- data/templates/functional_test.rb +88 -71
- data/templates/helper.rb +12 -2
- data/templates/indicator.gif +0 -0
- data/templates/layout.rhtml +15 -14
- data/templates/partial_form_errors.rhtml +9 -0
- data/templates/partial_item.rhtml +25 -16
- data/templates/rico_corner.js +781 -0
- data/templates/script.js +327 -47
- data/templates/style.css +324 -74
- data/templates/view_edit.rhtml +22 -0
- data/templates/view_index.rhtml +1 -0
- data/templates/view_list.rhtml +53 -15
- data/templates/view_new.rhtml +22 -0
- metadata +32 -39
- data/templates/partial_edit.rhtml +0 -13
- data/templates/partial_error.rhtml +0 -3
- data/templates/partial_new.rhtml +0 -13
@@ -1,71 +1,88 @@
|
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
post :
|
54
|
-
|
55
|
-
assert_response :
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
assert_response :success
|
65
|
-
assert_template
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
+
get :new<%= suffix %>
|
43
|
+
|
44
|
+
assert_response :success
|
45
|
+
assert_template 'new<%= suffix %>'
|
46
|
+
|
47
|
+
assert_not_nil assigns(:<%= singular_name %>)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_create
|
51
|
+
num_<%= plural_name %> = <%= model_name %>.count
|
52
|
+
|
53
|
+
post :create<%= suffix %>, :<%= singular_name %> => {}
|
54
|
+
|
55
|
+
assert_response :redirect
|
56
|
+
assert_redirected_to :action => 'list<%= suffix %>'
|
57
|
+
|
58
|
+
assert_equal num_<%= plural_name %> + 1, <%= model_name %>.count
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_edit<%= suffix %>
|
62
|
+
get :edit<%= suffix %>, :id => 1
|
63
|
+
|
64
|
+
assert_response :success
|
65
|
+
assert_template 'edit<%= suffix %>'
|
66
|
+
|
67
|
+
assert_not_nil assigns(:<%= singular_name %>)
|
68
|
+
assert assigns(:<%= singular_name %>).valid?
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_update<%= suffix %>
|
72
|
+
post :update<%= suffix %>, :id => 1
|
73
|
+
assert_response :redirect
|
74
|
+
assert_redirected_to :action => 'show<%= suffix %>', :id => 1
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_destroy<%= suffix %>
|
78
|
+
assert_not_nil <%= model_name %>.find(1)
|
79
|
+
|
80
|
+
post :destroy, :id => 1
|
81
|
+
assert_response :redirect
|
82
|
+
assert_redirected_to :action => 'list<%= suffix %>'
|
83
|
+
|
84
|
+
assert_raise(ActiveRecord::RecordNotFound) {
|
85
|
+
<%= model_name %>.find(1)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
data/templates/helper.rb
CHANGED
@@ -1,2 +1,12 @@
|
|
1
|
-
module <%= controller_class_name %>Helper
|
2
|
-
|
1
|
+
module <%= controller_class_name %>Helper
|
2
|
+
|
3
|
+
def num_columns
|
4
|
+
<%= model_name %>.content_columns.length + 1
|
5
|
+
end
|
6
|
+
|
7
|
+
# This can be moved into application_helper.rb
|
8
|
+
def loading_indicator_tag(scope,id)
|
9
|
+
"<img src=\"/images/indicator.gif\" style=\"display: none;\" id=\"#{scope}-#{id}-loading-indicator\" alt=\"loading indicator\" class=\"loading-indicator\" />"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
Binary file
|
data/templates/layout.rhtml
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<%%=
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
</
|
1
|
+
<!DOCTYPE html
|
2
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
5
|
+
<head>
|
6
|
+
<title><%= Inflector.titleize(plural_name) %></title>
|
7
|
+
<%%= stylesheet_link_tag 'ajax_scaffold', :media => 'all' %>
|
8
|
+
<%%= javascript_include_tag 'prototype', 'effects', 'rico_corner', 'ajax_scaffold' %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<%%= @content_for_layout %>
|
13
|
+
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%% unless @<%= singular_name %>.nil? %>
|
2
|
+
<%%= error_messages_for '<%= singular_name %>' %>
|
3
|
+
<%% end -%>
|
4
|
+
|
5
|
+
<%% for name in [:notice, :warning, :error, :message] %>
|
6
|
+
<%% if @flash[name] %>
|
7
|
+
<%%= "<div class=\"#{name}\">#{@flash[name]}</div>" %>
|
8
|
+
<%% end %>
|
9
|
+
<%% end %>
|
@@ -1,16 +1,25 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<%%=
|
8
|
-
<%%= link_to_remote
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
<%%=
|
16
|
-
|
1
|
+
<tr id="view-<%= singular_name %>-<%%= <%= singular_name %>.id %>">
|
2
|
+
<%% for column in <%= model_name %>.content_columns %>
|
3
|
+
<td><%%=h <%= singular_name %>.send(column.name) %> </td>
|
4
|
+
<%% end %>
|
5
|
+
<td class="actions">
|
6
|
+
<div>
|
7
|
+
<%%= loading_indicator_tag '<%= singular_name %>', "edit-#{<%= singular_name %>.id}" %>
|
8
|
+
<%%= link_to_remote "Edit",
|
9
|
+
:url => { :controller => '<%= controller_name %>', :action => 'edit', :id => <%= singular_name %> },
|
10
|
+
:loading => "AjaxScaffold.editOnLoading(request,'<%= singular_name %>', #{<%= singular_name %>.id});",
|
11
|
+
:success => "AjaxScaffold.editOnSuccess(request,'<%= singular_name %>', #{<%= singular_name %>.id});",
|
12
|
+
:failure => "AjaxScaffold.editOnFailure(request,'<%= singular_name %>', #{<%= singular_name %>.id});",
|
13
|
+
:complete => "AjaxScaffold.editOnComplete(request,'<%= singular_name %>', #{<%= singular_name %>.id});",
|
14
|
+
:post => true; %>
|
15
|
+
<%%= link_to_remote "Delete",
|
16
|
+
:url => { :controller => '<%= controller_name %>',:action => 'destroy', :id => <%= singular_name %> },
|
17
|
+
:confirm => 'Are you sure?',
|
18
|
+
:loading => "AjaxScaffold.deleteOnLoading('<%= singular_name %>', #{<%= singular_name %>.id});",
|
19
|
+
:success => "AjaxScaffold.deleteOnSuccess('<%= singular_name %>', #{<%= singular_name %>.id});",
|
20
|
+
:failure => "AjaxScaffold.deleteOnFailure('<%= singular_name %>', #{<%= singular_name %>.id});",
|
21
|
+
:complete => "AjaxScaffold.deleteOnComplete('<%= singular_name %>', #{<%= singular_name %>.id});",
|
22
|
+
:post => true; %>
|
23
|
+
</div>
|
24
|
+
</td>
|
25
|
+
</tr>
|