stefanpenner-my_scaffold 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/generators/my_scaffold/my_scaffold_generator.rb +95 -128
- data/test/environment.rb +30 -0
- data/test/my_scaffold_test.rb +1 -1
- metadata +2 -9
- data/generators/my_scaffold/templates/erb/_form.html.erb +0 -8
- data/generators/my_scaffold/templates/erb/edit.html.erb +0 -12
- data/generators/my_scaffold/templates/erb/index.html.erb +0 -22
- data/generators/my_scaffold/templates/erb/layout.html.erb +0 -22
- data/generators/my_scaffold/templates/erb/new.html.erb +0 -8
- data/generators/my_scaffold/templates/erb/show.html.erb +0 -12
- data/generators/my_scaffold/templates/functional_test/should_be_restful.rb +0 -13
data/VERSION.yml
CHANGED
@@ -1,64 +1,8 @@
|
|
1
|
-
#--
|
2
|
-
# ShouldaScaffoldGeneratorConfig based on rubygems code.
|
3
|
-
# Thank you Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
4
|
-
#++
|
5
|
-
class MyScaffoldGeneratorConfig
|
6
|
-
|
7
|
-
DEFAULT_TEMPLATING = 'haml'
|
8
|
-
DEFAULT_FUNCTIONAL_TEST_STYLE = 'basic'
|
9
|
-
|
10
|
-
def initialize()
|
11
|
-
@config = load_file(config_file)
|
12
|
-
|
13
|
-
@templating = @config[:templating] || DEFAULT_TEMPLATING
|
14
|
-
@functional_test_style = @config[:functional_test_style] || DEFAULT_FUNCTIONAL_TEST_STYLE
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :templating, :functional_test_style
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def load_file(filename)
|
22
|
-
begin
|
23
|
-
YAML.load(File.read(filename)) if filename and File.exist?(filename)
|
24
|
-
rescue ArgumentError
|
25
|
-
warn "Failed to load #{config_file_name}"
|
26
|
-
rescue Errno::EACCES
|
27
|
-
warn "Failed to load #{config_file_name} due to permissions problem."
|
28
|
-
end or {}
|
29
|
-
end
|
30
|
-
|
31
|
-
def config_file
|
32
|
-
File.join(find_home, '.my_generator')
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# Finds the user's home directory.
|
37
|
-
|
38
|
-
def find_home
|
39
|
-
['HOME', 'USERPROFILE'].each do |homekey|
|
40
|
-
return ENV[homekey] if ENV[homekey]
|
41
|
-
end
|
42
|
-
|
43
|
-
if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
|
44
|
-
return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}"
|
45
|
-
end
|
46
|
-
|
47
|
-
begin
|
48
|
-
File.expand_path("~")
|
49
|
-
rescue
|
50
|
-
if File::ALT_SEPARATOR then
|
51
|
-
"C:/"
|
52
|
-
else
|
53
|
-
"/"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
1
|
class MyScaffoldGenerator < Rails::Generator::NamedBase
|
60
|
-
default_options :skip_timestamps => false,
|
61
|
-
|
2
|
+
default_options :skip_timestamps => false,
|
3
|
+
:skip_migration => false,
|
4
|
+
:skip_layout => true
|
5
|
+
|
62
6
|
attr_reader :controller_name,
|
63
7
|
:controller_class_path,
|
64
8
|
:controller_file_path,
|
@@ -68,119 +12,142 @@ class MyScaffoldGenerator < Rails::Generator::NamedBase
|
|
68
12
|
:controller_underscore_name,
|
69
13
|
:controller_singular_name,
|
70
14
|
:controller_plural_name
|
15
|
+
|
16
|
+
alias_method :controller_file_name,
|
17
|
+
:controller_underscore_name
|
71
18
|
|
72
|
-
alias_method :
|
73
|
-
|
74
|
-
|
19
|
+
alias_method :controller_table_name,
|
20
|
+
:controller_plural_name
|
21
|
+
|
75
22
|
def initialize(runtime_args, runtime_options = {})
|
76
23
|
super
|
77
24
|
|
78
|
-
|
25
|
+
options[:templating] = 'haml'
|
26
|
+
options[:functional_test_style] = 'basic'
|
79
27
|
|
80
28
|
@controller_name = @name.pluralize
|
81
|
-
|
82
|
-
base_name,
|
83
|
-
|
84
|
-
|
85
|
-
|
29
|
+
|
30
|
+
base_name,
|
31
|
+
@controller_class_path,
|
32
|
+
@controller_file_path,
|
33
|
+
@controller_class_nesting,
|
34
|
+
@controller_class_nesting_depth = extract_modules(@controller_name)
|
35
|
+
|
36
|
+
@controller_class_name_without_nesting,
|
37
|
+
@controller_underscore_name,
|
38
|
+
@controller_plural_name = inflect_names(base_name)
|
39
|
+
|
40
|
+
@controller_singular_name = base_name.singularize
|
41
|
+
|
86
42
|
if @controller_class_nesting.empty?
|
87
43
|
@controller_class_name = @controller_class_name_without_nesting
|
88
44
|
else
|
89
45
|
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
90
46
|
end
|
91
47
|
end
|
92
|
-
|
48
|
+
|
93
49
|
def manifest
|
94
50
|
record do |m|
|
95
51
|
# Check for class naming collisions.
|
96
|
-
m.class_collisions(controller_class_path,
|
97
|
-
|
52
|
+
m.class_collisions(controller_class_path,
|
53
|
+
"#{controller_class_name}Controller",
|
54
|
+
"#{controller_class_name}Helper")
|
98
55
|
|
56
|
+
m.class_collisions(class_path,
|
57
|
+
"#{class_name}")
|
58
|
+
|
99
59
|
# Controller, helper, views, and test directories.
|
100
|
-
m.directory(File.join('app/models',
|
101
|
-
m.directory(File.join('app/controllers',
|
102
|
-
m.directory(File.join('app/helpers',
|
103
|
-
m.directory(File.join('app/views',
|
60
|
+
m.directory(File.join('app/models', class_path))
|
61
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
62
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
63
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
104
64
|
m.directory(File.join('app/views/layouts', controller_class_path))
|
105
|
-
m.directory(File.join('test/functional',
|
106
|
-
m.directory(File.join('test/unit',
|
107
|
-
|
65
|
+
m.directory(File.join('test/functional', controller_class_path))
|
66
|
+
m.directory(File.join('test/unit', class_path))
|
67
|
+
|
108
68
|
m.directory('public/stylesheets/blueprint')
|
109
|
-
|
110
|
-
|
111
|
-
m.template(
|
112
|
-
|
113
|
-
|
114
|
-
|
69
|
+
|
70
|
+
scaffold_views.each do |view|
|
71
|
+
m.template("#{templating}/#{view}.html.#{templating}",
|
72
|
+
File.join('app/views',
|
73
|
+
controller_class_path,
|
74
|
+
controller_file_name,
|
75
|
+
"#{view}.html.#{templating}"))
|
115
76
|
end
|
116
|
-
|
77
|
+
|
117
78
|
# Layout and stylesheet.
|
118
79
|
m.template("#{templating}/layout.html.#{templating}",
|
119
80
|
File.join('app/views/layouts',
|
120
81
|
controller_class_path,
|
121
82
|
"#{controller_file_name}.html.#{templating}"))
|
122
|
-
|
123
|
-
%w(print
|
124
|
-
|
83
|
+
|
84
|
+
%w(print
|
85
|
+
screen
|
86
|
+
ie).each do |stylesheet|
|
87
|
+
m.template("blueprint/#{stylesheet}.css",
|
88
|
+
"public/stylesheets/blueprint/#{stylesheet}.css")
|
125
89
|
end
|
126
|
-
|
90
|
+
|
127
91
|
m.template('controller.rb',
|
128
92
|
File.join('app/controllers',
|
129
93
|
controller_class_path,
|
130
|
-
"#{controller_file_name}_controller.rb")
|
131
|
-
|
94
|
+
"#{controller_file_name}_controller.rb"))
|
95
|
+
|
132
96
|
m.template("functional_test/#{functional_test_style}.rb",
|
133
97
|
File.join('test/functional',
|
134
98
|
controller_class_path,
|
135
99
|
"#{controller_file_name}_controller_test.rb"))
|
136
|
-
|
100
|
+
|
137
101
|
m.template('helper.rb',
|
138
102
|
File.join('app/helpers',
|
139
103
|
controller_class_path,
|
140
104
|
"#{controller_file_name}_helper.rb"))
|
141
|
-
|
105
|
+
|
142
106
|
m.route_resources controller_file_name
|
143
|
-
|
107
|
+
|
144
108
|
m.dependency 'my_model', [name] + @args, :collision => :skip
|
145
109
|
end
|
146
110
|
end
|
147
|
-
|
111
|
+
|
148
112
|
def templating
|
149
|
-
options[:templating]
|
113
|
+
options[:templating]
|
150
114
|
end
|
151
|
-
|
115
|
+
|
152
116
|
def functional_test_style
|
153
|
-
options[:functional_test_style]
|
117
|
+
options[:functional_test_style]
|
154
118
|
end
|
155
|
-
|
119
|
+
|
156
120
|
protected
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
opt.on("--functional-test-style [basic|should_be_restful]",
|
175
|
-
"Specify the style of the functional test (should_be_restful by default)") { |v| options[:functional_test_style] = v }
|
121
|
+
def banner
|
122
|
+
"Usage: #{$0} my_scaffold ModelName [field:type, field:type]"
|
123
|
+
end
|
124
|
+
|
125
|
+
def add_options!(opt)
|
126
|
+
opt.separator ''
|
127
|
+
opt.separator 'Options:'
|
128
|
+
|
129
|
+
opt.on("--skip-timestamps",
|
130
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
131
|
+
|
132
|
+
opt.on("--skip-migration",
|
133
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
134
|
+
|
135
|
+
|
136
|
+
opt.on("--functional-test-style [basic]",
|
137
|
+
"Specify the style of the functional test (should_be_restful by default)") { |v| options[:functional_test_style] = v }
|
176
138
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
139
|
+
end
|
140
|
+
|
141
|
+
def scaffold_views
|
142
|
+
%w[ index
|
143
|
+
show
|
144
|
+
new
|
145
|
+
edit
|
146
|
+
_form ]
|
147
|
+
end
|
148
|
+
|
149
|
+
def model_name
|
150
|
+
class_name.demodulize
|
151
|
+
end
|
186
152
|
end
|
153
|
+
|
data/test/environment.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file
|
2
|
+
|
3
|
+
# Uncomment below to force Rails into production mode when
|
4
|
+
# you don't control web/app server and can't set it the proper way
|
5
|
+
# ENV['RAILS_ENV'] ||= 'production'
|
6
|
+
|
7
|
+
# Specifies gem version of Rails to use when vendor/rails is not present
|
8
|
+
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
|
9
|
+
|
10
|
+
# Bootstrap the Rails environment, frameworks, and default configuration
|
11
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
12
|
+
|
13
|
+
Rails::Initializer.run do |config|
|
14
|
+
config.time_zone = 'UTC'
|
15
|
+
|
16
|
+
config.gem 'mocha'
|
17
|
+
|
18
|
+
config.gem 'thoughtbot-shoulda', :lib => 'shoulda',
|
19
|
+
:source => "http://gems.github.com"
|
20
|
+
|
21
|
+
config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl',
|
22
|
+
:source => "http://gems.github.com"
|
23
|
+
|
24
|
+
config.gem 'my_scaffold'
|
25
|
+
|
26
|
+
config.action_controller.session = {
|
27
|
+
:session_key => '_rails_test_session',
|
28
|
+
:secret => 'a8e3520f0ba3cd7472d3c92ea082962ad2b775f13d03fc82122a68a7d58bf2eef8a5413b077b15b3e8bce847a36327c11f5b26197ed1f06a833c67e5bb778cf2'
|
29
|
+
}
|
30
|
+
end
|
data/test/my_scaffold_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stefanpenner-my_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Penner
|
@@ -40,16 +40,8 @@ files:
|
|
40
40
|
- generators/my_scaffold/templates/blueprint/print.css
|
41
41
|
- generators/my_scaffold/templates/blueprint/screen.css
|
42
42
|
- generators/my_scaffold/templates/controller.rb
|
43
|
-
- generators/my_scaffold/templates/erb
|
44
|
-
- generators/my_scaffold/templates/erb/_form.html.erb
|
45
|
-
- generators/my_scaffold/templates/erb/edit.html.erb
|
46
|
-
- generators/my_scaffold/templates/erb/index.html.erb
|
47
|
-
- generators/my_scaffold/templates/erb/layout.html.erb
|
48
|
-
- generators/my_scaffold/templates/erb/new.html.erb
|
49
|
-
- generators/my_scaffold/templates/erb/show.html.erb
|
50
43
|
- generators/my_scaffold/templates/functional_test
|
51
44
|
- generators/my_scaffold/templates/functional_test/basic.rb
|
52
|
-
- generators/my_scaffold/templates/functional_test/should_be_restful.rb
|
53
45
|
- generators/my_scaffold/templates/haml
|
54
46
|
- generators/my_scaffold/templates/haml/_form.html.haml
|
55
47
|
- generators/my_scaffold/templates/haml/edit.html.haml
|
@@ -60,6 +52,7 @@ files:
|
|
60
52
|
- generators/my_scaffold/templates/helper.rb
|
61
53
|
- generators/my_scaffold/USAGE
|
62
54
|
- lib/my_scaffold.rb
|
55
|
+
- test/environment.rb
|
63
56
|
- test/my_scaffold_test.rb
|
64
57
|
- test/test_helper.rb
|
65
58
|
has_rdoc: true
|
@@ -1,12 +0,0 @@
|
|
1
|
-
<h1>Editing <%= singular_name.humanize %></h1>
|
2
|
-
|
3
|
-
<%% form_for(@<%= singular_name %>) do |form| %>
|
4
|
-
<%%= render :partial => 'form', :locals => {:form => form} %>
|
5
|
-
<p><%%= form.submit 'Update' %></p>
|
6
|
-
<%% end %>
|
7
|
-
|
8
|
-
<p>
|
9
|
-
<%%= link_to 'Show', @<%= singular_name %> %>
|
10
|
-
|
|
11
|
-
<%%= link_to 'Back', <%= plural_name %>_path %>
|
12
|
-
</p>
|
@@ -1,22 +0,0 @@
|
|
1
|
-
<h1> Listing <%= plural_name.humanize %></h1>
|
2
|
-
|
3
|
-
<table>
|
4
|
-
<tr>
|
5
|
-
<% for attribute in attributes -%>
|
6
|
-
<th><%= attribute.column.human_name %></th>
|
7
|
-
<% end -%>
|
8
|
-
</tr>
|
9
|
-
|
10
|
-
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
11
|
-
<tr>
|
12
|
-
<% for attribute in attributes -%>
|
13
|
-
<td><%%= h <%= singular_name %>.<%= attribute.name %> %></td>
|
14
|
-
<% end -%>
|
15
|
-
<td><%%= link_to 'Show', <%= singular_name %> %></td>
|
16
|
-
<td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
|
17
|
-
<td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
|
18
|
-
</tr>
|
19
|
-
<%% end %>
|
20
|
-
</table>
|
21
|
-
|
22
|
-
<p><%%= link_to 'New <%= singular_name.humanize %>', new_<%= singular_name %>_path %></p>
|
@@ -1,22 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title><%%= "#{controller.controller_name}: #{controller.action_name}" %></title>
|
5
|
-
<%%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
|
6
|
-
<%%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
|
7
|
-
<%%= "<!--[if IE]>#{stylesheet_link_tag 'blueprint/ie', :media => 'screen'}<![endif]-->" %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
<div class="container">
|
11
|
-
<div id="content" class="column span-24">
|
12
|
-
<%% flash.each do |key, value| -%>
|
13
|
-
<div class="<%%= key %>">
|
14
|
-
<%%= h(value) %>
|
15
|
-
</div>
|
16
|
-
<%% end %>
|
17
|
-
|
18
|
-
<%%= yield %>
|
19
|
-
</div>
|
20
|
-
</div>
|
21
|
-
</body>
|
22
|
-
</html>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<h1>New <%= singular_name.humanize %></h1>
|
2
|
-
|
3
|
-
<%% form_for(@<%= singular_name %>) do |form| %>
|
4
|
-
<%%= render :partial => 'form', :locals => {:form => form} %>
|
5
|
-
<p><%%= form.submit 'Create' %></p>
|
6
|
-
<%% end %>
|
7
|
-
|
8
|
-
<p><%%= link_to 'Back', <%= plural_name %>_path %></p>
|
@@ -1,12 +0,0 @@
|
|
1
|
-
<dl>
|
2
|
-
<% for attribute in attributes -%>
|
3
|
-
<dt><%= attribute.column.human_name %></dt>
|
4
|
-
<dd><%%= h @<%= singular_name %>.<%= attribute.name %> %></dd>
|
5
|
-
<% end -%>
|
6
|
-
</dl>
|
7
|
-
|
8
|
-
<p>
|
9
|
-
<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)%>
|
10
|
-
|
|
11
|
-
<%%= link_to 'Back', <%= plural_name %>_path %>
|
12
|
-
</p>
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
-
|
3
|
-
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@<%= file_name %> = Factory(:<%= file_name %>)
|
7
|
-
end
|
8
|
-
|
9
|
-
should_be_restful do |resource|
|
10
|
-
resource.formats = [:html, :xml]
|
11
|
-
resource.destroy.flash = nil
|
12
|
-
end
|
13
|
-
end
|