schofield 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -25,6 +25,11 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
25
25
  sco_parent_underscored = sco_parent_class.underscore.downcase
26
26
  sco_parent_underscored_plural = sco_parent_underscored.pluralize
27
27
  sco_parent_titleized_plural = sco_parent_underscored.titleize.pluralize
28
+ sco_child_class = options[:child] ? options[:child].classify : ''
29
+ sco_child_underscored = sco_child_class.underscore.downcase
30
+ sco_child_underscored_plural = sco_child_underscored.pluralize
31
+ sco_child_titleized_plural = sco_child_underscored.titleize.pluralize
32
+ sco_child_humanized = sco_child_underscored.humanize.downcase
28
33
 
29
34
  assigns = { :sco_underscored => sco_underscored,
30
35
  :sco_underscored_plural => sco_underscored_plural,
@@ -36,7 +41,11 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
36
41
  :sco_parent_class => sco_parent_class,
37
42
  :sco_titleized_plural => sco_titleized_plural,
38
43
  :sco_humanized => sco_humanized,
39
- :non_restful_actions => non_restful_actions }
44
+ :non_restful_actions => non_restful_actions,
45
+ :sco_child_underscored => sco_child_underscored,
46
+ :sco_child_underscored_plural => sco_child_underscored_plural,
47
+ :sco_child_titleized_plural => sco_child_titleized_plural,
48
+ :sco_child_humanized => sco_child_humanized }
40
49
 
41
50
 
42
51
  # Check for class naming collisions.
@@ -74,8 +83,14 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
74
83
  m.template "#{template_directory}/#{action}.rb",
75
84
  File.join('app/views', class_path, file_name, "#{action}.haml"),
76
85
  :assigns => assigns if actions_with_view.include?(action)
77
-
78
86
  end
87
+
88
+ if actions.include?('index')
89
+ m.template 'index_partial.rb',
90
+ File.join('app/views/shared', "_#{sco_underscored_plural}.haml"),
91
+ :assigns => assigns
92
+ end
93
+
79
94
  end
80
95
  end
81
96
 
@@ -101,6 +116,7 @@ class SchofieldControllerGenerator < Rails::Generator::NamedBase
101
116
  opt.separator ''
102
117
  opt.separator 'Options:'
103
118
  opt.on('--parent PARENT', 'Specify the parent model') { |v| options[:parent] = v if v.present? }
119
+ opt.on('--child CHILD', 'Specify the child model') { |v| options[:child] = v if v.present? }
104
120
  end
105
121
 
106
122
  def banner
@@ -0,0 +1,17 @@
1
+ - if <%= sco_underscored_plural %>.any?
2
+
3
+ %table#<%= sco_underscored_plural %>
4
+
5
+ = render :partial => 'shared/admin/table_header', :locals => { :columns => %w( Title ), :buttons => 3 }
6
+
7
+ %tbody
8
+
9
+ - <%= sco_underscored_plural %>.each do |<%= sco_underscored %>|
10
+
11
+ %tr
12
+
13
+ %td&= <%= sco_underscored %>
14
+
15
+ %td= link_to_button 'Show', admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
16
+ %td= link_to_button 'Edit', edit_admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
17
+ %td= link_to_button 'Delete', admin_<%= sco_underscored %>_path(<%= sco_underscored %>), :method => 'delete', :confirm => "Are you sure you want to delete the <%= sco_humanized %>: #{h(<%= sco_underscored %>)}?"
@@ -2,20 +2,4 @@
2
2
 
3
3
  %p= link_to('Add new <%= sco_humanized %>', new_admin_<%= sco_parent_underscored %>_<%= sco_underscored %>_path)
4
4
 
5
- - if @<%= sco_underscored_plural %>.any?
6
-
7
- %table#<%= sco_underscored_plural %>
8
-
9
- = render :partial => 'shared/admin/table_header', :locals => { :columns => %w( Title ), :buttons => 3 }
10
-
11
- %tbody
12
-
13
- - @<%= sco_underscored_plural %>.each do |<%= sco_underscored %>|
14
-
15
- %tr
16
-
17
- %td&= <%= sco_underscored %>
18
-
19
- %td= link_to_button 'Show', admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
20
- %td= link_to_button 'Edit', edit_admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
21
- %td= link_to_button 'Delete', admin_<%= sco_underscored %>_path(<%= sco_underscored %>), :method => 'delete', :confirm => "Are you sure you want to delete the <%= sco_humanized %>: #{h(<%= sco_underscored %>)}?"
5
+ = render :partial => 'shared/<%= sco_underscored_plural %>', :object => @<%= sco_underscored_plural %>
@@ -2,20 +2,4 @@
2
2
 
3
3
  %p= link_to('Add new <%= sco_humanized %>', new_admin_<%= sco_underscored %>_path)
4
4
 
5
- - if @<%= sco_underscored_plural %>.any?
6
-
7
- %table#<%= sco_underscored_plural %>
8
-
9
- = render :partial => 'shared/admin/table_header', :locals => { :columns => %w( Title ), :buttons => 3 }
10
-
11
- %tbody
12
-
13
- - @<%= sco_underscored_plural %>.each do |<%= sco_underscored %>|
14
-
15
- %tr
16
-
17
- %td&= <%= sco_underscored %>
18
-
19
- %td= link_to_button 'Show', admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
20
- %td= link_to_button 'Edit', edit_admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
21
- %td= link_to_button 'Delete', admin_<%= sco_underscored %>_path(<%= sco_underscored %>), :method => 'delete', :confirm => "Are you sure you want to delete the <%= sco_humanized %>: #{h(<%= sco_underscored %>)}?"
5
+ = render :partial => 'shared/<%= sco_underscored_plural %>', :object => @<%= sco_underscored_plural %>
@@ -1,3 +1,10 @@
1
1
  - titles link_to('<%= sco_titleized_plural %>', admin_<%= sco_underscored_plural %>_path), @<%= sco_underscored %>
2
2
 
3
- - toggle_show_edit 'Edit', :admin, @<%= sco_underscored %>
3
+ - toggle_show_edit 'Edit', :admin, @<%= sco_underscored %>
4
+
5
+
6
+ %h5 <%= sco_child_titleized_plural %>
7
+
8
+ %p= link_to('Add new <%= sco_child_humanized %>', new_admin_<%= sco_underscored %>_<%= sco_child_underscored %>_path(@<%= sco_underscored %>))
9
+
10
+ = render :partial => 'shared/<%= sco_child_underscored_plural %>', :object => @<%= sco_underscored %>.<%= sco_child_underscored_plural %>
@@ -1,13 +1,7 @@
1
1
  namespace :schofield do
2
-
3
2
  desc "Generate controllers and views based on routes"
4
3
  task :generate => :environment do
5
-
6
4
  @generator = Schofield::Generator.new
7
- ActionController::Routing::Routes.routes.each do |route|
8
- @generator.process_route(route)
9
- end
10
5
  @generator.generate
11
-
12
6
  end
13
7
  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, :child
48
48
 
49
49
  def initialize route_info
50
50
  @controller_name = route_info.controller_name
@@ -63,18 +63,30 @@ module Schofield
63
63
  @controller_infos = {}
64
64
  end
65
65
 
66
+ def process_routes
67
+ ActionController::Routing::Routes.routes.each { |route| process_route(route) }
68
+ end
69
+
66
70
  def process_route route
67
71
  route_info = RouteInfo.new(route)
68
72
  return unless route_info.use?
69
- @controller_infos[route_info.controller_name] ||= ControllerInfo.new(route_info)
70
- @controller_infos[route_info.controller_name].actions << route_info.action_name
73
+ @controller_infos[route_info.model_name] ||= ControllerInfo.new(route_info)
74
+ @controller_infos[route_info.model_name].actions << route_info.action_name
71
75
  end
72
-
76
+
77
+ def set_children
78
+ @controller_infos.each do |index, info|
79
+ @controller_infos[info.parent].child = index unless info.parent.nil?
80
+ end
81
+ end
82
+
73
83
  def generate
84
+ process_routes
85
+ set_children
74
86
  require 'rails_generator'
75
87
  require 'rails_generator/scripts/generate'
76
88
  @controller_infos.each do |index, info|
77
- Rails::Generator::Scripts::Generate.new.run(['schofield_controller', info.controller_path, *info.actions ], :parent => info.parent)
89
+ Rails::Generator::Scripts::Generate.new.run(['schofield_controller', info.controller_path, *info.actions ], :parent => info.parent, :child => info.child)
78
90
  Rails::Generator::Scripts::Generate.new.run(['schofield_form', info.model_name], :partial => true, :haml => true, :controller => info.controller_path, :parent => info.parent)
79
91
  end
80
92
  end
data/schofield.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{schofield}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
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"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "generators/schofield_controller/schofield_controller_generator.rb",
27
27
  "generators/schofield_controller/templates/controller_spec.rb",
28
28
  "generators/schofield_controller/templates/helper_spec.rb",
29
+ "generators/schofield_controller/templates/index_partial.rb",
29
30
  "generators/schofield_controller/templates/nested/controller.rb",
30
31
  "generators/schofield_controller/templates/nested/edit.rb",
31
32
  "generators/schofield_controller/templates/nested/index.rb",
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Tauber
@@ -51,6 +51,7 @@ files:
51
51
  - generators/schofield_controller/schofield_controller_generator.rb
52
52
  - generators/schofield_controller/templates/controller_spec.rb
53
53
  - generators/schofield_controller/templates/helper_spec.rb
54
+ - generators/schofield_controller/templates/index_partial.rb
54
55
  - generators/schofield_controller/templates/nested/controller.rb
55
56
  - generators/schofield_controller/templates/nested/edit.rb
56
57
  - generators/schofield_controller/templates/nested/index.rb