schofield 0.2.2 → 0.3.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/.rvmrc +61 -0
- data/Gemfile.lock +4 -4
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/generators/schofield/association.rb +24 -24
- data/lib/generators/schofield/attribute.rb +49 -32
- data/lib/generators/schofield/attributes.rb +129 -128
- data/lib/generators/schofield/level.rb +86 -86
- data/lib/generators/schofield/levels.rb +21 -16
- data/lib/generators/schofield/navigation.rb +17 -0
- data/lib/generators/schofield/responses.rb +13 -13
- data/lib/generators/schofield/routes.rb +19 -14
- data/lib/generators/schofield/schofield_generator.rb +22 -18
- data/lib/generators/templates/controller.erb +7 -7
- data/lib/generators/templates/form.erb +11 -7
- data/lib/generators/templates/index.erb +2 -2
- data/lib/generators/templates/join_controller.erb +1 -1
- data/lib/generators/templates/model.erb +37 -39
- data/lib/generators/templates/show.erb +1 -1
- data/schofield.gemspec +10 -9
- data/spec/spec_helper.rb +1 -1
- metadata +20 -20
@@ -1,10 +1,10 @@
|
|
1
1
|
module Schofield
|
2
|
-
|
2
|
+
|
3
3
|
module Generators
|
4
|
-
|
4
|
+
|
5
5
|
class Routes
|
6
|
-
|
7
|
-
def self.add_routes levels, depth=
|
6
|
+
|
7
|
+
def self.add_routes levels, depth=3
|
8
8
|
childless = []
|
9
9
|
levels.each do |level|
|
10
10
|
if level.join?
|
@@ -12,35 +12,40 @@ module Schofield
|
|
12
12
|
elsif level.nests?
|
13
13
|
@routes << route_string([level], depth)
|
14
14
|
add_routes(level.nested_levels, depth+1)
|
15
|
-
@routes << "#{' ' * depth}end" + (depth ==
|
15
|
+
@routes << "#{' ' * depth}end" + (depth == 3 ? "\n" : '')
|
16
16
|
else
|
17
17
|
childless << level
|
18
18
|
end
|
19
19
|
end
|
20
20
|
@routes << route_string(childless, depth) if childless.any?
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.route_string levels, depth
|
24
24
|
string = ' ' * depth
|
25
25
|
string += "resources "
|
26
26
|
string += ':' + levels.map{ |level| level.name.tableize }.join(', :')
|
27
27
|
string += ", "
|
28
|
-
string += ":except => #{depth ==
|
28
|
+
string += ":except => #{depth == 3 ? ':edit' : '[:index, :edit]'}"
|
29
29
|
string += levels.length == 1 && levels.first.nests? ? ', :shallow => true do' : ''
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def self.generate
|
33
|
-
@routes = [
|
33
|
+
@routes = [
|
34
|
+
" namespace :admin do\n",
|
35
|
+
" root :to => 'home#index'",
|
36
|
+
" match '/:locale' => 'home#index'\n",
|
37
|
+
" scope '/:locale', :locale => /\#{I18n.available_locales.join('|')}/, :shallow_path => '/:locale' do\n"
|
38
|
+
]
|
34
39
|
@joins = []
|
35
40
|
add_routes(Levels.all.select(&:routes?))
|
36
|
-
@routes.push "\n
|
37
|
-
@routes.push "\n
|
38
|
-
@routes.
|
41
|
+
@routes.push "\n resources :#{@joins.map{ |s| s.name.tableize }.join(', :')}, :only => [:create, :delete]" if @joins.any?
|
42
|
+
@routes.push "\n resources :#{Levels.sortables.map{ |s| s.tableize }.join(', :')}, :only => [] do\n post :sort, :on => :collection\n end" if Levels.sortables.any?
|
43
|
+
@routes.push ' end'
|
39
44
|
@routes.push ' end'
|
40
45
|
@routes.join("\n") + "\n\n"
|
41
46
|
end
|
42
|
-
|
47
|
+
|
43
48
|
end
|
44
|
-
|
49
|
+
|
45
50
|
end
|
46
51
|
end
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'rails/generators/base'
|
2
2
|
|
3
|
-
%w( levels level responses association routes attributes attribute ).each do |file|
|
3
|
+
%w( levels level responses association routes attributes attribute navigation ).each do |file|
|
4
4
|
require File.join(File.dirname(__FILE__), file)
|
5
5
|
end
|
6
6
|
|
7
7
|
|
8
8
|
|
9
9
|
module Schofield
|
10
|
-
|
10
|
+
|
11
11
|
module Generators
|
12
|
-
|
12
|
+
|
13
13
|
class Schofield < Rails::Generators::Base
|
14
14
|
|
15
15
|
source_root File.expand_path(File.join(File.dirname(__FILE__), '../', 'templates'))
|
16
16
|
|
17
17
|
class_option :tables_to_ignore, :aliases => '-i', :type => :string, :default => '', :desc => 'Indicates which tables to ignore'
|
18
18
|
class_option :ask_questions, :aliases => '-a', :type => :boolean, :desc => 'Indicates whether to ask questions again rather than use recorded answers'
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
|
20
|
+
|
21
|
+
|
22
22
|
def generate
|
23
23
|
Responses.generator = self
|
24
24
|
Responses.re_ask = options[:ask_questions]
|
@@ -29,11 +29,11 @@ module Schofield
|
|
29
29
|
Responses.save
|
30
30
|
Association.report
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def generate_routes
|
34
34
|
inject_into_file(File.join(Rails.root, 'config', 'routes.rb'), Routes.generate, :before => /end\s*\Z/)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def generate_controllers
|
38
38
|
Levels.all.select(&:controllers?).each do |level|
|
39
39
|
source = level.join? ? 'join_controller.erb' : 'controller.erb'
|
@@ -41,11 +41,11 @@ module Schofield
|
|
41
41
|
template_with_context(source, Proc.new{level}, destination)
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def generate_views
|
46
46
|
Levels.all.select(&:views?).each do |level|
|
47
47
|
template_with_context('form.erb', Proc.new{level}, view_path(level, '_form.haml'))
|
48
|
-
create_file(view_path(level, 'new.haml'), %q(= render :partial => 'form', :layout => 'shared/
|
48
|
+
create_file(view_path(level, 'new.haml'), %q(= render :partial => 'form', :layout => 'admin/shared/module_layout'))
|
49
49
|
template_with_context('show.erb', Proc.new{level}, view_path(level, 'show.haml'))
|
50
50
|
if !level.nested?
|
51
51
|
template_with_context('index.erb', Proc.new{level}, view_path(level, 'index.haml'))
|
@@ -59,12 +59,16 @@ module Schofield
|
|
59
59
|
template_with_context('model.erb', Proc.new{level}, destination)
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
|
+
def generate_navigation
|
64
|
+
inject_into_file(File.join(Rails.root, 'app/views/admin/shared', '_navigation.haml'), Navigation.generate, :after => /- if current_user\n/)
|
65
|
+
end
|
66
|
+
|
63
67
|
def generate_tables
|
64
68
|
tables = []
|
65
69
|
Levels.all.select(&:tables?).each do |level|
|
66
70
|
columns_level = level.subclass? ? level.superclass : level
|
67
|
-
columns = columns_level.attributes.select{ |a| columns_level.form_field?(a)
|
71
|
+
columns = columns_level.attributes.select{ |a| columns_level.form_field?(a) && !a.text? }.sort_by(&:weight).map(&:to_column)
|
68
72
|
if level.nested?
|
69
73
|
tables << <<-STRING.gsub(/^ {12}/, '')
|
70
74
|
def #{level.name.pluralize}_table
|
@@ -76,7 +80,7 @@ module Schofield
|
|
76
80
|
else
|
77
81
|
tables << <<-STRING.gsub(/^ {12}/, '')
|
78
82
|
def render_#{level.name.pluralize} collection
|
79
|
-
table_renderer(collection).render(
|
83
|
+
table_renderer(:#{level.name.pluralize}, collection).render(
|
80
84
|
#{columns.join(",\n ")}
|
81
85
|
)
|
82
86
|
end
|
@@ -87,15 +91,15 @@ module Schofield
|
|
87
91
|
"module Admin::TableDefinitionsHelper\n\n#{tables.join("\n\n")}\nend"
|
88
92
|
end
|
89
93
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
94
|
+
|
95
|
+
|
96
|
+
|
93
97
|
private
|
94
98
|
|
95
99
|
def tables_to_ignore
|
96
100
|
@tables_to_ignore ||= %w( schema_migrations ) + options[:tables_to_ignore].split(',').map{ |e| e.strip.tableize }
|
97
101
|
end
|
98
|
-
|
102
|
+
|
99
103
|
def view_path level, file_name
|
100
104
|
File.join('app/views/admin', level.name.tableize, file_name)
|
101
105
|
end
|
@@ -107,7 +111,7 @@ module Schofield
|
|
107
111
|
def tables
|
108
112
|
ActiveRecord::Base.connection.tables - tables_to_ignore
|
109
113
|
end
|
110
|
-
|
114
|
+
|
111
115
|
def template_with_context(source, context, destination=nil, config={}, &block)
|
112
116
|
destination ||= source
|
113
117
|
source = File.expand_path(find_in_source_paths(source.to_s))
|
@@ -1,23 +1,23 @@
|
|
1
1
|
class Admin::<%= level.name.tableize.camelize %>Controller < Admin::AdminController
|
2
|
-
|
2
|
+
|
3
3
|
include InheritResources
|
4
4
|
<%- if level.sortable? -%>
|
5
5
|
include SortAction
|
6
|
-
|
6
|
+
|
7
7
|
<%- end -%>
|
8
|
-
|
8
|
+
|
9
9
|
actions :new, :create, :update, :destroy, :show<%= ', :index' unless level.nested? %>
|
10
|
-
|
10
|
+
|
11
11
|
<%- if level.nests? -%>
|
12
12
|
drill_down_on_create
|
13
|
-
|
13
|
+
|
14
14
|
<%- end -%>
|
15
15
|
<%- if level.nested? -%>
|
16
16
|
<%= level.polymorphic? ? 'polymorphic_' : '' %>belongs_to :<%= level.parent_associations.select(&:nest?).map(&:parent_name).join(', :') %>, :optional => true
|
17
|
-
|
17
|
+
|
18
18
|
<%- end -%>
|
19
19
|
private
|
20
|
-
|
20
|
+
|
21
21
|
def titles
|
22
22
|
generate_titles :<%= level.ancestry.join(', :') %>
|
23
23
|
end
|
@@ -3,13 +3,13 @@
|
|
3
3
|
= semantic_form_for <%= level.nested? ? 'parent? ? [:admin, parent, resource] : ' : '' %>[:admin, resource]<%= level.multipart? ? ', :html => { :multipart => true }' : '' %> do |f|
|
4
4
|
|
5
5
|
= f.inputs do
|
6
|
-
|
6
|
+
|
7
7
|
<%- level.attributes.each do |attribute| -%>
|
8
8
|
<%- if level.form_field?(attribute) -%>
|
9
9
|
<%- if attribute.attachment? -%>
|
10
|
-
= f.input :<%= attribute.name.gsub(/_file_name$/, '') %>, :as => :
|
10
|
+
= f.input :<%= attribute.name.gsub(/_file_name$/, '') %>, :as => :<%= attribute.image? ? 'image' : 'attachment' %><%= attribute.required_attachment? ? ', :required => true' : '' %>
|
11
11
|
<%- else -%>
|
12
|
-
= f.input :<%= attribute.actual_name %><%= attribute.text? ? %q(, :input_html => { :class => 'medium
|
12
|
+
= f.input :<%= attribute.actual_name %><%= attribute.text? ? %q(, :input_html => { :class => 'medium wysiwyg' }) : '' %>
|
13
13
|
<%- end -%>
|
14
14
|
<%- end -%>
|
15
15
|
<%- end -%>
|
@@ -19,13 +19,17 @@
|
|
19
19
|
<%- child.attributes.each do |attribute| -%>
|
20
20
|
<%- if child.form_field?(attribute) && attribute.actual_name != level.name -%>
|
21
21
|
<%- if attribute.attachment? -%>
|
22
|
-
= <%= child.name %>.input :<%= attribute.name.gsub(/_file_name$/, '') %>, :as => :
|
22
|
+
= <%= child.name %>.input :<%= attribute.name.gsub(/_file_name$/, '') %>, :as => :<%= attribute.image? ? 'image' : 'attachment' %><%= attribute.required_attachment? ? ', :required => true' : '' %>
|
23
23
|
<%- else -%>
|
24
|
-
= <%= child.name %>.input :<%= attribute.actual_name %><%= attribute.text? ? %q(, :input_html => { :class => 'medium
|
24
|
+
= <%= child.name %>.input :<%= attribute.actual_name %><%= attribute.text? ? %q(, :input_html => { :class => 'medium wysiwyg' }) : '' %>
|
25
25
|
<%- end -%>
|
26
26
|
<%- end -%>
|
27
27
|
<%- end -%>
|
28
28
|
= <%= child.name %>.input :nested, :as => :hidden
|
29
29
|
<%- end -%>
|
30
|
-
|
31
|
-
= f.buttons
|
30
|
+
|
31
|
+
= f.buttons
|
32
|
+
<%- if level.multipart? -%>
|
33
|
+
|
34
|
+
= render :partial => 'admin/shared/progress_bar'
|
35
|
+
<%- end -%>
|
@@ -1,11 +1,8 @@
|
|
1
1
|
class <%= level.name.camelize %> < <%= level.subclass? ? level.superclass.name.camelize : 'ActiveRecord::Base' %>
|
2
|
-
|
2
|
+
|
3
3
|
strip_attributes!
|
4
|
-
<%- if level.has_manies? -%>
|
5
|
-
prevent_destroy_if_has_children :<%= level.has_manies.map{ |l| l.name.pluralize }.join(', :') %>
|
6
|
-
<%- end -%>
|
7
4
|
<%- if level.sortable? -%>
|
8
|
-
acts_as_list<%=
|
5
|
+
acts_as_list<%=
|
9
6
|
if level.polymorphic?
|
10
7
|
" :scope => [:#{level.polymorphic_name}_type, :#{level.polymorphic_name}_id]"
|
11
8
|
elsif level.nested?
|
@@ -13,28 +10,29 @@ class <%= level.name.camelize %> < <%= level.subclass? ? level.superclass.name.c
|
|
13
10
|
end
|
14
11
|
%>
|
15
12
|
<%- end -%>
|
16
|
-
|
17
|
-
|
18
|
-
<%- end -%>
|
19
|
-
|
20
|
-
|
13
|
+
|
14
|
+
|
21
15
|
# ATTRIBUTES
|
22
|
-
<%- if level.
|
23
|
-
|
24
|
-
<%= level.
|
16
|
+
<%- if level.attr_accessors? -%>
|
17
|
+
|
18
|
+
<%= level.attr_accessors %>
|
19
|
+
<%- end -%>
|
20
|
+
<%- if level.attr_accessibles? -%>
|
21
|
+
|
22
|
+
<%= level.attr_accessibles %>
|
25
23
|
<%- end -%>
|
26
24
|
<%- if level.belongs_to_one? -%>
|
27
|
-
|
25
|
+
|
28
26
|
attr_accessor :nested
|
29
27
|
<%- end -%>
|
30
|
-
|
31
|
-
|
28
|
+
|
29
|
+
|
32
30
|
# FILTERS
|
33
|
-
|
34
|
-
|
31
|
+
|
32
|
+
|
35
33
|
# ASSOCIATIONS
|
36
34
|
<%- if level.parent_associations.find(&:non_polymorphic?) -%>
|
37
|
-
|
35
|
+
|
38
36
|
<%- level.parent_associations.select(&:non_polymorphic?).each do |association| -%>
|
39
37
|
belongs_to :<%= association.parent_name %>
|
40
38
|
<%- end -%>
|
@@ -45,7 +43,7 @@ class <%= level.name.camelize %> < <%= level.subclass? ? level.superclass.name.c
|
|
45
43
|
<%- end -%>
|
46
44
|
<%- end -%>
|
47
45
|
<%- if level.child_associations.find(&:non_polymorphic_one_to_many?) -%>
|
48
|
-
|
46
|
+
|
49
47
|
<%- level.child_associations.select(&:non_polymorphic_one_to_many?).map(&:child).each do |child| -%>
|
50
48
|
has_many :<%= child.name.pluralize %>, :dependent => :destroy
|
51
49
|
<%- if child.join? -%>
|
@@ -54,56 +52,56 @@ class <%= level.name.camelize %> < <%= level.subclass? ? level.superclass.name.c
|
|
54
52
|
<%- end -%>
|
55
53
|
<%- end -%>
|
56
54
|
<%- if level.child_associations.find(&:non_polymorphic_one_to_one?) -%>
|
57
|
-
|
55
|
+
|
58
56
|
<%- level.child_associations.select(&:non_polymorphic_one_to_one?).each do |association| -%>
|
59
57
|
has_one :<%= association.child_name %>, :dependent => :destroy
|
60
58
|
<%- end -%>
|
61
59
|
<%- end -%>
|
62
60
|
<%- if level.child_associations.find(&:polymorphic_one_to_many?) -%>
|
63
|
-
|
61
|
+
|
64
62
|
<%- level.child_associations.select(&:polymorphic_one_to_many?).each do |association| -%>
|
65
63
|
has_many :<%= association.child_name.pluralize %>, :as => :<%= association.polymorphic_name %>, :dependent => :destroy
|
66
64
|
<%- end -%>
|
67
65
|
<%- end -%>
|
68
66
|
<%- if level.child_associations.find(&:polymorphic_one_to_one?) -%>
|
69
|
-
|
67
|
+
|
70
68
|
<%- level.child_associations.select(&:polymorphic_one_to_one?).each do |association| -%>
|
71
69
|
has_one :<%= association.child_name %>, :as => :<%= association.polymorphic_name %>, :dependent => :destroy
|
72
70
|
<%- end -%>
|
73
71
|
<%- end -%>
|
74
|
-
|
75
|
-
|
72
|
+
|
73
|
+
|
76
74
|
# NESTING
|
77
75
|
<%- if level.child_associations.find(&:one_to_one?) %>
|
78
|
-
|
76
|
+
|
79
77
|
<%- level.child_associations.select(&:one_to_one?).each do |association| -%>
|
80
78
|
accepts_nested_attributes_for :<%= association.child_name %>
|
81
79
|
<%- end -%>
|
82
80
|
<%- end -%>
|
83
|
-
|
84
|
-
|
81
|
+
|
82
|
+
|
85
83
|
# ATTACHMENTS
|
86
84
|
<%- if level.attachments? -%>
|
87
|
-
|
85
|
+
<%= level.attached_files %>
|
88
86
|
<%- end -%>
|
89
|
-
|
90
|
-
|
87
|
+
|
88
|
+
|
91
89
|
# VALIDATIONS
|
92
90
|
<%- if !level.subclass? && level.validations? -%>
|
93
|
-
|
91
|
+
|
94
92
|
<%= level.validations.join("\n ") %>
|
95
93
|
<%- end -%>
|
96
|
-
|
97
|
-
|
94
|
+
|
95
|
+
|
98
96
|
# SCOPES
|
99
|
-
|
97
|
+
|
100
98
|
scope :collection
|
101
|
-
|
102
|
-
|
99
|
+
|
100
|
+
|
103
101
|
# METHODS
|
104
|
-
|
102
|
+
|
105
103
|
def to_s
|
106
104
|
<%= level.to_s_string || (level.join? && level.nested? && level.parent_associations.find(&:nest?).parent_name) || '"##{id}"' %>
|
107
105
|
end
|
108
|
-
|
106
|
+
|
109
107
|
end
|
data/schofield.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "schofield"
|
8
|
+
s.version = "0.3.0"
|
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 =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2012-01-04"
|
13
|
+
s.description = "longer description of your gem"
|
14
|
+
s.email = "marc@marctauber.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.rdoc"
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".bundle/config",
|
21
21
|
".document",
|
22
|
+
".rvmrc",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE.txt",
|
@@ -30,6 +31,7 @@ Gem::Specification.new do |s|
|
|
30
31
|
"lib/generators/schofield/attributes.rb",
|
31
32
|
"lib/generators/schofield/level.rb",
|
32
33
|
"lib/generators/schofield/levels.rb",
|
34
|
+
"lib/generators/schofield/navigation.rb",
|
33
35
|
"lib/generators/schofield/responses.rb",
|
34
36
|
"lib/generators/schofield/routes.rb",
|
35
37
|
"lib/generators/schofield/schofield_generator.rb",
|
@@ -44,18 +46,17 @@ Gem::Specification.new do |s|
|
|
44
46
|
"spec/spec.opts",
|
45
47
|
"spec/spec_helper.rb"
|
46
48
|
]
|
47
|
-
s.homepage =
|
49
|
+
s.homepage = "http://github.com/sauberia/schofield"
|
48
50
|
s.licenses = ["MIT"]
|
49
51
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version =
|
51
|
-
s.summary =
|
52
|
+
s.rubygems_version = "1.8.10"
|
53
|
+
s.summary = "one-line summary of your gem"
|
52
54
|
s.test_files = [
|
53
55
|
"spec/schofield_spec.rb",
|
54
56
|
"spec/spec_helper.rb"
|
55
57
|
]
|
56
58
|
|
57
59
|
if s.respond_to? :specification_version then
|
58
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
59
60
|
s.specification_version = 3
|
60
61
|
|
61
62
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|