schofield 0.1.0 → 0.1.1
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
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -27,12 +27,25 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
|
|
27
27
|
sco_parent_underscored_plural = sco_parent_underscored.pluralize
|
28
28
|
sco_parent_titleized_plural = sco_parent_underscored.titleize.pluralize
|
29
29
|
|
30
|
-
|
31
|
-
sco_child_underscored = sco_child_class.underscore.downcase
|
32
|
-
sco_child_underscored_plural = sco_child_underscored.pluralize
|
33
|
-
sco_child_titleized_plural = sco_child_underscored.titleize.pluralize
|
34
|
-
sco_child_humanized = sco_child_underscored.humanize.downcase
|
30
|
+
sco_children = []
|
35
31
|
|
32
|
+
if has_children?
|
33
|
+
options[:children].each do |child|
|
34
|
+
sco_child_class = has_children? ? child.classify : ''
|
35
|
+
sco_child_underscored = sco_child_class.underscore.downcase
|
36
|
+
sco_child_underscored_plural = sco_child_underscored.pluralize
|
37
|
+
sco_child_titleized_plural = sco_child_underscored.titleize.pluralize
|
38
|
+
sco_child_humanized = sco_child_underscored.humanize.downcase
|
39
|
+
sco_children << {
|
40
|
+
:class => sco_child_class,
|
41
|
+
:underscored => sco_child_underscored,
|
42
|
+
:underscored_plural => sco_child_underscored_plural,
|
43
|
+
:titleized_plural => sco_child_titleized_plural,
|
44
|
+
:humanized => sco_child_humanized
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
36
49
|
assigns = { :sco_underscored => sco_underscored,
|
37
50
|
:sco_underscored_plural => sco_underscored_plural,
|
38
51
|
:sco_class => sco_class,
|
@@ -44,10 +57,7 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
|
|
44
57
|
:sco_titleized_plural => sco_titleized_plural,
|
45
58
|
:sco_humanized => sco_humanized,
|
46
59
|
:non_restful_actions => non_restful_actions,
|
47
|
-
:
|
48
|
-
:sco_child_underscored_plural => sco_child_underscored_plural,
|
49
|
-
:sco_child_titleized_plural => sco_child_titleized_plural,
|
50
|
-
:sco_child_humanized => sco_child_humanized }
|
60
|
+
:sco_children => sco_children }
|
51
61
|
|
52
62
|
|
53
63
|
# Check for class naming collisions.
|
@@ -118,15 +128,15 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
|
|
118
128
|
opt.separator ''
|
119
129
|
opt.separator 'Options:'
|
120
130
|
opt.on('--parent PARENT', 'Specify the parent model') { |v| options[:parent] = v if v.present? }
|
121
|
-
opt.on('--
|
131
|
+
opt.on('--children CHILDREN', 'Specify the children models') { |v| options[:children] = v if v.present? }
|
122
132
|
end
|
123
133
|
|
124
134
|
def has_parent?
|
125
135
|
options[:parent].present?
|
126
136
|
end
|
127
137
|
|
128
|
-
def
|
129
|
-
options[:
|
138
|
+
def has_children?
|
139
|
+
options[:children].present?
|
130
140
|
end
|
131
141
|
|
132
142
|
def filter_actions array
|
@@ -1,10 +1,10 @@
|
|
1
1
|
- toggle_show_edit 'Edit', :admin, @<%= sco_underscored %>
|
2
|
-
<%
|
2
|
+
<% sco_children.each do |child| -%>
|
3
3
|
|
4
4
|
|
5
|
-
%h5 <%=
|
5
|
+
%h5 <%= child[:titleized_plural] %>
|
6
6
|
|
7
|
-
%p= link_to('Add new <%=
|
7
|
+
%p= link_to('Add new <%= child[:humanized] %>', new_admin_<%= sco_underscored %>_<%= child[:underscored] %>_path(@<%= sco_underscored %>))
|
8
8
|
|
9
|
-
= render :partial => 'shared/<%=
|
9
|
+
= render :partial => 'shared/<%= child[:underscored_plural] %>', :object => @<%= sco_underscored %>.<%= child[:underscored_plural] %>
|
10
10
|
<% end -%>
|
data/lib/schofield.rb
CHANGED
@@ -44,7 +44,7 @@ module Schofield
|
|
44
44
|
class ControllerInfo
|
45
45
|
|
46
46
|
attr_reader :parent, :controller_name, :controller_path, :model_name
|
47
|
-
attr_accessor :actions, :
|
47
|
+
attr_accessor :actions, :children
|
48
48
|
|
49
49
|
def initialize route_info
|
50
50
|
@controller_name = route_info.controller_name
|
@@ -52,6 +52,7 @@ module Schofield
|
|
52
52
|
@model_name = route_info.model_name
|
53
53
|
@parent = route_info.parent
|
54
54
|
@actions = []
|
55
|
+
@children = []
|
55
56
|
end
|
56
57
|
|
57
58
|
end
|
@@ -76,7 +77,7 @@ module Schofield
|
|
76
77
|
|
77
78
|
def set_children
|
78
79
|
@controller_infos.each do |index, info|
|
79
|
-
@controller_infos[info.parent].
|
80
|
+
@controller_infos[info.parent].children << index unless info.parent.nil?
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
@@ -86,7 +87,7 @@ module Schofield
|
|
86
87
|
require 'rails_generator'
|
87
88
|
require 'rails_generator/scripts/generate'
|
88
89
|
@controller_infos.each do |index, info|
|
89
|
-
Rails::Generator::Scripts::Generate.new.run(['schofield_controller', info.controller_path, *info.actions ], :parent => info.parent, :
|
90
|
+
Rails::Generator::Scripts::Generate.new.run(['schofield_controller', info.controller_path, *info.actions ], :parent => info.parent, :children => info.children)
|
90
91
|
Rails::Generator::Scripts::Generate.new.run(['schofield_form', info.model_name], :partial => true, :haml => true, :controller => info.controller_path, :parent => info.parent)
|
91
92
|
end
|
92
93
|
end
|
data/schofield.gemspec
CHANGED