leonardo 1.4.0 → 1.5.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/CHANGELOG +17 -0
- data/README.rdoc +13 -10
- data/lib/generators/base.rb +28 -0
- data/lib/generators/erb/leosca/leosca_generator.rb +11 -0
- data/lib/generators/erb/leosca/templates/_list.erb +14 -10
- data/lib/generators/erb/leosca/templates/destroy.js.erb +1 -1
- data/lib/generators/erb/leosca/templates/show.html.erb +1 -1
- data/lib/generators/leolay/install_generator.rb +17 -0
- data/lib/generators/leolay/leolay_generator.rb +47 -0
- data/lib/generators/leolay/templates/config/locales/devise.en.yml +4 -0
- data/lib/generators/leolay/templates/config/locales/devise.it.yml +4 -0
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/controller_spec.rb +181 -0
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/edit_spec.rb +18 -0
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/index_spec.rb +41 -0
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/new_spec.rb +19 -0
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/show_spec.rb +28 -0
- data/lib/generators/leolay/templates/spec/factories.rb +23 -0
- data/lib/generators/leolay/templates/spec/helpers/application_helpers_spec.rb +13 -0
- data/lib/generators/leolay/templates/spec/support/devise.rb +4 -0
- data/lib/generators/leosca/install_generator.rb +1 -0
- data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +152 -20
- data/lib/generators/rails/leosca_controller/templates/controller.rb +1 -1
- data/template.rb +119 -107
- metadata +15 -5
data/CHANGELOG
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
1.5.0 (September 6th, 2011) Marco Mastrodonato
|
2
|
+
* Added Rspec support with requests to check ajax => All green if you use formtastic views (associations with select)
|
3
|
+
* New template
|
4
|
+
* Little improvements
|
5
|
+
|
6
|
+
Next release:
|
7
|
+
* Nested resource
|
8
|
+
* Code improvements
|
9
|
+
|
10
|
+
|
11
|
+
1.4.1 (August 25th, 2011) Marco Mastrodonato
|
12
|
+
* Autocheck to exclude pagination from views and controller
|
13
|
+
* Fixed the template.rb to generate rspec:install and added :development to group as well as :test. Now if you choose to use rspec, leosca will generate rspec test.
|
14
|
+
* Added leolay:install to copy generator under project folder to be able to customize it like leosca:install
|
15
|
+
|
16
|
+
|
17
|
+
|
1
18
|
1.4.0 (August 24th, 2011) Marco Mastrodonato
|
2
19
|
* New file custom.js to fill with your javascripts and use application.js as manifest file
|
3
20
|
* Two new files under vendor/assets folder: vendor.js and vendor.css to use as manifest file
|
data/README.rdoc
CHANGED
@@ -46,6 +46,7 @@ Will be:
|
|
46
46
|
2. If you have used my template you have an application ready to work:
|
47
47
|
run rails s and try it on http://localhost:3000
|
48
48
|
if you chose authentication you have to sign in, try with this different profile:
|
49
|
+
|
49
50
|
email: admin@AppExample.com, password: abcd1234
|
50
51
|
[this profile can do everything]
|
51
52
|
or
|
@@ -84,25 +85,27 @@ Go to lib\generators\rails if you want to customize more.
|
|
84
85
|
|
85
86
|
For more information about usage:
|
86
87
|
|
87
|
-
rails g leolay --help
|
88
|
-
|
88
|
+
rails g leolay --help
|
89
|
+
|
90
|
+
rails g leosca --help
|
89
91
|
|
90
92
|
|
91
93
|
=== Example:
|
92
94
|
|
93
95
|
leolay:
|
94
96
|
|
95
|
-
rails generate leolay
|
96
|
-
rails generate leolay --main_color=#c8c8c8
|
97
|
-
rails generate leolay layout1 --main_color=rgb(200,150,200) --second-color=yellow
|
98
|
-
rails generate leolay layout2 --skip-pagination --skip-authentication --skip-authorization
|
97
|
+
rails generate leolay
|
98
|
+
rails generate leolay --main_color=#c8c8c8
|
99
|
+
rails generate leolay layout1 --main_color=rgb(200,150,200) --second-color=yellow
|
100
|
+
rails generate leolay layout2 --skip-pagination --skip-authentication --skip-authorization
|
99
101
|
|
100
102
|
leosca:
|
101
103
|
|
102
|
-
rails generate leosca product name:string
|
103
|
-
rails generate leosca product name:string --skip-remote => if you do not want ajax
|
104
|
-
rails generate leosca product name:string --skip-seeds
|
105
|
-
rails generate leosca product name:string --seeds=60 => if you need more records
|
104
|
+
rails generate leosca product name:string
|
105
|
+
rails generate leosca product name:string --skip-remote => if you do not want ajax
|
106
|
+
rails generate leosca product name:string --skip-seeds
|
107
|
+
rails generate leosca product name:string --seeds=60 => if you need more records
|
108
|
+
|
106
109
|
|
107
110
|
PS: Of course, these options are in addition to those provided by the original scaffold
|
108
111
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module LeonardoShared
|
2
|
+
def prova
|
3
|
+
puts 'ok'
|
4
|
+
end
|
5
|
+
|
6
|
+
protected
|
7
|
+
def authorization?
|
8
|
+
File.exists? "app/models/ability.rb"
|
9
|
+
end
|
10
|
+
def authentication?
|
11
|
+
return true if File.exists? "app/models/user.rb"
|
12
|
+
File.exists? "config/initializers/devise.rb"
|
13
|
+
end
|
14
|
+
def camel_case(str)
|
15
|
+
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
16
|
+
str.split('_').map { |i| i.capitalize }.join
|
17
|
+
end
|
18
|
+
def formtastic?
|
19
|
+
return false unless options.formtastic?
|
20
|
+
File.exists? "config/initializers/formtastic.rb"
|
21
|
+
end
|
22
|
+
def jquery_ui?
|
23
|
+
File.exists? "vendor/assets/javascripts/jquery-ui"
|
24
|
+
end
|
25
|
+
def pagination?
|
26
|
+
File.exists? "config/initializers/kaminari_config.rb"
|
27
|
+
end
|
28
|
+
end
|
@@ -64,6 +64,14 @@ module Erb
|
|
64
64
|
def authorization?
|
65
65
|
File.exists? "app/models/ability.rb"
|
66
66
|
end
|
67
|
+
def authentication?
|
68
|
+
return true if File.exists? "app/models/user.rb"
|
69
|
+
File.exists? "config/initializers/devise.rb"
|
70
|
+
end
|
71
|
+
def camel_case(str)
|
72
|
+
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
73
|
+
str.split('_').map { |i| i.capitalize }.join
|
74
|
+
end
|
67
75
|
def formtastic?
|
68
76
|
return false unless options.formtastic?
|
69
77
|
File.exists? "config/initializers/formtastic.rb"
|
@@ -71,6 +79,9 @@ module Erb
|
|
71
79
|
def jquery_ui?
|
72
80
|
File.exists? "vendor/assets/javascripts/jquery-ui"
|
73
81
|
end
|
82
|
+
def pagination?
|
83
|
+
File.exists? "config/initializers/kaminari_config.rb"
|
84
|
+
end
|
74
85
|
end
|
75
86
|
end
|
76
87
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
+
<%- if pagination? -%>
|
1
2
|
<%%= paginate @<%= plural_table_name %>, :remote => remote %>
|
3
|
+
<%- end -%>
|
2
4
|
<div class="separator"></div>
|
3
5
|
|
4
6
|
<table class='user' cellspacing='0'>
|
@@ -18,7 +20,7 @@
|
|
18
20
|
<%- attributes.each do |attribute| -%>
|
19
21
|
<%- case attribute.type
|
20
22
|
when :boolean -%>
|
21
|
-
<td><%%= <%= singular_table_name %>.<%= attribute.name %> ? style_image_tag("ico_v.png") : style_image_tag(
|
23
|
+
<td><%%= <%= singular_table_name %>.<%= attribute.name %> ? style_image_tag("ico_v.png", :class => "ico_true") : style_image_tag("ico_x.png", :class => "ico_false") %></td>
|
22
24
|
<%- when :references, :belongs_to -%>
|
23
25
|
<%% link_name = <%= singular_table_name %>.<%= attribute.name %>.try(:name) || <%= singular_table_name %>.<%= attribute.name %>.try(:id) %>
|
24
26
|
<td><%%= link_to(link_name, <%= singular_table_name %>.<%= attribute.name %> ) %></td>
|
@@ -27,24 +29,26 @@
|
|
27
29
|
<%- end -%>
|
28
30
|
<%- end -%>
|
29
31
|
<td><%%= link_to t(:show), <%= singular_table_name %> %></td>
|
30
|
-
|
32
|
+
<%- if authorization? -%>
|
31
33
|
<%% if can? :update, <%= singular_table_name %> -%>
|
32
|
-
|
34
|
+
<%- end -%>
|
33
35
|
<td><%%= link_to t(:edit), edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
|
34
|
-
|
36
|
+
<%- if authorization? -%>
|
35
37
|
<%% end -%>
|
36
|
-
|
37
|
-
|
38
|
+
<%- end -%>
|
39
|
+
<%- if authorization? -%>
|
38
40
|
<%% if can? :destroy, <%= singular_table_name %> -%>
|
39
|
-
|
41
|
+
<%- end -%>
|
40
42
|
<td><%%= link_to t(:destroy), <%= singular_table_name %>, <%= key_value :confirm, "t(:sure?)" %>, <%= key_value :method, ":delete" %>, :remote => remote %></td>
|
41
|
-
|
43
|
+
<%- if authorization? -%>
|
42
44
|
<%% end -%>
|
43
|
-
|
45
|
+
<%- end -%>
|
44
46
|
</tr>
|
45
47
|
<%% end %>
|
46
48
|
</tbody>
|
47
49
|
</table>
|
48
50
|
|
49
51
|
<div class="separator"></div>
|
50
|
-
|
52
|
+
<%- if pagination? -%>
|
53
|
+
<%%= paginate @<%= plural_table_name %>, :remote => remote %>
|
54
|
+
<%- end -%>
|
@@ -1 +1 @@
|
|
1
|
-
$("#tr<%%= @<%= singular_table_name %>.id %>").hide('fast');
|
1
|
+
$("#tr<%%= @<%= singular_table_name %>.id %>").hide('fast').text('');
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<%- case attribute.type
|
11
11
|
when :boolean -%>
|
12
12
|
<td><b><%%= t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %>:</b></td>
|
13
|
-
<td><%%= @<%= singular_table_name %>.<%= attribute.name %> ? style_image_tag("ico_v.png") : style_image_tag(
|
13
|
+
<td><%%= @<%= singular_table_name %>.<%= attribute.name %> ? style_image_tag("ico_v.png", :class => "ico_true") : style_image_tag("ico_x.png", :class => "ico_false") %></td>
|
14
14
|
<%- when :references, :belongs_to -%>
|
15
15
|
<%% link_name = @<%= singular_table_name %>.<%= attribute.name %>.try(:name) || @<%= singular_table_name %>.<%= attribute.name %>.try(:id) %>
|
16
16
|
<td><b><%%= t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %>:</b></td>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Leolay
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
def copy_all_to_local
|
8
|
+
#directory "leolay", "lib/generators/leolay"
|
9
|
+
copy_file "leolay/leolay_generator.rb", "lib/generators/leolay/leolay_generator.rb"
|
10
|
+
copy_file "leolay/USAGE", "lib/generators/leolay/USAGE"
|
11
|
+
directory "leolay/templates", "lib/generators/leolay/templates"
|
12
|
+
#copy_file "leonardo_shared.rb", "lib/generators/leonardo_shared.rb" unless File.exists? "lib/generators/leonardo_shared.rb"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -288,6 +288,53 @@ class LeolayGenerator < Rails::Generators::Base
|
|
288
288
|
end if options.formtastic?
|
289
289
|
end
|
290
290
|
|
291
|
+
def setup_rspec
|
292
|
+
file = "spec/spec_helper.rb"
|
293
|
+
return unless File.exists? file
|
294
|
+
inject_into_file file, :after => "require 'rspec/rails'" do
|
295
|
+
<<-FILE.gsub(/^ /, '')
|
296
|
+
|
297
|
+
require 'capybara/rspec'
|
298
|
+
require 'helpers/application_helpers_spec'
|
299
|
+
|
300
|
+
Capybara.default_wait_time = 5 #default=2
|
301
|
+
FILE
|
302
|
+
end
|
303
|
+
|
304
|
+
gsub_file file, 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', '#config.fixture_path = "#{::Rails.root}/spec/fixtures"'
|
305
|
+
#inject_into_file file, "#", :before => 'config.fixture_path = "#{::Rails.root}/spec/fixtures"'
|
306
|
+
|
307
|
+
gsub_file file, "config.use_transactional_fixtures = true" do
|
308
|
+
<<-FILE.gsub(/^ /, '')
|
309
|
+
config.use_transactional_fixtures = false
|
310
|
+
|
311
|
+
config.before(:suite) do
|
312
|
+
DatabaseCleaner.strategy = :truncation
|
313
|
+
end
|
314
|
+
|
315
|
+
config.before(:each) do
|
316
|
+
DatabaseCleaner.start
|
317
|
+
end
|
318
|
+
|
319
|
+
config.after(:each) do
|
320
|
+
DatabaseCleaner.clean
|
321
|
+
end
|
322
|
+
|
323
|
+
config.include ApplicationHelpers
|
324
|
+
FILE
|
325
|
+
end
|
326
|
+
|
327
|
+
file = "spec/factories.rb"
|
328
|
+
copy_file file, file
|
329
|
+
file = "spec/support/devise.rb"
|
330
|
+
copy_file file, file
|
331
|
+
file = "spec/helpers/application_helpers_spec.rb"
|
332
|
+
copy_file file, file
|
333
|
+
file = "lib/templates/rspec/scaffold"
|
334
|
+
directory file, file
|
335
|
+
|
336
|
+
end
|
337
|
+
|
291
338
|
private
|
292
339
|
def style_name
|
293
340
|
style.underscore
|
@@ -37,6 +37,10 @@ en:
|
|
37
37
|
inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
|
38
38
|
updated: 'You updated your account successfully.'
|
39
39
|
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
40
|
+
reasons:
|
41
|
+
inactive: 'inactive'
|
42
|
+
unconfirmed: 'unconfirmed'
|
43
|
+
locked: 'locked'
|
40
44
|
unlocks:
|
41
45
|
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
|
42
46
|
unlocked: 'Your account was successfully unlocked. You are now signed in.'
|
@@ -35,6 +35,10 @@ it:
|
|
35
35
|
inactive_signed_up: 'Ti sei registrato, ma non sei collegato perchè il tuo account è %{reason}.'
|
36
36
|
updated: "Il tuo account è stato aggiornato."
|
37
37
|
destroyed: "Arrivederci! L'account è stato cancellato. Speriamo di rivederti presto."
|
38
|
+
reasons:
|
39
|
+
inactive: "Inattivo"
|
40
|
+
unconfirmed: "Non confermato"
|
41
|
+
locked: "Bloccato"
|
38
42
|
unlocks:
|
39
43
|
send_instructions: "Riceverai un messaggio email con le istruzioni per sbloccare il tuo account entro qualche minuto."
|
40
44
|
unlocked: "Il tuo account è stato correttamente sbloccato. Ora sei collegato."
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/application_helpers_spec'
|
3
|
+
|
4
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
5
|
+
# It demonstrates how one might use RSpec to specify the controller code that
|
6
|
+
# was generated by Rails when you ran the scaffold generator.
|
7
|
+
#
|
8
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
9
|
+
# generator. If you are using any extension libraries to generate different
|
10
|
+
# controller code, this generated spec may or may not pass.
|
11
|
+
#
|
12
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
13
|
+
# of tools you can use to make these specs even more expressive, but we're
|
14
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
15
|
+
#
|
16
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
17
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
18
|
+
# is no simpler way to get a handle on the object needed for the example.
|
19
|
+
# Message expectations are only used when there is no simpler way to specify
|
20
|
+
# that an instance is receiving a specific message.
|
21
|
+
|
22
|
+
describe <%= controller_class_name %>Controller do
|
23
|
+
include ApplicationHelpers
|
24
|
+
|
25
|
+
<% unless options[:singleton] -%>
|
26
|
+
describe "GET index" do
|
27
|
+
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
28
|
+
login_controller_as(:user)
|
29
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
30
|
+
get :index
|
31
|
+
assigns(:<%= table_name %>).should eq([<%= file_name %>])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
<% end -%>
|
36
|
+
describe "GET show" do
|
37
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
38
|
+
login_controller_as(:user)
|
39
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
40
|
+
get :show, :id => <%= file_name %>.id.to_s
|
41
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "GET new" do
|
46
|
+
it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
|
47
|
+
login_controller_as(:user)
|
48
|
+
get :new
|
49
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "GET edit" do
|
54
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
55
|
+
login_controller_as(:user)
|
56
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
57
|
+
get :edit, :id => <%= file_name %>.id.to_s
|
58
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "POST create" do
|
63
|
+
describe "with valid params" do
|
64
|
+
it "creates a new <%= class_name %>" do
|
65
|
+
login_controller_as(:user)
|
66
|
+
expect {
|
67
|
+
post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
|
68
|
+
}.to change(<%= class_name %>, :count).by(1)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
|
72
|
+
login_controller_as(:user)
|
73
|
+
post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
|
74
|
+
assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
|
75
|
+
assigns(:<%= ns_file_name %>).should be_persisted
|
76
|
+
end
|
77
|
+
|
78
|
+
it "redirects to the created <%= ns_file_name %>" do
|
79
|
+
login_controller_as(:user)
|
80
|
+
post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
|
81
|
+
response.should redirect_to(<%= class_name %>.last)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "with invalid params" do
|
86
|
+
it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
|
87
|
+
login_controller_as(:user)
|
88
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
89
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
90
|
+
post :create, :<%= ns_file_name %> => {}
|
91
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "re-renders the 'new' template" do
|
95
|
+
login_controller_as(:user)
|
96
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
97
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
98
|
+
post :create, :<%= ns_file_name %> => {}
|
99
|
+
response.should render_template("new")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "PUT update" do
|
105
|
+
describe "with valid params" do
|
106
|
+
it "updates the requested <%= ns_file_name %>" do
|
107
|
+
login_controller_as(:user)
|
108
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
109
|
+
# Assuming there are no other <%= table_name %> in the database, this
|
110
|
+
# specifies that the <%= class_name %> created on the previous line
|
111
|
+
# receives the :update_attributes message with whatever params are
|
112
|
+
# submitted in the request.
|
113
|
+
<%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= params %>)
|
114
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => <%= params %>
|
115
|
+
end
|
116
|
+
|
117
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
118
|
+
login_controller_as(:user)
|
119
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
120
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
|
121
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "redirects to the <%= ns_file_name %>" do
|
125
|
+
login_controller_as(:user)
|
126
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
127
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
|
128
|
+
response.should redirect_to(<%= file_name %>)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "with invalid params" do
|
133
|
+
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
134
|
+
login_controller_as(:user)
|
135
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
136
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
137
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
138
|
+
put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
|
139
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "re-renders the 'edit' template" do
|
143
|
+
login_controller_as(:user)
|
144
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
145
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
146
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
147
|
+
put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
|
148
|
+
response.should render_template("edit")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "DELETE destroy" do
|
154
|
+
describe "with authorization" do
|
155
|
+
it "destroys the requested <%= ns_file_name %>" do
|
156
|
+
login_controller_as(:user_manager)
|
157
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
158
|
+
expect {
|
159
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
160
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "redirects to the <%= table_name %> list" do
|
164
|
+
login_controller_as(:user_manager)
|
165
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
166
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
167
|
+
response.should redirect_to(<%= index_helper %>_url)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
describe "without authorization" do
|
171
|
+
it "destroys the requested <%= ns_file_name %>" do
|
172
|
+
login_controller_as(:user)
|
173
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
174
|
+
expect {
|
175
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
176
|
+
}.to change(<%= class_name %>, :count).by(0)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
+
describe "<%= ns_table_name %>/edit.html.<%= options[:template_engine] %>" do
|
5
|
+
before(:each) do
|
6
|
+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, Factory(:<%= ns_file_name %>) )
|
7
|
+
end
|
8
|
+
|
9
|
+
it "renders the edit <%= ns_file_name %> form" do
|
10
|
+
render
|
11
|
+
|
12
|
+
rendered.should have_selector("form", :action => <%= index_helper %>_path(@<%= ns_file_name %>), :method => "post") do |form|
|
13
|
+
<% for attribute in output_attributes -%>
|
14
|
+
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
15
|
+
<% end -%>
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
<%
|
4
|
+
def value_for_check(attribute)
|
5
|
+
name = ":text"
|
6
|
+
([] <<
|
7
|
+
case attribute.type
|
8
|
+
when :boolean
|
9
|
+
"\"tr#tr\#{r.id}>td>img.\#{r.#{attribute.name} ? \"ico_true\" : \"ico_false\"}\""
|
10
|
+
else
|
11
|
+
"\"tr#tr\#{r.id}>td\""
|
12
|
+
end <<
|
13
|
+
case attribute.type
|
14
|
+
when :references, :belongs_to
|
15
|
+
"#{name} => (r.#{attribute.name}.try(:name) || r.#{attribute.name}.try(:id))"
|
16
|
+
when :boolean
|
17
|
+
nil
|
18
|
+
else
|
19
|
+
"#{name} => r.#{attribute.name}"
|
20
|
+
end <<
|
21
|
+
":count => 1"
|
22
|
+
).compact.join(', ')
|
23
|
+
end
|
24
|
+
%>
|
25
|
+
|
26
|
+
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
27
|
+
describe "<%= ns_table_name %>/index.html.<%= options[:template_engine] %>" do
|
28
|
+
before(:each) do
|
29
|
+
@records = assign(:<%= table_name %>, FactoryGirl.create_list(:<%= ns_file_name %>, 2) )
|
30
|
+
assign(:<%= ns_file_name %>, Factory(:<%= ns_file_name %>) )
|
31
|
+
end
|
32
|
+
|
33
|
+
it "renders a list of <%= ns_table_name %>" do
|
34
|
+
render
|
35
|
+
@records.each do |r|
|
36
|
+
<% for attribute in output_attributes -%>
|
37
|
+
assert_select <%= value_for_check(attribute) %>
|
38
|
+
<% end -%>
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
+
describe "<%= ns_table_name %>/new.html.<%= options[:template_engine] %>" do
|
5
|
+
before(:each) do
|
6
|
+
assign(:<%= ns_file_name %>, Factory.build(:<%= ns_file_name %>) )
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
it "renders new <%= ns_file_name %> form" do
|
11
|
+
render
|
12
|
+
|
13
|
+
rendered.should have_selector("form", :action => <%= index_helper %>_path, :method => "post") do |form|
|
14
|
+
<% for attribute in output_attributes -%>
|
15
|
+
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
16
|
+
<% end -%>
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
<%
|
4
|
+
def value_for_check(attribute)
|
5
|
+
case attribute.type
|
6
|
+
when :references, :belongs_to
|
7
|
+
"have_content(@#{ns_file_name}.#{attribute.name}.try(:name) || @#{ns_file_name}.#{attribute.name}.try(:id))"
|
8
|
+
when :boolean
|
9
|
+
"have_css(\"img.\#{@#{ns_file_name}.#{attribute.name} ? \"ico_true\" : \"ico_false\"}\")"
|
10
|
+
else
|
11
|
+
"have_content(@#{ns_file_name}.#{attribute.name})"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
%>
|
15
|
+
|
16
|
+
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
17
|
+
describe "<%= ns_table_name %>/show.html.<%= options[:template_engine] %>" do
|
18
|
+
before(:each) do
|
19
|
+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, Factory(:<%= ns_file_name %>) )
|
20
|
+
end
|
21
|
+
|
22
|
+
it "renders attributes" do
|
23
|
+
render
|
24
|
+
<% for attribute in output_attributes -%>
|
25
|
+
rendered.should <%= value_for_check(attribute) %>
|
26
|
+
<% end -%>
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :user do
|
3
|
+
email 'test@leonardo.com'
|
4
|
+
password 'abcd1234'
|
5
|
+
roles ['user']
|
6
|
+
|
7
|
+
trait :guest do
|
8
|
+
roles ['guest']
|
9
|
+
end
|
10
|
+
trait :manager do
|
11
|
+
roles ['manager']
|
12
|
+
end
|
13
|
+
trait :admin do
|
14
|
+
roles ['admin']
|
15
|
+
end
|
16
|
+
|
17
|
+
factory :user_guest, :traits => [:guest]
|
18
|
+
factory :user_manager, :traits => [:manager]
|
19
|
+
factory :user_admin, :traits => [:admin]
|
20
|
+
end
|
21
|
+
### Leonardo creates here below your factories ###
|
22
|
+
### Insert below here other your factories ###
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ApplicationHelpers
|
2
|
+
def login_view_as(role=:user)
|
3
|
+
user = Factory(role)
|
4
|
+
fill_in 'user_email', :with => user.email
|
5
|
+
fill_in 'user_password', :with => user.password
|
6
|
+
click_button 'Sign in'
|
7
|
+
end
|
8
|
+
def login_controller_as(role=:user)
|
9
|
+
user = Factory(role)
|
10
|
+
#user.confirm! # or set a confirmed_at inside the factory. Only necessary if you are using the confirmable module
|
11
|
+
sign_in user
|
12
|
+
end
|
13
|
+
end
|
@@ -8,6 +8,7 @@ module Leosca
|
|
8
8
|
directory "erb/leosca", "lib/generators/erb/leosca" if options.erb?
|
9
9
|
directory "rails/leosca", "lib/generators/rails/leosca"
|
10
10
|
directory "rails/leosca_controller", "lib/generators/rails/leosca_controller"
|
11
|
+
#copy_file "leonardo_shared.rb", "lib/generators/leonardo_shared.rb"
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rails/generators/resource_helpers'
|
2
|
+
#require '../../leonardo_shared' #I'd like to share common code but it can't find that module :(
|
2
3
|
|
3
4
|
WINDOWS = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
|
4
5
|
CRLF = WINDOWS ? "\r\n" : "\n"
|
@@ -7,6 +8,7 @@ module Rails
|
|
7
8
|
module Generators
|
8
9
|
class LeoscaControllerGenerator < NamedBase
|
9
10
|
include ResourceHelpers
|
11
|
+
#include LeonardoShared
|
10
12
|
#puts 'rails:leosca_controller'
|
11
13
|
|
12
14
|
source_root File.expand_path('../templates', __FILE__)
|
@@ -66,17 +68,18 @@ module Rails
|
|
66
68
|
inject_into_file file, :after => " hints:#{CRLF}" do
|
67
69
|
content = " #{file_name}:#{CRLF}"
|
68
70
|
attributes.each do |attribute|
|
71
|
+
attr_name = attribute.name.gsub '_', ''
|
69
72
|
case attribute.type
|
70
73
|
when :integer, :decimal, :float
|
71
|
-
content << " #{attribute.name}: \"Fill the #{
|
74
|
+
content << " #{attribute.name}: \"Fill the #{attr_name} with a#{"n" if attribute.type == :integer} #{attribute.type.to_s} number\"#{CRLF}"
|
72
75
|
when :boolean
|
73
|
-
content << " #{attribute.name}: \"Select if #{
|
76
|
+
content << " #{attribute.name}: \"Select if this #{file_name} should be #{attr_name} or not\"#{CRLF}"
|
74
77
|
when :string, :text
|
75
|
-
content << " #{attribute.name}: \"Choose a good #{
|
78
|
+
content << " #{attribute.name}: \"Choose a good #{attr_name} for this #{file_name}\"#{CRLF}"
|
76
79
|
when :date, :datetime, :time
|
77
|
-
content << " #{attribute.name}: \"Choose a #{attribute.type.to_s} for #{
|
80
|
+
content << " #{attribute.name}: \"Choose a #{attribute.type.to_s} for #{attr_name}\"#{CRLF}"
|
78
81
|
else
|
79
|
-
content << " #{attribute.name}: \"Choose a #{
|
82
|
+
content << " #{attribute.name}: \"Choose a #{attr_name}\"#{CRLF}"
|
80
83
|
end
|
81
84
|
end
|
82
85
|
content
|
@@ -125,21 +128,7 @@ module Rails
|
|
125
128
|
append_file file do
|
126
129
|
items = []
|
127
130
|
attributes.each do |attribute|
|
128
|
-
|
129
|
-
when :boolean then :true
|
130
|
-
when :integer then "#"
|
131
|
-
when :float, :decimal then "#.46"
|
132
|
-
when :references, :belongs_to then "#"
|
133
|
-
when :date then "'#{Time.now.strftime("%Y-%m-%d 00:00:00.000")}'"
|
134
|
-
when :datetime then "'#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}'"
|
135
|
-
when :time then "'#{Time.now.strftime("%H:%M:%S.000")}'"
|
136
|
-
else "'#{attribute.name.capitalize}\#'"
|
137
|
-
end
|
138
|
-
name = case attribute.type
|
139
|
-
when :references, :belongs_to then ":#{attribute.name}_id"
|
140
|
-
else ":#{attribute.name}"
|
141
|
-
end
|
142
|
-
items << " #{name} => #{value}"
|
131
|
+
items << attribute_to_hash(attribute)
|
143
132
|
end
|
144
133
|
row = "{ #{items.join(', ')} }"
|
145
134
|
|
@@ -153,6 +142,85 @@ module Rails
|
|
153
142
|
end if File.exists?(file)
|
154
143
|
end
|
155
144
|
|
145
|
+
def update_specs
|
146
|
+
file = "spec/spec_helper.rb"
|
147
|
+
return unless File.exists? file
|
148
|
+
|
149
|
+
check_attr_to_have, check_attr_to_not_have = get_attr_to_match
|
150
|
+
|
151
|
+
file = "spec/requests/#{plural_table_name}_spec.rb"
|
152
|
+
remove = <<-FILE.gsub(/^ /, '')
|
153
|
+
it "works! (now write some real specs)" do
|
154
|
+
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
155
|
+
get #{plural_table_name}_path
|
156
|
+
response.status.should be(200)
|
157
|
+
end
|
158
|
+
FILE
|
159
|
+
gsub_file file, remove, ""
|
160
|
+
|
161
|
+
inject_into_file file, :after => "describe \"GET /#{plural_table_name}\" do" do
|
162
|
+
<<-FILE.gsub(/^ /, '')
|
163
|
+
|
164
|
+
it "displays #{plural_table_name}" do
|
165
|
+
#{singular_table_name} = Factory(:#{singular_table_name})
|
166
|
+
visit #{plural_table_name}_path
|
167
|
+
login_view_as(:user_guest)
|
168
|
+
#save_and_open_page #uncomment to debug
|
169
|
+
page.should #{check_attr_to_have}
|
170
|
+
assert page.find("#tr\#{#{singular_table_name}.id}").visible?
|
171
|
+
end
|
172
|
+
it "checks ajax", :js => true do
|
173
|
+
#{singular_table_name} = Factory(:#{singular_table_name})
|
174
|
+
visit #{plural_table_name}_path
|
175
|
+
login_view_as(:user_manager)
|
176
|
+
page.should #{check_attr_to_have}
|
177
|
+
click_link "Destroy"
|
178
|
+
page.driver.browser.switch_to.alert.accept
|
179
|
+
#save_and_open_page #uncomment to debug
|
180
|
+
page.should #{check_attr_to_not_have}
|
181
|
+
assert !find("#tr\#{#{singular_table_name}.id}").visible?
|
182
|
+
end
|
183
|
+
FILE
|
184
|
+
end
|
185
|
+
|
186
|
+
inject_into_file file, :before => /^end/ do
|
187
|
+
items = []
|
188
|
+
attributes.each do |attribute|
|
189
|
+
items << attribute_to_requests(attribute)
|
190
|
+
end
|
191
|
+
<<-FILE.gsub(/^ /, '')
|
192
|
+
|
193
|
+
describe "POST /#{plural_table_name}" do
|
194
|
+
it "creates a new #{singular_table_name}" do
|
195
|
+
#{singular_table_name} = Factory.build(:#{singular_table_name})
|
196
|
+
visit new_#{singular_table_name}_path
|
197
|
+
login_view_as(:user)
|
198
|
+
#{items.join(CRLF)}
|
199
|
+
click_button "Create \#{I18n.t('models.#{singular_table_name}')}"
|
200
|
+
#save_and_open_page #uncomment to debug
|
201
|
+
page.should have_content(I18n.t(:created, :model => I18n.t('models.#{singular_table_name}')))
|
202
|
+
page.should #{check_attr_to_have}
|
203
|
+
end
|
204
|
+
end
|
205
|
+
FILE
|
206
|
+
end
|
207
|
+
|
208
|
+
file = "spec/factories.rb"
|
209
|
+
inject_into_file file, :after => "### Leonardo creates here below your factories ###" do
|
210
|
+
items = []
|
211
|
+
attributes.each do |attribute|
|
212
|
+
items << attribute_to_factories(attribute)
|
213
|
+
end
|
214
|
+
<<-FILE.gsub(/^ /, '')
|
215
|
+
|
216
|
+
factory :#{singular_table_name} do |#{singular_table_name[0..0]}|
|
217
|
+
#{items.join(CRLF)}
|
218
|
+
end
|
219
|
+
FILE
|
220
|
+
end if File.exists?(file)
|
221
|
+
|
222
|
+
end
|
223
|
+
|
156
224
|
protected
|
157
225
|
def authorization?
|
158
226
|
File.exists? "app/models/ability.rb"
|
@@ -165,6 +233,70 @@ module Rails
|
|
165
233
|
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
166
234
|
str.split('_').map { |i| i.capitalize }.join
|
167
235
|
end
|
236
|
+
def formtastic?
|
237
|
+
return false unless options.formtastic?
|
238
|
+
File.exists? "config/initializers/formtastic.rb"
|
239
|
+
end
|
240
|
+
def jquery_ui?
|
241
|
+
File.exists? "vendor/assets/javascripts/jquery-ui"
|
242
|
+
end
|
243
|
+
def pagination?
|
244
|
+
File.exists? "config/initializers/kaminari_config.rb"
|
245
|
+
end
|
246
|
+
def attribute_to_hash(attribute)
|
247
|
+
name = case attribute.type
|
248
|
+
when :references, :belongs_to then ":#{attribute.name}_id"
|
249
|
+
else ":#{attribute.name}"
|
250
|
+
end
|
251
|
+
value = case attribute.type
|
252
|
+
when :boolean then "true"
|
253
|
+
when :integer then "#"
|
254
|
+
when :float, :decimal then "#.46"
|
255
|
+
when :references, :belongs_to then "#"
|
256
|
+
when :date then "#{Time.now.strftime("%Y-%m-%d 00:00:00.000")}".inspect
|
257
|
+
when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
|
258
|
+
when :time then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
|
259
|
+
else "#{attribute.name.titleize}\#".inspect
|
260
|
+
end
|
261
|
+
" #{name} => #{value}"
|
262
|
+
end
|
263
|
+
def attribute_to_factories(attribute)
|
264
|
+
name = case attribute.type
|
265
|
+
when :references, :belongs_to then "#{singular_table_name[0..0]}.association "
|
266
|
+
when :boolean, :datetime, :time then "#{singular_table_name[0..0]}.#{attribute.name} "
|
267
|
+
else "#{singular_table_name[0..0]}.sequence(:#{attribute.name}) "
|
268
|
+
end
|
269
|
+
value = case attribute.type
|
270
|
+
when :boolean then "true"
|
271
|
+
when :integer then "{|n| n }"
|
272
|
+
when :float, :decimal then "{|n| n }"
|
273
|
+
when :references, :belongs_to then ":#{attribute.name}"
|
274
|
+
when :date then "{|n| n.month.ago }"
|
275
|
+
when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
|
276
|
+
when :time then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
|
277
|
+
else "{|n| \"#{attribute.name.titleize}\#{n}\" }"
|
278
|
+
end
|
279
|
+
" #{name} #{value}"
|
280
|
+
end
|
281
|
+
def attribute_to_requests(attribute)
|
282
|
+
case attribute.type
|
283
|
+
when :boolean then " check '#{singular_table_name}_#{attribute.name}' if #{singular_table_name}.#{attribute.name}"
|
284
|
+
when :references, :belongs_to then " select #{singular_table_name}.#{attribute.name}.name, :from => '#{singular_table_name}_#{attribute.name}_id'"
|
285
|
+
when :datetime, :time then ""
|
286
|
+
when :date then " fill_in '#{singular_table_name}_#{attribute.name}', :with => #{singular_table_name}.#{attribute.name}.strftime('%d/%m/%Y')"
|
287
|
+
else " fill_in '#{singular_table_name}_#{attribute.name}', :with => #{singular_table_name}.#{attribute.name}"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
def get_attr_to_match
|
291
|
+
attributes.each do |attribute|
|
292
|
+
return "have_content(#{singular_table_name}.#{attribute.name})",
|
293
|
+
"have_no_content(#{singular_table_name}.#{attribute.name})" if attribute.type==:string
|
294
|
+
end
|
295
|
+
#If there are not string attributes
|
296
|
+
return "have_xpath('//table/tbody/tr')",
|
297
|
+
"have_no_xpath('//table/tbody/tr')"
|
298
|
+
end
|
299
|
+
|
168
300
|
end
|
169
301
|
end
|
170
302
|
end
|
@@ -37,7 +37,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
37
37
|
|
38
38
|
@<%= plural_table_name %> = case request.format
|
39
39
|
when 'text/html', 'text/javascript'
|
40
|
-
<%= class_name %>.where(conditions).order(:id).page(params[:page])
|
40
|
+
<%= class_name %>.where(conditions).order(:id)<%= ".page(params[:page])" if pagination? %>
|
41
41
|
else
|
42
42
|
<%= class_name %>.where(conditions)
|
43
43
|
end
|
data/template.rb
CHANGED
@@ -1,107 +1,119 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
gem '
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
gem '
|
45
|
-
gem '
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
gem '
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
if
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
1
|
+
#########################################################
|
2
|
+
# 2011 Marco Mastrodonato(c)
|
3
|
+
# This is a Rails 3.1 template to use with leonardo gem
|
4
|
+
# https://rubygems.org/gems/leonardo
|
5
|
+
#
|
6
|
+
# USAGE: rails new yourappname -m template.rb
|
7
|
+
#
|
8
|
+
# -------------------------------------------------------
|
9
|
+
# 25-08-2011: Added rspec generation
|
10
|
+
#########################################################
|
11
|
+
|
12
|
+
puts '*' * 40
|
13
|
+
puts "* Processing template..."
|
14
|
+
puts '*' * 40
|
15
|
+
|
16
|
+
use_git = yes?("Do you think to use git ?")
|
17
|
+
if use_git
|
18
|
+
git :init
|
19
|
+
file ".gitignore", <<-EOS.gsub(/^ /, '')
|
20
|
+
.DS_Store
|
21
|
+
log/*.log
|
22
|
+
tmp/**/*
|
23
|
+
config/database.yml
|
24
|
+
db/*.sqlite3
|
25
|
+
nbproject/*
|
26
|
+
.idea
|
27
|
+
EOS
|
28
|
+
end
|
29
|
+
|
30
|
+
gem 'kaminari' if yes?("Pagination ?")
|
31
|
+
|
32
|
+
gem 'paperclip' if yes?("Attachment ?")
|
33
|
+
|
34
|
+
gem 'fastercsv' if yes?("FasterCSV ?")
|
35
|
+
|
36
|
+
gem 'state_machine' if yes?("Do you have to handle states ?")
|
37
|
+
|
38
|
+
formtastic = yes?("Formtastic ?")
|
39
|
+
if formtastic
|
40
|
+
#gem 'justinfrench-formtastic', :lib => 'formtastic', :source => 'http://gems.github.com'
|
41
|
+
#rake "gems:install" if install_gem
|
42
|
+
|
43
|
+
#A Rails FormBuilder DSL (with some other goodies) to make it far easier to create beautiful, semantically rich, syntactically awesome, readily stylable and wonderfully accessible HTML forms in your Rails applications.
|
44
|
+
gem 'formtastic'
|
45
|
+
gem 'validation_reflection'
|
46
|
+
end
|
47
|
+
|
48
|
+
rspec = yes?("Add rspec as testing framework ?")
|
49
|
+
if rspec
|
50
|
+
gem 'rspec-rails', :group => [:test, :development]
|
51
|
+
gem 'capybara', :group => :test
|
52
|
+
gem 'launchy', :group => :test
|
53
|
+
gem 'database_cleaner', :group => :test
|
54
|
+
gem 'factory_girl_rails', :group => :test
|
55
|
+
end
|
56
|
+
|
57
|
+
model_name = nil
|
58
|
+
devise = yes?("Would you like to install Devise?")
|
59
|
+
if devise
|
60
|
+
gem 'devise'
|
61
|
+
model_name = ask(" What would you like the user model to be called? [user]")
|
62
|
+
model_name = "user" if model_name.blank?
|
63
|
+
end
|
64
|
+
|
65
|
+
cancan = yes?("Authorization ?")
|
66
|
+
gem 'cancan' if cancan
|
67
|
+
|
68
|
+
#home = yes?("Generate controller home ? (raccomanded)")
|
69
|
+
home = true
|
70
|
+
|
71
|
+
leolay = yes?("Layout ?")
|
72
|
+
leolay_main_color = leolay_second_color = ""
|
73
|
+
if leolay
|
74
|
+
gem 'leonardo'
|
75
|
+
puts " Enter colors, for example:"
|
76
|
+
puts " #c8c8c8 or rgb(200,200,200) or gray"
|
77
|
+
leolay_main_color = ask(" Choose main color [blank=default color]:")
|
78
|
+
leolay_second_color = ask(" Choose secondary color [blank=default color]:")
|
79
|
+
end
|
80
|
+
|
81
|
+
run "bundle install"
|
82
|
+
|
83
|
+
generate "rspec:install" if rspec
|
84
|
+
|
85
|
+
generate "formtastic:install" if formtastic
|
86
|
+
|
87
|
+
if devise
|
88
|
+
generate("devise:install")
|
89
|
+
generate("devise", model_name)
|
90
|
+
#generate("devise:views") #not use since leolay copies custom views
|
91
|
+
end
|
92
|
+
|
93
|
+
generate "cancan:ability" if cancan
|
94
|
+
|
95
|
+
if leolay
|
96
|
+
generate "leolay",
|
97
|
+
"cloudy",
|
98
|
+
("--main_color=#{leolay_main_color}" if leolay_main_color.any?),
|
99
|
+
("--second_color=#{leolay_second_color}" if leolay_second_color.any?),
|
100
|
+
(cancan ? "" : "--skip-authorization"),
|
101
|
+
(devise ? "" : "--skip-authentication"),
|
102
|
+
(formtastic ? "" : "--skip-formtastic")
|
103
|
+
end
|
104
|
+
|
105
|
+
if home
|
106
|
+
generate "controller", "home", "index"
|
107
|
+
route "root :to => 'home#index'"
|
108
|
+
end
|
109
|
+
|
110
|
+
File.unlink "public/index.html"
|
111
|
+
|
112
|
+
rake "db:create:all"
|
113
|
+
rake "db:migrate"
|
114
|
+
|
115
|
+
#rake "gems:unpack" if yes?("Unpack to vendor/gems ?")
|
116
|
+
|
117
|
+
git :add => ".", :commit => "-m 'initial commit'" if use_git
|
118
|
+
|
119
|
+
puts "ENJOY!"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leonardo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marco Mastrodonato
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-30 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: A generator for creating Rails 3.1 applications ready to go. It generates the layout, the style, the internationalization and manage external gems for authentication, authorization and other. It also provides a customized scaffold to generates cool sites ajax ready in few minutes. If you find a bug please report to m.mastrodonato@gmail.com
|
@@ -27,6 +27,7 @@ extensions: []
|
|
27
27
|
extra_rdoc_files: []
|
28
28
|
|
29
29
|
files:
|
30
|
+
- lib/generators/base.rb
|
30
31
|
- lib/generators/erb/leosca/leosca_generator.rb
|
31
32
|
- lib/generators/erb/leosca/templates/destroy.js.erb
|
32
33
|
- lib/generators/erb/leosca/templates/edit.html.erb
|
@@ -37,6 +38,7 @@ files:
|
|
37
38
|
- lib/generators/erb/leosca/templates/show.html.erb
|
38
39
|
- lib/generators/erb/leosca/templates/_form.html.erb
|
39
40
|
- lib/generators/erb/leosca/templates/_list.erb
|
41
|
+
- lib/generators/leolay/install_generator.rb
|
40
42
|
- lib/generators/leolay/leolay_generator.rb
|
41
43
|
- lib/generators/leolay/templates/app/assets/javascripts/custom.js
|
42
44
|
- lib/generators/leolay/templates/app/views/devise/confirmations/new.html.erb
|
@@ -58,7 +60,15 @@ files:
|
|
58
60
|
- lib/generators/leolay/templates/config/locales/kaminari.it.yml
|
59
61
|
- lib/generators/leolay/templates/config.rb
|
60
62
|
- lib/generators/leolay/templates/layout_helper.rb
|
63
|
+
- lib/generators/leolay/templates/lib/templates/rspec/scaffold/controller_spec.rb
|
64
|
+
- lib/generators/leolay/templates/lib/templates/rspec/scaffold/edit_spec.rb
|
65
|
+
- lib/generators/leolay/templates/lib/templates/rspec/scaffold/index_spec.rb
|
66
|
+
- lib/generators/leolay/templates/lib/templates/rspec/scaffold/new_spec.rb
|
67
|
+
- lib/generators/leolay/templates/lib/templates/rspec/scaffold/show_spec.rb
|
61
68
|
- lib/generators/leolay/templates/lib/utility.rb
|
69
|
+
- lib/generators/leolay/templates/spec/factories.rb
|
70
|
+
- lib/generators/leolay/templates/spec/helpers/application_helpers_spec.rb
|
71
|
+
- lib/generators/leolay/templates/spec/support/devise.rb
|
62
72
|
- lib/generators/leolay/templates/styles/cloudy/images/jquery-ui/Thumbs.db
|
63
73
|
- lib/generators/leolay/templates/styles/cloudy/images/jquery-ui/ui-bg_diagonals-thick_18_b81900_40x40.png
|
64
74
|
- lib/generators/leolay/templates/styles/cloudy/images/jquery-ui/ui-bg_diagonals-thick_20_666666_40x40.png
|
@@ -146,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
156
|
requirements: []
|
147
157
|
|
148
158
|
rubyforge_project:
|
149
|
-
rubygems_version: 1.8.
|
159
|
+
rubygems_version: 1.8.9
|
150
160
|
signing_key:
|
151
161
|
specification_version: 3
|
152
162
|
summary: A layout and customized scaffold generator for Rails 3.1
|