schofield 0.0.6 → 0.0.7
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/VERSION +1 -1
- data/generators/schofield_controller/schofield_controller_generator.rb +17 -3
- data/generators/schofield_controller/templates/nested/controller.rb +22 -11
- data/generators/schofield_controller/templates/nested/show.rb +0 -1
- data/generators/schofield_controller/templates/unnested/controller.rb +21 -10
- data/generators/schofield_controller/templates/unnested/show.rb +5 -3
- data/schofield.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
@@ -13,7 +13,9 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
|
|
13
13
|
def manifest
|
14
14
|
record do |m|
|
15
15
|
|
16
|
-
|
16
|
+
|
17
|
+
|
18
|
+
template_directory = has_parent? ? 'nested' : 'unnested'
|
17
19
|
|
18
20
|
sco_class = class_name.gsub('Admin::', '').singularize
|
19
21
|
sco_humanized_uc = sco_class.underscore.humanize
|
@@ -21,11 +23,11 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
|
|
21
23
|
sco_underscored_plural = sco_underscored.pluralize
|
22
24
|
sco_titleized_plural = sco_underscored.pluralize.titleize
|
23
25
|
sco_humanized = sco_humanized_uc.downcase
|
24
|
-
sco_parent_class =
|
26
|
+
sco_parent_class = has_parent? ? options[:parent].classify : ''
|
25
27
|
sco_parent_underscored = sco_parent_class.underscore.downcase
|
26
28
|
sco_parent_underscored_plural = sco_parent_underscored.pluralize
|
27
29
|
sco_parent_titleized_plural = sco_parent_underscored.titleize.pluralize
|
28
|
-
sco_child_class =
|
30
|
+
sco_child_class = has_child? ? options[:child].classify : ''
|
29
31
|
sco_child_underscored = sco_child_class.underscore.downcase
|
30
32
|
sco_child_underscored_plural = sco_child_underscored.pluralize
|
31
33
|
sco_child_titleized_plural = sco_child_underscored.titleize.pluralize
|
@@ -118,6 +120,18 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
|
|
118
120
|
opt.on('--parent PARENT', 'Specify the parent model') { |v| options[:parent] = v if v.present? }
|
119
121
|
opt.on('--child CHILD', 'Specify the child model') { |v| options[:child] = v if v.present? }
|
120
122
|
end
|
123
|
+
|
124
|
+
def has_parent?
|
125
|
+
options[:parent].present?
|
126
|
+
end
|
127
|
+
|
128
|
+
def has_child?
|
129
|
+
options[:child].present?
|
130
|
+
end
|
131
|
+
|
132
|
+
def filter_actions array
|
133
|
+
array.map { |item| actions.include?(item) ? ":#{item}" : nil }.compact.join(', ')
|
134
|
+
end
|
121
135
|
|
122
136
|
def banner
|
123
137
|
"Usage: #{$0} schofield_controller ControllerName [--parent PARENT]"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class <%= class_name %>Controller < Admin::AdminController
|
2
2
|
|
3
|
-
before_filter :find_<%= sco_underscored %>, :only => [
|
4
|
-
before_filter :find_<%= sco_parent_underscored %>,
|
3
|
+
before_filter :find_<%= sco_underscored %>, :only => [<%= filter_actions %w( show edit update destroy) %>]
|
4
|
+
before_filter :find_<%= sco_parent_underscored %>, :only => [<%= filter_actions %w( index new create) %>]
|
5
5
|
|
6
6
|
|
7
7
|
<% if actions.include?('index') -%>
|
@@ -11,19 +11,26 @@ class <%= class_name %>Controller < Admin::AdminController
|
|
11
11
|
end
|
12
12
|
|
13
13
|
<% end -%>
|
14
|
-
|
14
|
+
<% if actions.include?('show') -%>
|
15
|
+
|
15
16
|
def show
|
16
17
|
end
|
17
|
-
|
18
|
+
|
19
|
+
<% end -%>
|
20
|
+
<% if actions.include?('new') -%>
|
18
21
|
|
19
22
|
def new
|
20
23
|
@<%= sco_underscored %> = @<%= sco_parent_underscored %>.<%= sco_underscored_plural %>.build
|
21
24
|
end
|
22
|
-
|
25
|
+
|
26
|
+
<% end -%>
|
27
|
+
<% if actions.include?('edit') -%>
|
23
28
|
|
24
29
|
def edit
|
25
30
|
end
|
26
|
-
|
31
|
+
|
32
|
+
<% end -%>
|
33
|
+
<% if actions.include?('create') -%>
|
27
34
|
|
28
35
|
def create
|
29
36
|
@<%= sco_underscored %> = @<%= sco_parent_underscored %>.<%= sco_underscored_plural %>.build(params[:<%= sco_underscored %>])
|
@@ -34,7 +41,9 @@ class <%= class_name %>Controller < Admin::AdminController
|
|
34
41
|
render :action => 'new'
|
35
42
|
end
|
36
43
|
end
|
37
|
-
|
44
|
+
|
45
|
+
<% end -%>
|
46
|
+
<% if actions.include?('update') -%>
|
38
47
|
|
39
48
|
def update
|
40
49
|
if @<%= sco_underscored %>.update_attributes(params[:<%= sco_underscored %>])
|
@@ -44,15 +53,17 @@ class <%= class_name %>Controller < Admin::AdminController
|
|
44
53
|
render :action => 'edit'
|
45
54
|
end
|
46
55
|
end
|
47
|
-
|
56
|
+
|
57
|
+
<% end -%>
|
58
|
+
<% if actions.include?('destroy') -%>
|
48
59
|
|
49
60
|
def destroy
|
50
61
|
@<%= sco_underscored %>.destroy
|
51
62
|
redirect_to :back
|
52
63
|
end
|
53
64
|
|
54
|
-
|
55
|
-
<% if actions.include?('sort') -%>
|
65
|
+
<% end -%>
|
66
|
+
<% if actions.include?('sort') -%>
|
56
67
|
|
57
68
|
def sort
|
58
69
|
params[:<%= sco_underscored %>].each_with_index do |id, index|
|
@@ -62,8 +73,8 @@ class <%= class_name %>Controller < Admin::AdminController
|
|
62
73
|
end
|
63
74
|
|
64
75
|
<% end -%>
|
65
|
-
|
66
76
|
<% for action in non_restful_actions -%>
|
77
|
+
|
67
78
|
def <%= action %>
|
68
79
|
end
|
69
80
|
|
@@ -1,4 +1,3 @@
|
|
1
1
|
- titles link_to(@<%= sco_underscored %>.<%= sco_parent_underscored %>, admin_<%= sco_parent_underscored %>_path(@<%= sco_underscored %>.<%= sco_parent_underscored %>)), link_to('<%= sco_titleized_plural %>', admin_<%= sco_parent_underscored %>_<%= sco_underscored_plural %>_path(@<%= sco_underscored %>.<%= sco_parent_underscored %>)), @<%= sco_underscored %>
|
2
2
|
|
3
|
-
|
4
3
|
- toggle_show_edit 'Edit', :admin, @<%= sco_underscored %>
|
@@ -1,28 +1,35 @@
|
|
1
1
|
class <%= class_name %>Controller < Admin::AdminController
|
2
2
|
|
3
|
-
before_filter :find_<%= sco_underscored %>, :only => [
|
3
|
+
before_filter :find_<%= sco_underscored %>, :only => [<%= filter_actions %w( show edit update destroy) %>]
|
4
4
|
|
5
5
|
|
6
|
-
<% if actions.include?('index') -%>
|
6
|
+
<% if actions.include?('index') -%>
|
7
7
|
|
8
8
|
def index
|
9
9
|
@<%= sco_underscored_plural %> = <%= sco_class %>.all
|
10
10
|
end
|
11
11
|
|
12
|
-
<% end -%>
|
13
|
-
|
12
|
+
<% end -%>
|
13
|
+
<% if actions.include?('show') -%>
|
14
|
+
|
14
15
|
def show
|
15
16
|
end
|
16
17
|
|
18
|
+
<% end -%>
|
19
|
+
<% if actions.include?('new') -%>
|
17
20
|
|
18
21
|
def new
|
19
22
|
@<%= sco_underscored %> = <%= sco_class %>.new
|
20
23
|
end
|
21
|
-
|
24
|
+
|
25
|
+
<% end -%>
|
26
|
+
<% if actions.include?('edit') -%>
|
22
27
|
|
23
28
|
def edit
|
24
29
|
end
|
25
30
|
|
31
|
+
<% end -%>
|
32
|
+
<% if actions.include?('create') -%>
|
26
33
|
|
27
34
|
def create
|
28
35
|
@<%= sco_underscored %> = <%= sco_class %>.new(params[:<%= sco_underscored %>])
|
@@ -34,6 +41,8 @@ class <%= class_name %>Controller < Admin::AdminController
|
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
44
|
+
<% end -%>
|
45
|
+
<% if actions.include?('update') -%>
|
37
46
|
|
38
47
|
def update
|
39
48
|
if @<%= sco_underscored %>.update_attributes(params[:<%= sco_underscored %>])
|
@@ -44,14 +53,16 @@ class <%= class_name %>Controller < Admin::AdminController
|
|
44
53
|
end
|
45
54
|
end
|
46
55
|
|
56
|
+
<% end -%>
|
57
|
+
<% if actions.include?('destroy') -%>
|
47
58
|
|
48
59
|
def destroy
|
49
60
|
@<%= sco_underscored %>.destroy
|
50
61
|
redirect_to :back
|
51
62
|
end
|
52
63
|
|
53
|
-
|
54
|
-
<% if actions.include?('sort') -%>
|
64
|
+
<% end -%>
|
65
|
+
<% if actions.include?('sort') -%>
|
55
66
|
|
56
67
|
def sort
|
57
68
|
params[:<%= sco_underscored %>].each_with_index do |id, index|
|
@@ -60,13 +71,13 @@ class <%= class_name %>Controller < Admin::AdminController
|
|
60
71
|
render :nothing => true
|
61
72
|
end
|
62
73
|
|
63
|
-
<% end -%>
|
74
|
+
<% end -%>
|
75
|
+
<% for action in non_restful_actions -%>
|
64
76
|
|
65
|
-
<% for action in non_restful_actions -%>
|
66
77
|
def <%= action %>
|
67
78
|
end
|
68
79
|
|
69
|
-
<% end -%>
|
80
|
+
<% end -%>
|
70
81
|
|
71
82
|
private
|
72
83
|
|
@@ -1,10 +1,12 @@
|
|
1
1
|
- titles link_to('<%= sco_titleized_plural %>', admin_<%= sco_underscored_plural %>_path), @<%= sco_underscored %>
|
2
2
|
|
3
3
|
- toggle_show_edit 'Edit', :admin, @<%= sco_underscored %>
|
4
|
-
|
5
|
-
|
4
|
+
<% if has_child? -%>
|
5
|
+
|
6
|
+
|
6
7
|
%h5 <%= sco_child_titleized_plural %>
|
7
8
|
|
8
9
|
%p= link_to('Add new <%= sco_child_humanized %>', new_admin_<%= sco_underscored %>_<%= sco_child_underscored %>_path(@<%= sco_underscored %>))
|
9
10
|
|
10
|
-
= render :partial => 'shared/<%= sco_child_underscored_plural %>', :object => @<%= sco_underscored %>.<%= sco_child_underscored_plural %>
|
11
|
+
= render :partial => 'shared/<%= sco_child_underscored_plural %>', :object => @<%= sco_underscored %>.<%= sco_child_underscored_plural %>
|
12
|
+
<% end -%>
|
data/schofield.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{schofield}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marc Tauber"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-06}
|
13
13
|
s.description = %q{Create views and controllers from routes defined in admin namespace. Very, very basic and very specific to my needs.'}
|
14
14
|
s.email = %q{marc@marctauber.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schofield
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Tauber
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-06 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|