flexi_generators 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +83 -70
- data/Rakefile +0 -22
- data/VERSION +1 -1
- data/flexi_generators.gemspec +75 -136
- data/init.rb +0 -1
- data/lib/flexi_generators.rb +2 -4
- data/lib/generators/flexi_auth/USAGE +5 -0
- data/lib/generators/flexi_auth/flexi_auth_generator.rb +117 -0
- data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/authentication.rb +2 -9
- data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/authlogic_session.rb +0 -0
- data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/fixtures.yml +0 -0
- data/lib/generators/flexi_auth/templates/migration.rb +16 -0
- data/lib/generators/flexi_auth/templates/sessions_controller.rb +25 -0
- data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/sessions_helper.rb +0 -0
- data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/tests/testunit/sessions_controller.rb +1 -17
- data/lib/generators/flexi_auth/templates/tests/testunit/user.rb +4 -0
- data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/tests/testunit/users_controller.rb +1 -1
- data/lib/generators/flexi_auth/templates/user.rb +3 -0
- data/lib/generators/flexi_auth/templates/users_controller.rb +42 -0
- data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/users_helper.rb +0 -0
- data/lib/generators/flexi_auth/templates/views/erb/_error_messages.html.erb +11 -0
- data/lib/generators/flexi_auth/templates/views/erb/edit.html.erb +24 -0
- data/lib/generators/flexi_auth/templates/views/erb/index.html.erb +27 -0
- data/lib/generators/flexi_auth/templates/views/erb/login.html.erb +22 -0
- data/lib/generators/flexi_auth/templates/views/erb/new.html.erb +24 -0
- data/lib/generators/flexi_auth/templates/views/erb/show.html.erb +16 -0
- data/lib/generators/flexi_prepare/USAGE +6 -0
- data/lib/generators/flexi_prepare/flexi_prepare_generator.rb +56 -0
- data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/add.png +0 -0
- data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/admin_home_controller.rb +0 -0
- data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/admin_home_index.html.erb +1 -1
- data/lib/generators/flexi_prepare/templates/application.css +278 -0
- data/lib/generators/flexi_prepare/templates/application.html.erb +57 -0
- data/lib/generators/flexi_prepare/templates/application_helper.rb +42 -0
- data/lib/generators/flexi_prepare/templates/back.png +0 -0
- data/lib/generators/flexi_prepare/templates/bg.png +0 -0
- data/lib/generators/flexi_prepare/templates/bg2.png +0 -0
- data/lib/generators/flexi_prepare/templates/boxheader.gif +0 -0
- data/lib/generators/flexi_prepare/templates/btn-bg-hover.png +0 -0
- data/lib/generators/flexi_prepare/templates/btn-bg.png +0 -0
- data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/custom_field_error.rb +1 -1
- data/lib/generators/flexi_prepare/templates/delete.png +0 -0
- data/lib/generators/flexi_prepare/templates/edit.png +0 -0
- data/lib/generators/flexi_prepare/templates/inflector_portuguese.rb +59 -0
- data/lib/generators/flexi_prepare/templates/login.css +142 -0
- data/lib/generators/flexi_prepare/templates/login.html.erb +26 -0
- data/lib/generators/flexi_prepare/templates/logo.png +0 -0
- data/lib/generators/flexi_prepare/templates/menu.png +0 -0
- data/lib/generators/flexi_prepare/templates/messages/Thumbs.db +0 -0
- data/lib/generators/flexi_prepare/templates/messages/error.png +0 -0
- data/lib/generators/flexi_prepare/templates/messages/info.png +0 -0
- data/lib/generators/flexi_prepare/templates/messages/success.png +0 -0
- data/lib/generators/flexi_prepare/templates/messages/tip.png +0 -0
- data/lib/generators/flexi_prepare/templates/messages/warning.png +0 -0
- data/lib/generators/flexi_prepare/templates/pt-BR.yml +204 -0
- data/lib/generators/flexi_prepare/templates/show.png +0 -0
- data/{generators/flexi_layout/templates/stylesheet_site.css → lib/generators/flexi_prepare/templates/site.css} +32 -23
- data/lib/generators/flexi_prepare/templates/site.html.erb +20 -0
- data/{generators/flexi_layout/templates/home_controller.rb → lib/generators/flexi_prepare/templates/site_controller.rb} +1 -1
- data/lib/generators/flexi_prepare/templates/site_helper.rb +2 -0
- data/lib/generators/flexi_prepare/templates/site_index.html.erb +27 -0
- data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/users.png +0 -0
- data/lib/generators/flexi_scaffold/USAGE +8 -0
- data/lib/generators/flexi_scaffold/flexi_scaffold_generator.rb +98 -0
- data/lib/generators/flexi_scaffold/templates/controller.rb +42 -0
- data/{generators → lib/generators}/flexi_scaffold/templates/fixtures.yml +3 -3
- data/{generators → lib/generators}/flexi_scaffold/templates/helper.rb +1 -1
- data/{generators → lib/generators}/flexi_scaffold/templates/migration.rb +3 -5
- data/lib/generators/flexi_scaffold/templates/model.rb +3 -0
- data/lib/generators/flexi_scaffold/templates/tests/controller.rb +50 -0
- data/lib/generators/flexi_scaffold/templates/tests/helper.rb +4 -0
- data/{test/flexi_generators_test.rb → lib/generators/flexi_scaffold/templates/tests/model.rb} +2 -2
- data/lib/generators/flexi_scaffold/templates/views/erb/_error_messages.html.erb +11 -0
- data/lib/generators/flexi_scaffold/templates/views/erb/_form.html.erb +13 -0
- data/lib/generators/flexi_scaffold/templates/views/erb/edit.html.erb +3 -0
- data/lib/generators/flexi_scaffold/templates/views/erb/index.html.erb +29 -0
- data/lib/generators/flexi_scaffold/templates/views/erb/new.html.erb +3 -0
- data/lib/generators/flexi_scaffold/templates/views/erb/show.html.erb +15 -0
- data/template.rb +6 -0
- metadata +79 -137
- data/flexi_template.rb +0 -28
- data/generators/flexi_authentication/USAGE +0 -50
- data/generators/flexi_authentication/flexi_authentication_generator.rb +0 -127
- data/generators/flexi_authentication/lib/insert_commands.rb +0 -74
- data/generators/flexi_authentication/templates/admin_users_controller.rb +0 -60
- data/generators/flexi_authentication/templates/migration.rb +0 -30
- data/generators/flexi_authentication/templates/sessions_controller.rb +0 -52
- data/generators/flexi_authentication/templates/tests/rspec/sessions_controller.rb +0 -39
- data/generators/flexi_authentication/templates/tests/rspec/user.rb +0 -83
- data/generators/flexi_authentication/templates/tests/rspec/users_controller.rb +0 -26
- data/generators/flexi_authentication/templates/tests/shoulda/sessions_controller.rb +0 -40
- data/generators/flexi_authentication/templates/tests/shoulda/user.rb +0 -85
- data/generators/flexi_authentication/templates/tests/shoulda/users_controller.rb +0 -27
- data/generators/flexi_authentication/templates/tests/testunit/user.rb +0 -88
- data/generators/flexi_authentication/templates/user.rb +0 -43
- data/generators/flexi_authentication/templates/views/erb/admin_user_edit.html.erb +0 -23
- data/generators/flexi_authentication/templates/views/erb/admin_user_index.html.erb +0 -33
- data/generators/flexi_authentication/templates/views/erb/admin_user_new.html.erb +0 -23
- data/generators/flexi_authentication/templates/views/erb/login.html.erb +0 -38
- data/generators/flexi_layout/USAGE +0 -18
- data/generators/flexi_layout/flexi_layout_generator.rb +0 -51
- data/generators/flexi_layout/lib/insert_commands.rb +0 -28
- data/generators/flexi_layout/templates/bg.png +0 -0
- data/generators/flexi_layout/templates/helper.rb +0 -19
- data/generators/flexi_layout/templates/home_helper.rb +0 -2
- data/generators/flexi_layout/templates/home_index.html.erb +0 -17
- data/generators/flexi_layout/templates/inflector_portuguese.rb +0 -62
- data/generators/flexi_layout/templates/layout.html.erb +0 -47
- data/generators/flexi_layout/templates/layout_login.html.erb +0 -27
- data/generators/flexi_layout/templates/layout_site.html.erb +0 -22
- data/generators/flexi_layout/templates/logo.png +0 -0
- data/generators/flexi_layout/templates/pt-BR.yml +0 -143
- data/generators/flexi_layout/templates/stylesheet.css +0 -132
- data/generators/flexi_layout/templates/stylesheet_login.css +0 -73
- data/generators/flexi_resource_scaffold/USAGE +0 -29
- data/generators/flexi_resource_scaffold/flexi_resource_scaffold_generator.rb +0 -179
- data/generators/flexi_resource_scaffold/templates/controller.rb +0 -29
- data/generators/flexi_resource_scaffold/templates/fixtures.yml +0 -10
- data/generators/flexi_resource_scaffold/templates/functional_test.rb +0 -57
- data/generators/flexi_resource_scaffold/templates/helper.rb +0 -2
- data/generators/flexi_resource_scaffold/templates/migration.rb +0 -15
- data/generators/flexi_resource_scaffold/templates/model.rb +0 -2
- data/generators/flexi_resource_scaffold/templates/old_migration.rb +0 -13
- data/generators/flexi_resource_scaffold/templates/rspec/functional_spec.rb +0 -255
- data/generators/flexi_resource_scaffold/templates/rspec/helper_spec.rb +0 -11
- data/generators/flexi_resource_scaffold/templates/rspec/routing_spec.rb +0 -61
- data/generators/flexi_resource_scaffold/templates/rspec/unit_spec.rb +0 -11
- data/generators/flexi_resource_scaffold/templates/rspec/views/edit_spec.rb +0 -28
- data/generators/flexi_resource_scaffold/templates/rspec/views/index_spec.rb +0 -26
- data/generators/flexi_resource_scaffold/templates/rspec/views/new_spec.rb +0 -30
- data/generators/flexi_resource_scaffold/templates/rspec/views/show_spec.rb +0 -25
- data/generators/flexi_resource_scaffold/templates/shoulda_functional_test.rb +0 -19
- data/generators/flexi_resource_scaffold/templates/unit_test.rb +0 -7
- data/generators/flexi_resource_scaffold/templates/view__form.erb +0 -6
- data/generators/flexi_resource_scaffold/templates/view__form.haml +0 -5
- data/generators/flexi_resource_scaffold/templates/view_edit.erb +0 -8
- data/generators/flexi_resource_scaffold/templates/view_edit.haml +0 -11
- data/generators/flexi_resource_scaffold/templates/view_index.erb +0 -27
- data/generators/flexi_resource_scaffold/templates/view_index.haml +0 -19
- data/generators/flexi_resource_scaffold/templates/view_new.erb +0 -9
- data/generators/flexi_resource_scaffold/templates/view_new.haml +0 -9
- data/generators/flexi_resource_scaffold/templates/view_show.erb +0 -10
- data/generators/flexi_resource_scaffold/templates/view_show.haml +0 -9
- data/generators/flexi_scaffold/USAGE +0 -51
- data/generators/flexi_scaffold/flexi_scaffold_generator.rb +0 -232
- data/generators/flexi_scaffold/templates/actions/create.rb +0 -9
- data/generators/flexi_scaffold/templates/actions/destroy.rb +0 -6
- data/generators/flexi_scaffold/templates/actions/edit.rb +0 -3
- data/generators/flexi_scaffold/templates/actions/index.rb +0 -4
- data/generators/flexi_scaffold/templates/actions/new.rb +0 -3
- data/generators/flexi_scaffold/templates/actions/show.rb +0 -3
- data/generators/flexi_scaffold/templates/actions/update.rb +0 -9
- data/generators/flexi_scaffold/templates/controller.rb +0 -5
- data/generators/flexi_scaffold/templates/model.rb +0 -3
- data/generators/flexi_scaffold/templates/tests/rspec/actions/create.rb +0 -11
- data/generators/flexi_scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
- data/generators/flexi_scaffold/templates/tests/rspec/actions/edit.rb +0 -4
- data/generators/flexi_scaffold/templates/tests/rspec/actions/index.rb +0 -4
- data/generators/flexi_scaffold/templates/tests/rspec/actions/new.rb +0 -4
- data/generators/flexi_scaffold/templates/tests/rspec/actions/show.rb +0 -4
- data/generators/flexi_scaffold/templates/tests/rspec/actions/update.rb +0 -11
- data/generators/flexi_scaffold/templates/tests/rspec/controller.rb +0 -8
- data/generators/flexi_scaffold/templates/tests/rspec/model.rb +0 -7
- data/generators/flexi_scaffold/templates/tests/shoulda/actions/create.rb +0 -13
- data/generators/flexi_scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
- data/generators/flexi_scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
- data/generators/flexi_scaffold/templates/tests/shoulda/actions/index.rb +0 -6
- data/generators/flexi_scaffold/templates/tests/shoulda/actions/new.rb +0 -6
- data/generators/flexi_scaffold/templates/tests/shoulda/actions/show.rb +0 -6
- data/generators/flexi_scaffold/templates/tests/shoulda/actions/update.rb +0 -13
- data/generators/flexi_scaffold/templates/tests/shoulda/controller.rb +0 -5
- data/generators/flexi_scaffold/templates/tests/shoulda/model.rb +0 -7
- data/generators/flexi_scaffold/templates/tests/testunit/actions/create.rb +0 -11
- data/generators/flexi_scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
- data/generators/flexi_scaffold/templates/tests/testunit/actions/edit.rb +0 -4
- data/generators/flexi_scaffold/templates/tests/testunit/actions/index.rb +0 -4
- data/generators/flexi_scaffold/templates/tests/testunit/actions/new.rb +0 -4
- data/generators/flexi_scaffold/templates/tests/testunit/actions/show.rb +0 -4
- data/generators/flexi_scaffold/templates/tests/testunit/actions/update.rb +0 -11
- data/generators/flexi_scaffold/templates/tests/testunit/controller.rb +0 -5
- data/generators/flexi_scaffold/templates/tests/testunit/model.rb +0 -7
- data/generators/flexi_scaffold/templates/views/erb/_form.html.erb +0 -6
- data/generators/flexi_scaffold/templates/views/erb/edit.html.erb +0 -8
- data/generators/flexi_scaffold/templates/views/erb/index.html.erb +0 -41
- data/generators/flexi_scaffold/templates/views/erb/new.html.erb +0 -10
- data/generators/flexi_scaffold/templates/views/erb/show.html.erb +0 -19
- data/generators/flexi_scaffold/templates/views/haml/_form.html.haml +0 -10
- data/generators/flexi_scaffold/templates/views/haml/edit.html.haml +0 -14
- data/generators/flexi_scaffold/templates/views/haml/index.html.haml +0 -25
- data/generators/flexi_scaffold/templates/views/haml/new.html.haml +0 -7
- data/generators/flexi_scaffold/templates/views/haml/show.html.haml +0 -20
- data/test/test_helper.rb +0 -3
@@ -1,51 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
Scaffolds an entire resource, from model and migration to controller and
|
3
|
-
views. The resource is ready to use as a starting point for your restful,
|
4
|
-
resource-oriented application. Tests or specs are also generated depending
|
5
|
-
on if you have a "spec" directory or not.
|
6
|
-
|
7
|
-
IMPORTANT: This generator uses the "title" helper method which is generated
|
8
|
-
by the flexi_layout generator. You may want to run that generator first.
|
9
|
-
|
10
|
-
Usage:
|
11
|
-
Pass the name of the model, either CamelCased or under_scored, as the first
|
12
|
-
argument, and an optional list of attribute pairs and controller actions.
|
13
|
-
|
14
|
-
If no controller actions are specified, they will default to index, show,
|
15
|
-
new, create, edit, update, and destroy.
|
16
|
-
|
17
|
-
IMPORTANT: If no attribute pairs are specified, no model will be generated.
|
18
|
-
It will try to determine the attributes from an existing model.
|
19
|
-
|
20
|
-
Attribute pairs are column_name:sql_type arguments specifying the
|
21
|
-
model's attributes. Timestamps are added by default, so you don't have to
|
22
|
-
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
23
|
-
|
24
|
-
For example, `flexi_scaffold post name:string content:text hidden:boolean`
|
25
|
-
gives you a model with those three attributes, a controller that handles
|
26
|
-
the create/show/update/destroy, forms to create and edit your posts, and
|
27
|
-
an index that lists them all, as well as a map.resources :posts
|
28
|
-
declaration in config/routes.rb.
|
29
|
-
|
30
|
-
Adding an "!" in the mix of arguments will invert the passed controller
|
31
|
-
actions. This will include all 7 controller actitons except the ones
|
32
|
-
mentioned. This option doesn't effect model attributes.
|
33
|
-
|
34
|
-
Examples:
|
35
|
-
script/generate flexi_scaffold post
|
36
|
-
|
37
|
-
Will create a controller called "posts" it will contain all seven
|
38
|
-
CRUD actions along with the views. A model will NOT be created,
|
39
|
-
instead it will look for an existing model and use those attributes.
|
40
|
-
|
41
|
-
script/generate flexi_scaffold post name:string content:text index new edit
|
42
|
-
|
43
|
-
Will create a Post model and migration file with the name and content
|
44
|
-
attributes. It will also create a controller with index, new, create,
|
45
|
-
edit, and update actions. Notice the create and update actions are
|
46
|
-
added automatically with new and edit.
|
47
|
-
|
48
|
-
script/generate flexi_scaffold post ! show new
|
49
|
-
|
50
|
-
Creates a posts controller (no model) with index, edit, update, and
|
51
|
-
destroy actions.
|
@@ -1,232 +0,0 @@
|
|
1
|
-
class FlexiScaffoldGenerator < Rails::Generator::Base
|
2
|
-
attr_accessor :name, :attributes, :controller_actions
|
3
|
-
|
4
|
-
def initialize(runtime_args, runtime_options = {})
|
5
|
-
super
|
6
|
-
usage if @args.empty?
|
7
|
-
|
8
|
-
@name = @args.first
|
9
|
-
@controller_actions = []
|
10
|
-
@attributes = []
|
11
|
-
|
12
|
-
@args[1..-1].each do |arg|
|
13
|
-
if arg == '!'
|
14
|
-
options[:invert] = true
|
15
|
-
elsif arg.include? ':'
|
16
|
-
@attributes << Rails::Generator::GeneratedAttribute.new(*arg.split(":"))
|
17
|
-
else
|
18
|
-
@controller_actions << arg
|
19
|
-
@controller_actions << 'create' if arg == 'new'
|
20
|
-
@controller_actions << 'update' if arg == 'edit'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
@controller_actions.uniq!
|
25
|
-
@attributes.uniq!
|
26
|
-
|
27
|
-
if options[:invert] || @controller_actions.empty?
|
28
|
-
@controller_actions = all_actions - @controller_actions
|
29
|
-
end
|
30
|
-
|
31
|
-
if @attributes.empty?
|
32
|
-
options[:skip_model] = true # default to skipping model if no attributes passed
|
33
|
-
if model_exists?
|
34
|
-
model_columns_for_attributes.each do |column|
|
35
|
-
@attributes << Rails::Generator::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
36
|
-
end
|
37
|
-
else
|
38
|
-
@attributes << Rails::Generator::GeneratedAttribute.new('name', 'string')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def manifest
|
44
|
-
record do |m|
|
45
|
-
unless options[:skip_model]
|
46
|
-
m.directory "app/models"
|
47
|
-
m.template "model.rb", "app/models/#{singular_name}.rb"
|
48
|
-
unless options[:skip_migration]
|
49
|
-
m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
|
50
|
-
end
|
51
|
-
|
52
|
-
if rspec?
|
53
|
-
m.directory "spec/models"
|
54
|
-
m.template "tests/#{test_framework}/model.rb", "spec/models/#{singular_name}_spec.rb"
|
55
|
-
m.directory "spec/fixtures"
|
56
|
-
m.template "fixtures.yml", "spec/fixtures/#{plural_name}.yml"
|
57
|
-
else
|
58
|
-
m.directory "test/unit"
|
59
|
-
m.template "tests/#{test_framework}/model.rb", "test/unit/#{singular_name}_test.rb"
|
60
|
-
m.directory "test/fixtures"
|
61
|
-
m.template "fixtures.yml", "test/fixtures/#{plural_name}.yml"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
unless options[:skip_controller]
|
66
|
-
m.directory "app/controllers"
|
67
|
-
m.template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
|
68
|
-
|
69
|
-
m.directory "app/helpers"
|
70
|
-
m.template "helper.rb", "app/helpers/#{plural_name}_helper.rb"
|
71
|
-
|
72
|
-
m.directory "app/views/#{plural_name}"
|
73
|
-
controller_actions.each do |action|
|
74
|
-
if File.exist? source_path("views/#{view_language}/#{action}.html.#{view_language}")
|
75
|
-
m.template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
if form_partial?
|
80
|
-
m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
|
81
|
-
end
|
82
|
-
|
83
|
-
m.route_resources plural_name
|
84
|
-
|
85
|
-
if rspec?
|
86
|
-
m.directory "spec/controllers"
|
87
|
-
m.template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
|
88
|
-
else
|
89
|
-
m.directory "test/functional"
|
90
|
-
m.template "tests/#{test_framework}/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def form_partial?
|
97
|
-
actions? :new, :edit
|
98
|
-
end
|
99
|
-
|
100
|
-
def all_actions
|
101
|
-
%w[index show new create edit update destroy]
|
102
|
-
end
|
103
|
-
|
104
|
-
def action?(name)
|
105
|
-
controller_actions.include? name.to_s
|
106
|
-
end
|
107
|
-
|
108
|
-
def actions?(*names)
|
109
|
-
names.all? { |n| action? n.to_s }
|
110
|
-
end
|
111
|
-
|
112
|
-
def singular_name
|
113
|
-
name.underscore
|
114
|
-
end
|
115
|
-
|
116
|
-
def plural_name
|
117
|
-
name.underscore.pluralize
|
118
|
-
end
|
119
|
-
|
120
|
-
def class_name
|
121
|
-
name.camelize
|
122
|
-
end
|
123
|
-
|
124
|
-
def plural_class_name
|
125
|
-
plural_name.camelize
|
126
|
-
end
|
127
|
-
|
128
|
-
def controller_methods(dir_name)
|
129
|
-
controller_actions.map do |action|
|
130
|
-
read_template("#{dir_name}/#{action}.rb")
|
131
|
-
end.join(" \n").strip
|
132
|
-
end
|
133
|
-
|
134
|
-
def render_form
|
135
|
-
if form_partial?
|
136
|
-
if options[:haml]
|
137
|
-
"= render :partial => 'form', :locals => { :f => f }"
|
138
|
-
else
|
139
|
-
"<%= render :partial => 'form', :locals => { :f => f } %>"
|
140
|
-
end
|
141
|
-
else
|
142
|
-
read_template("views/#{view_language}/_form.html.#{view_language}")
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def items_path(suffix = 'path')
|
147
|
-
if action? :index
|
148
|
-
"#{plural_name}_#{suffix}"
|
149
|
-
else
|
150
|
-
"root_#{suffix}"
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def item_path(suffix = 'path')
|
155
|
-
if action? :show
|
156
|
-
"@#{singular_name}"
|
157
|
-
else
|
158
|
-
items_path(suffix)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def item_path_for_spec(suffix = 'path')
|
163
|
-
if action? :show
|
164
|
-
"#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
|
165
|
-
else
|
166
|
-
items_path(suffix)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def item_path_for_test(suffix = 'path')
|
171
|
-
if action? :show
|
172
|
-
"#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
|
173
|
-
else
|
174
|
-
items_path(suffix)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def model_columns_for_attributes
|
179
|
-
class_name.constantize.columns.reject do |column|
|
180
|
-
column.name.to_s =~ /^(id|created_at|updated_at)$/
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def rspec?
|
185
|
-
test_framework == :rspec
|
186
|
-
end
|
187
|
-
|
188
|
-
protected
|
189
|
-
|
190
|
-
def view_language
|
191
|
-
options[:haml] ? 'haml' : 'erb'
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_framework
|
195
|
-
options[:test_framework] ||= default_test_framework
|
196
|
-
end
|
197
|
-
|
198
|
-
def default_test_framework
|
199
|
-
File.exist?(destination_path("spec")) ? :rspec : :testunit
|
200
|
-
end
|
201
|
-
|
202
|
-
def add_options!(opt)
|
203
|
-
opt.separator ''
|
204
|
-
opt.separator 'Options:'
|
205
|
-
opt.on("--skip-model", "Don't generate a model or migration file.") { |v| options[:skip_model] = v }
|
206
|
-
opt.on("--skip-migration", "Don't generate migration file for model.") { |v| options[:skip_migration] = v }
|
207
|
-
opt.on("--skip-timestamps", "Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
|
208
|
-
opt.on("--skip-controller", "Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
|
209
|
-
opt.on("--invert", "Generate all controller actions except these mentioned.") { |v| options[:invert] = v }
|
210
|
-
opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = v }
|
211
|
-
opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
|
212
|
-
opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
|
213
|
-
opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
|
214
|
-
end
|
215
|
-
|
216
|
-
# is there a better way to do this? Perhaps with const_defined?
|
217
|
-
def model_exists?
|
218
|
-
File.exist? destination_path("app/models/#{singular_name}.rb")
|
219
|
-
end
|
220
|
-
|
221
|
-
def read_template(relative_path)
|
222
|
-
ERB.new(File.read(source_path(relative_path)), nil, '-').result(binding)
|
223
|
-
end
|
224
|
-
|
225
|
-
def banner
|
226
|
-
<<-EOS
|
227
|
-
Creates a controller and optional model given the name, actions, and attributes.
|
228
|
-
|
229
|
-
USAGE: #{$0} #{spec.name} ModelName [controller_actions and model:attributes] [options]
|
230
|
-
EOS
|
231
|
-
end
|
232
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
def create
|
2
|
-
@<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
|
3
|
-
if @<%= singular_name %>.save
|
4
|
-
flash[:notice] = "<%= singular_name.capitalize %> adicionada com sucesso!"
|
5
|
-
redirect_to <%= item_path('url') %>
|
6
|
-
else
|
7
|
-
render :action => 'new'
|
8
|
-
end
|
9
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
def update
|
2
|
-
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
3
|
-
if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
|
4
|
-
flash[:notice] = "<%= singular_name.capitalize %> alterada com sucesso!"
|
5
|
-
redirect_to <%= item_path('url') %>
|
6
|
-
else
|
7
|
-
render :action => 'edit'
|
8
|
-
end
|
9
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
it "create action should render new template when model is invalid" do
|
2
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
-
post :create
|
4
|
-
response.should render_template(:new)
|
5
|
-
end
|
6
|
-
|
7
|
-
it "create action should redirect when model is valid" do
|
8
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
-
post :create
|
10
|
-
response.should redirect_to(<%= item_path_for_spec('url') %>)
|
11
|
-
end
|
@@ -1,6 +0,0 @@
|
|
1
|
-
it "destroy action should destroy model and redirect to index action" do
|
2
|
-
<%= singular_name %> = <%= class_name %>.first
|
3
|
-
delete :destroy, :id => <%= singular_name %>
|
4
|
-
response.should redirect_to(<%= items_path('url') %>)
|
5
|
-
<%= class_name %>.exists?(<%= singular_name %>.id).should be_false
|
6
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
it "update action should render edit template when model is invalid" do
|
2
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
-
put :update, :id => <%= class_name %>.first
|
4
|
-
response.should render_template(:edit)
|
5
|
-
end
|
6
|
-
|
7
|
-
it "update action should redirect when model is valid" do
|
8
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
-
put :update, :id => <%= class_name %>.first
|
10
|
-
response.should redirect_to(<%= item_path_for_spec('url') %>)
|
11
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
context "create action" do
|
2
|
-
should "render new template when model is invalid" do
|
3
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
4
|
-
post :create
|
5
|
-
assert_template 'new'
|
6
|
-
end
|
7
|
-
|
8
|
-
should "redirect when model is valid" do
|
9
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
10
|
-
post :create
|
11
|
-
assert_redirected_to <%= item_path_for_test('url') %>
|
12
|
-
end
|
13
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
context "destroy action" do
|
2
|
-
should "destroy model and redirect to index action" do
|
3
|
-
<%= singular_name %> = <%= class_name %>.first
|
4
|
-
delete :destroy, :id => <%= singular_name %>
|
5
|
-
assert_redirected_to <%= items_path('url') %>
|
6
|
-
assert !<%= class_name %>.exists?(<%= singular_name %>.id)
|
7
|
-
end
|
8
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
context "update action" do
|
2
|
-
should "render edit template when model is invalid" do
|
3
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
4
|
-
put :update, :id => <%= class_name %>.first
|
5
|
-
assert_template 'edit'
|
6
|
-
end
|
7
|
-
|
8
|
-
should "redirect when model is valid" do
|
9
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
10
|
-
put :update, :id => <%= class_name %>.first
|
11
|
-
assert_redirected_to <%= item_path_for_test('url') %>
|
12
|
-
end
|
13
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
def test_create_invalid
|
2
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
-
post :create
|
4
|
-
assert_template 'new'
|
5
|
-
end
|
6
|
-
|
7
|
-
def test_create_valid
|
8
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
-
post :create
|
10
|
-
assert_redirected_to <%= item_path_for_test('url') %>
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
def test_update_invalid
|
2
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
-
put :update, :id => <%= class_name %>.first
|
4
|
-
assert_template 'edit'
|
5
|
-
end
|
6
|
-
|
7
|
-
def test_update_valid
|
8
|
-
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
-
put :update, :id => <%= class_name %>.first
|
10
|
-
assert_redirected_to <%= item_path_for_test('url') %>
|
11
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<%% title("Editando <%= singular_name.titleize %>") %>
|
2
|
-
|
3
|
-
<%% form_for @<%= singular_name %> do |f| %>
|
4
|
-
<%= render_form %>
|
5
|
-
<div id="control_box">
|
6
|
-
<%%= submit_tag "Alterar" %> | <% if action? :index %> <%%= link_to "Cancelar", <%= plural_name %>_path %> <% end %>
|
7
|
-
</div>
|
8
|
-
<%% end %>
|
@@ -1,41 +0,0 @@
|
|
1
|
-
<%% title("<%= plural_name.titleize %>")%>
|
2
|
-
|
3
|
-
<%- if action? :new -%>
|
4
|
-
<div id="new_box">
|
5
|
-
<%%= link_to('Adicionar <%= singular_name.titleize %>', new_<%= singular_name %>_path, :class =>'new') %>
|
6
|
-
</div>
|
7
|
-
<%- end -%>
|
8
|
-
|
9
|
-
<table cellspacing="1" cellpadding="2">
|
10
|
-
<tr>
|
11
|
-
<%- for attribute in attributes -%>
|
12
|
-
<th><%= attribute.column.human_name.titleize %></th>
|
13
|
-
<%- end -%>
|
14
|
-
<%- if action? :show -%>
|
15
|
-
<th></th>
|
16
|
-
<%- end -%>
|
17
|
-
<%- if action? :edit -%>
|
18
|
-
<th></th>
|
19
|
-
<%- end -%>
|
20
|
-
<%- if action? :destroy -%>
|
21
|
-
<th></th>
|
22
|
-
<%- end -%>
|
23
|
-
</tr>
|
24
|
-
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
25
|
-
<tr>
|
26
|
-
<%- for attribute in attributes -%>
|
27
|
-
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
28
|
-
<% end %>
|
29
|
-
<%- if action? :show -%>
|
30
|
-
<td width="6%" align="center"><%%= link_to "Ver", <%= singular_name %>, :class=>'view' %></td>
|
31
|
-
<%- end -%>
|
32
|
-
<%- if action? :edit -%>
|
33
|
-
<td width="6%" align="center"><%%= link_to "Editar", edit_<%= singular_name %>_path(<%= singular_name %>), :class=>'edit' %></td>
|
34
|
-
<%- end -%>
|
35
|
-
<%- if action? :destroy -%>
|
36
|
-
<td width="6%" align="center"><%%= link_to "Excluir", <%= singular_name %>, :class=>'delete', :confirm => 'Tem certeza que deseja excluir?', :method => :delete %></td>
|
37
|
-
<%- end -%>
|
38
|
-
</tr>
|
39
|
-
<%% end %>
|
40
|
-
</table>
|
41
|
-
<%%= will_paginate @<%= plural_name %>, :previous_label=>'« Anterior', :next_label=>'Próximo »' %>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<%% title("Nova <%= singular_name.titleize %>") %>
|
2
|
-
|
3
|
-
<%% form_for @<%= singular_name %> do |f| %>
|
4
|
-
<%= render_form %>
|
5
|
-
<div id="control_box">
|
6
|
-
<%%= submit_tag "Salvar" %> | <% if action? :index -%> <%%= link_to "Cancelar", <%= plural_name %>_path %> <% end %>
|
7
|
-
</div>
|
8
|
-
<%% end %>
|
9
|
-
|
10
|
-
|