leonardo 1.5.0 → 1.6.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 +9 -3
- data/lib/generators/base.rb +262 -24
- data/lib/generators/erb/leosca/leosca_generator.rb +38 -22
- data/lib/generators/erb/leosca/templates/_form.html.erb +14 -3
- data/lib/generators/erb/leosca/templates/_list.erb +13 -20
- data/lib/generators/erb/leosca/templates/_show.erb +9 -0
- data/lib/generators/erb/leosca/templates/edit.html.erb +3 -5
- data/lib/generators/erb/leosca/templates/formtastic/_form.html.erb +10 -4
- data/lib/generators/erb/leosca/templates/index.html.erb +15 -4
- data/lib/generators/erb/leosca/templates/new.html.erb +1 -1
- data/lib/generators/erb/leosca/templates/show.html.erb +5 -22
- data/lib/generators/erb/leosca/templates/show.js.erb +7 -0
- data/lib/generators/leolay/USAGE +1 -1
- data/lib/generators/leolay/install_generator.rb +0 -1
- data/lib/generators/leolay/leolay_generator.rb +24 -17
- data/lib/generators/leolay/templates/config/locales/devise.en.yml +1 -0
- data/lib/generators/leolay/templates/config/locales/devise.it.yml +1 -0
- data/lib/generators/leolay/templates/config/locales/en.yml +5 -5
- data/lib/generators/leolay/templates/config/locales/it.yml +5 -5
- data/lib/generators/leolay/templates/lib/generators/rspec/scaffold/scaffold_generator.rb +173 -0
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/controller_spec.rb +39 -39
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/edit_spec.rb +4 -1
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/index_spec.rb +15 -4
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/new_spec.rb +5 -2
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/routing_spec.rb +37 -0
- data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/show_spec.rb +3 -0
- data/lib/generators/leolay/templates/styles/cloudy/{stylesheet.sass → stylesheets/app/stylesheet.sass} +0 -0
- data/lib/generators/leolay/templates/{vendor/assets/stylesheets → styles/cloudy/stylesheets/vendor}/jquery-ui/jquery-ui-1.8.16.redcarpet.css +17 -17
- data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-de.js +1 -1
- data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-en.js +1 -1
- data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-it.js +1 -1
- data/lib/generators/leosca/install_generator.rb +1 -1
- data/lib/generators/rails/leosca/leosca_generator.rb +21 -0
- data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +41 -114
- data/lib/generators/rails/leosca_controller/templates/controller.rb +51 -23
- data/template.rb +4 -1
- metadata +10 -6
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe <%= controller_class_name %>Controller do
|
4
|
+
describe "routing" do
|
5
|
+
|
6
|
+
<% unless options[:singleton] -%>
|
7
|
+
it "routes to #index" do
|
8
|
+
get("/<%= plural_parent_resources.join('/1/') %><%= "/1/" if nested? %><%= ns_table_name %>").should route_to("<%= ns_table_name %>#index"<%= nested_params_http_request("1") %>)
|
9
|
+
end
|
10
|
+
|
11
|
+
<% end -%>
|
12
|
+
it "routes to #new" do
|
13
|
+
get("/<%= plural_parent_resources.join('/1/') %><%= "/1/" if nested? %><%= ns_table_name %>/new").should route_to("<%= ns_table_name %>#new"<%= nested_params_http_request("1") %>)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "routes to #show" do
|
17
|
+
get("/<%= plural_parent_resources.join('/1/') %><%= "/1/" if nested? %><%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#show", :id => "1"<%= nested_params_http_request("1") %>)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "routes to #edit" do
|
21
|
+
get("/<%= plural_parent_resources.join('/1/') %><%= "/1/" if nested? %><%= ns_table_name %>/1/edit").should route_to("<%= ns_table_name %>#edit", :id => "1"<%= nested_params_http_request("1") %>)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "routes to #create" do
|
25
|
+
post("/<%= plural_parent_resources.join('/1/') %><%= "/1/" if nested? %><%= ns_table_name %>").should route_to("<%= ns_table_name %>#create"<%= nested_params_http_request("1") %>)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "routes to #update" do
|
29
|
+
put("/<%= plural_parent_resources.join('/1/') %><%= "/1/" if nested? %><%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#update", :id => "1"<%= nested_params_http_request("1") %>)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "routes to #destroy" do
|
33
|
+
delete("/<%= plural_parent_resources.join('/1/') %><%= "/1/" if nested? %><%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#destroy", :id => "1"<%= nested_params_http_request("1") %>)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -17,6 +17,9 @@ end
|
|
17
17
|
describe "<%= ns_table_name %>/show.html.<%= options[:template_engine] %>" do
|
18
18
|
before(:each) do
|
19
19
|
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, Factory(:<%= ns_file_name %>) )
|
20
|
+
<%- base_parent_resources.each do |parent| -%>
|
21
|
+
@<%= parent %> = assign(:<%= parent %>, @<%= ns_file_name %>.<%= parent %>)
|
22
|
+
<%- end -%>
|
20
23
|
end
|
21
24
|
|
22
25
|
it "renders attributes" do
|
File without changes
|
@@ -59,26 +59,26 @@
|
|
59
59
|
.ui-widget { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1.1em; }
|
60
60
|
.ui-widget .ui-widget { font-size: 1em; }
|
61
61
|
.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1em; }
|
62
|
-
.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(styles/cloudy/jquery-ui/ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; }
|
62
|
+
.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(../styles/cloudy/jquery-ui/ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; }
|
63
63
|
.ui-widget-content a { color: #333333; }
|
64
|
-
.ui-widget-header { border: 1px solid #990000; background: #cc0000 url(styles/cloudy/jquery-ui/ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; }
|
64
|
+
.ui-widget-header { border: 1px solid #990000; background: #cc0000 url(../styles/cloudy/jquery-ui/ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; }
|
65
65
|
.ui-widget-header a { color: #ffffff; }
|
66
66
|
|
67
67
|
/* Interaction states
|
68
68
|
----------------------------------*/
|
69
|
-
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(styles/cloudy/jquery-ui/ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; }
|
69
|
+
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(../styles/cloudy/jquery-ui/ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; }
|
70
70
|
.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; }
|
71
|
-
.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #ff0000; background: #fdf5ce url(styles/cloudy/jquery-ui/ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #990000; }
|
71
|
+
.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #ff0000; background: #fdf5ce url(../styles/cloudy/jquery-ui/ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #990000; }
|
72
72
|
.ui-state-hover a, .ui-state-hover a:hover { color: #990000; text-decoration: none; }
|
73
|
-
.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #ff0000; background: #ffffff url(styles/cloudy/jquery-ui/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #990000; }
|
73
|
+
.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #ff0000; background: #ffffff url(../styles/cloudy/jquery-ui/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #990000; }
|
74
74
|
.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #990000; text-decoration: none; }
|
75
75
|
.ui-widget :active { outline: none; }
|
76
76
|
|
77
77
|
/* Interaction Cues
|
78
78
|
----------------------------------*/
|
79
|
-
.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #ff0000; background: #ff0000 url(styles/cloudy/jquery-ui/ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; }
|
79
|
+
.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #ff0000; background: #ff0000 url(../styles/cloudy/jquery-ui/ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; }
|
80
80
|
.ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; }
|
81
|
-
.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(styles/cloudy/jquery-ui/ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; }
|
81
|
+
.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(../styles/cloudy/jquery-ui/ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; }
|
82
82
|
.ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; }
|
83
83
|
.ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; }
|
84
84
|
.ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; }
|
@@ -89,14 +89,14 @@
|
|
89
89
|
----------------------------------*/
|
90
90
|
|
91
91
|
/* states and images */
|
92
|
-
.ui-icon { width: 16px; height: 16px; background-image: url(styles/cloudy/jquery-ui/ui-icons_222222_256x240.png); }
|
93
|
-
.ui-widget-content .ui-icon {background-image: url(styles/cloudy/jquery-ui/ui-icons_222222_256x240.png); }
|
94
|
-
.ui-widget-header .ui-icon {background-image: url(styles/cloudy/jquery-ui/ui-icons_ffffff_256x240.png); }
|
95
|
-
.ui-state-default .ui-icon { background-image: url(styles/cloudy/jquery-ui/ui-icons_ef8c08_256x240.png); }
|
96
|
-
.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(styles/cloudy/jquery-ui/ui-icons_ef8c08_256x240.png); }
|
97
|
-
.ui-state-active .ui-icon {background-image: url(styles/cloudy/jquery-ui/ui-icons_ef8c08_256x240.png); }
|
98
|
-
.ui-state-highlight .ui-icon {background-image: url(styles/cloudy/jquery-ui/ui-icons_228ef1_256x240.png); }
|
99
|
-
.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(styles/cloudy/jquery-ui/ui-icons_ffd27a_256x240.png); }
|
92
|
+
.ui-icon { width: 16px; height: 16px; background-image: url(../styles/cloudy/jquery-ui/ui-icons_222222_256x240.png); }
|
93
|
+
.ui-widget-content .ui-icon {background-image: url(../styles/cloudy/jquery-ui/ui-icons_222222_256x240.png); }
|
94
|
+
.ui-widget-header .ui-icon {background-image: url(../styles/cloudy/jquery-ui/ui-icons_ffffff_256x240.png); }
|
95
|
+
.ui-state-default .ui-icon { background-image: url(../styles/cloudy/jquery-ui/ui-icons_ef8c08_256x240.png); }
|
96
|
+
.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(../styles/cloudy/jquery-ui/ui-icons_ef8c08_256x240.png); }
|
97
|
+
.ui-state-active .ui-icon {background-image: url(../styles/cloudy/jquery-ui/ui-icons_ef8c08_256x240.png); }
|
98
|
+
.ui-state-highlight .ui-icon {background-image: url(../styles/cloudy/jquery-ui/ui-icons_228ef1_256x240.png); }
|
99
|
+
.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(../styles/cloudy/jquery-ui/ui-icons_ffd27a_256x240.png); }
|
100
100
|
|
101
101
|
/* positioning */
|
102
102
|
.ui-icon-carat-1-n { background-position: 0 0; }
|
@@ -286,8 +286,8 @@
|
|
286
286
|
.ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; -khtml-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; }
|
287
287
|
|
288
288
|
/* Overlays */
|
289
|
-
.ui-widget-overlay { background: #666666 url(styles/cloudy/jquery-ui/ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); }
|
290
|
-
.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(styles/cloudy/jquery-ui/ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }/*
|
289
|
+
.ui-widget-overlay { background: #666666 url(../styles/cloudy/jquery-ui/ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); }
|
290
|
+
.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(../styles/cloudy/jquery-ui/ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }/*
|
291
291
|
* jQuery UI Resizable 1.8.16
|
292
292
|
*
|
293
293
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-de.js
CHANGED
@@ -14,7 +14,7 @@ jQuery(function($){
|
|
14
14
|
dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
|
15
15
|
dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
|
16
16
|
weekHeader: 'Wo',
|
17
|
-
dateFormat: 'dd
|
17
|
+
dateFormat: 'dd-mm-yy',
|
18
18
|
firstDay: 1,
|
19
19
|
isRTL: false,
|
20
20
|
showMonthAfterYear: false,
|
data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-en.js
CHANGED
@@ -14,7 +14,7 @@ jQuery(function($){
|
|
14
14
|
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
15
15
|
dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'],
|
16
16
|
weekHeader: 'Wk',
|
17
|
-
dateFormat: 'dd
|
17
|
+
dateFormat: 'dd-mm-yy',
|
18
18
|
firstDay: 1,
|
19
19
|
isRTL: false,
|
20
20
|
showMonthAfterYear: false,
|
data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-it.js
CHANGED
@@ -14,7 +14,7 @@ jQuery(function($){
|
|
14
14
|
dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
|
15
15
|
dayNamesMin: ['Do','Lu','Ma','Me','Gi','Ve','Sa'],
|
16
16
|
weekHeader: 'Sm',
|
17
|
-
dateFormat: 'dd
|
17
|
+
dateFormat: 'dd-mm-yy',
|
18
18
|
firstDay: 1,
|
19
19
|
isRTL: false,
|
20
20
|
showMonthAfterYear: false,
|
@@ -8,7 +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
|
-
|
11
|
+
copy_file "base.rb", "lib/generators/base.rb"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'rails/generators/rails/resource/resource_generator'
|
2
|
+
require File.join(File.dirname(__FILE__), '../../base')
|
2
3
|
|
3
4
|
module Rails
|
4
5
|
module Generators
|
5
6
|
class LeoscaGenerator < ResourceGenerator #metagenerator
|
7
|
+
include ::Leonardo::Nested
|
6
8
|
#puts 'rails:leosca'
|
7
9
|
|
8
10
|
remove_hook_for :resource_controller
|
@@ -10,6 +12,7 @@ module Rails
|
|
10
12
|
|
11
13
|
class_option :stylesheets, :type => :boolean, :default => false, :desc => "Generate Stylesheets"
|
12
14
|
class_option :stylesheet_engine, :desc => "Engine for Stylesheets"
|
15
|
+
class_option :under, :type => :string, :default => "", :banner => "brand/category", :desc => "Choose namespace(s) if resource must be nested"
|
13
16
|
|
14
17
|
hook_for :leosca_controller, :required => true
|
15
18
|
|
@@ -21,6 +24,24 @@ module Rails
|
|
21
24
|
invoke stylesheet_engine, [controller_name] if options[:stylesheets] && behavior == :invoke
|
22
25
|
end
|
23
26
|
|
27
|
+
#Override resource def
|
28
|
+
def add_resource_route
|
29
|
+
return if options[:actions].present?
|
30
|
+
|
31
|
+
if options[:under].present?
|
32
|
+
route_resources = plural_parent_resources
|
33
|
+
route_map = "resources"
|
34
|
+
else
|
35
|
+
route_resources = regular_class_path
|
36
|
+
route_map = "namespace"
|
37
|
+
end
|
38
|
+
|
39
|
+
route_config = route_resources.collect{|m| "#{route_map} :#{m} do " }.join(" ")
|
40
|
+
route_config << "resources :#{file_name.pluralize}"
|
41
|
+
route_config << " end" * route_resources.size
|
42
|
+
route route_config
|
43
|
+
end
|
44
|
+
|
24
45
|
end
|
25
46
|
end
|
26
47
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rails/generators/resource_helpers'
|
2
|
-
|
2
|
+
require File.join(File.dirname(__FILE__), '../../base')
|
3
3
|
|
4
4
|
WINDOWS = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
|
5
5
|
CRLF = WINDOWS ? "\r\n" : "\n"
|
@@ -8,14 +8,17 @@ module Rails
|
|
8
8
|
module Generators
|
9
9
|
class LeoscaControllerGenerator < NamedBase
|
10
10
|
include ResourceHelpers
|
11
|
-
|
11
|
+
include ::Leonardo::Leosca
|
12
|
+
include ::Leonardo::Nested
|
13
|
+
include ::Leonardo::Nested::Test
|
12
14
|
#puts 'rails:leosca_controller'
|
13
15
|
|
14
16
|
source_root File.expand_path('../templates', __FILE__)
|
15
17
|
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
16
|
-
class_option :seeds, :type => :boolean, :default => true, :
|
17
|
-
class_option :seeds_elements, :type => :string, :default => "30", :
|
18
|
-
class_option :remote, :type => :boolean, :default => true, :
|
18
|
+
class_option :seeds, :type => :boolean, :default => true, :desc => "Create seeds to run with rake db:seed"
|
19
|
+
class_option :seeds_elements, :type => :string, :default => "30", :desc => "Choose seeds elements", :banner => "NUMBER"
|
20
|
+
class_option :remote, :type => :boolean, :default => true, :desc => "Enable ajax. You can also do later set remote to true into index view."
|
21
|
+
class_option :under, :type => :string, :default => "", :banner => "brand/category", :desc => "Nested resources"
|
19
22
|
|
20
23
|
|
21
24
|
check_class_collision :suffix => "Controller"
|
@@ -48,17 +51,21 @@ module Rails
|
|
48
51
|
inject_into_file file, :after => "#Attributes zone - do not remove#{CRLF}" do
|
49
52
|
content = " #{file_name}:#{CRLF}"
|
50
53
|
attributes.each do |attribute|
|
51
|
-
content << " #{attribute.name}: \"#{
|
54
|
+
content << " #{attribute.name}: \"#{attribute.name.humanize}\"#{CRLF}"
|
52
55
|
end
|
53
56
|
content << " op_new: \"New #{singular_table_name}\"#{CRLF}"
|
54
57
|
content << " op_edit: \"Editing #{singular_table_name}\"#{CRLF}"
|
55
|
-
|
58
|
+
if nested?
|
59
|
+
content << " op_index: \"Listing #{plural_table_name} belongings to %{parent} %{name}\"#{CRLF}"
|
60
|
+
else
|
61
|
+
content << " op_index: \"Listing #{plural_table_name}\"#{CRLF}"
|
62
|
+
end
|
56
63
|
content
|
57
64
|
end
|
58
65
|
|
59
66
|
#Model name
|
60
67
|
inject_into_file file, :after => "models: &models#{CRLF}" do
|
61
|
-
<<-FILE.gsub(/^
|
68
|
+
<<-FILE.gsub(/^ /, '')
|
62
69
|
#{file_name}: "#{file_name.capitalize}"
|
63
70
|
#{controller_name}: "#{controller_name.capitalize}"
|
64
71
|
FILE
|
@@ -68,7 +75,7 @@ module Rails
|
|
68
75
|
inject_into_file file, :after => " hints:#{CRLF}" do
|
69
76
|
content = " #{file_name}:#{CRLF}"
|
70
77
|
attributes.each do |attribute|
|
71
|
-
attr_name = attribute.name.
|
78
|
+
attr_name = attribute.name.humanize
|
72
79
|
case attribute.type
|
73
80
|
when :integer, :decimal, :float
|
74
81
|
content << " #{attribute.name}: \"Fill the #{attr_name} with a#{"n" if attribute.type == :integer} #{attribute.type.to_s} number\"#{CRLF}"
|
@@ -76,7 +83,7 @@ module Rails
|
|
76
83
|
content << " #{attribute.name}: \"Select if this #{file_name} should be #{attr_name} or not\"#{CRLF}"
|
77
84
|
when :string, :text
|
78
85
|
content << " #{attribute.name}: \"Choose a good #{attr_name} for this #{file_name}\"#{CRLF}"
|
79
|
-
when :date, :datetime, :time
|
86
|
+
when :date, :datetime, :time, :timestamp
|
80
87
|
content << " #{attribute.name}: \"Choose a #{attribute.type.to_s} for #{attr_name}\"#{CRLF}"
|
81
88
|
else
|
82
89
|
content << " #{attribute.name}: \"Choose a #{attr_name}\"#{CRLF}"
|
@@ -88,17 +95,6 @@ module Rails
|
|
88
95
|
end
|
89
96
|
end
|
90
97
|
|
91
|
-
def update_layout_html
|
92
|
-
file = "app/views/layouts/_#{CONFIG[:default_style]}.html.erb"
|
93
|
-
inject_into_file file, :after => "<!-- Insert below other elements -->#{CRLF}" do
|
94
|
-
<<-FILE.gsub(/^ /, '')
|
95
|
-
#{"<% if can? :read, #{class_name} -%>" if authorization?}
|
96
|
-
<li class="<%= controller.controller_path == '#{controller_name}' ? 'active' : '' %>"><a href="<%= #{controller_name}_path %>"><%= t('models.#{controller_name}') %></a></li>
|
97
|
-
#{"<% end -%>" if authorization?}
|
98
|
-
FILE
|
99
|
-
end if File.exists?(file)
|
100
|
-
end
|
101
|
-
|
102
98
|
def update_ability_model
|
103
99
|
file = "app/models/ability.rb"
|
104
100
|
return unless File.exists?(file)
|
@@ -148,7 +144,7 @@ module Rails
|
|
148
144
|
|
149
145
|
check_attr_to_have, check_attr_to_not_have = get_attr_to_match
|
150
146
|
|
151
|
-
file = "spec/requests/#{
|
147
|
+
file = "spec/requests/#{plural_path_file_name}_spec.rb"
|
152
148
|
remove = <<-FILE.gsub(/^ /, '')
|
153
149
|
it "works! (now write some real specs)" do
|
154
150
|
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
@@ -163,23 +159,12 @@ module Rails
|
|
163
159
|
|
164
160
|
it "displays #{plural_table_name}" do
|
165
161
|
#{singular_table_name} = Factory(:#{singular_table_name})
|
166
|
-
visit #{
|
167
|
-
login_view_as(:user_guest)
|
162
|
+
visit #{list_resources_path_test}
|
163
|
+
#{"login_view_as(:user_guest)" if authentication?}
|
168
164
|
#save_and_open_page #uncomment to debug
|
169
165
|
page.should #{check_attr_to_have}
|
170
166
|
assert page.find("#tr\#{#{singular_table_name}.id}").visible?
|
171
167
|
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
168
|
FILE
|
184
169
|
end
|
185
170
|
|
@@ -193,8 +178,8 @@ module Rails
|
|
193
178
|
describe "POST /#{plural_table_name}" do
|
194
179
|
it "creates a new #{singular_table_name}" do
|
195
180
|
#{singular_table_name} = Factory.build(:#{singular_table_name})
|
196
|
-
visit
|
197
|
-
login_view_as(:
|
181
|
+
visit #{new_resource_path_test}
|
182
|
+
#{"login_view_as(:user_admin)" if authentication?}
|
198
183
|
#{items.join(CRLF)}
|
199
184
|
click_button "Create \#{I18n.t('models.#{singular_table_name}')}"
|
200
185
|
#save_and_open_page #uncomment to debug
|
@@ -202,11 +187,29 @@ module Rails
|
|
202
187
|
page.should #{check_attr_to_have}
|
203
188
|
end
|
204
189
|
end
|
190
|
+
|
191
|
+
describe "Check ajax /#{plural_table_name}" do
|
192
|
+
it "checks links on list page", :js => true do
|
193
|
+
#{singular_table_name} = Factory(:#{singular_table_name})
|
194
|
+
visit #{list_resources_path_test}
|
195
|
+
#{"login_view_as(:user_manager)" if authentication?} #authentication
|
196
|
+
page.find("div#list").should #{check_attr_to_have}
|
197
|
+
click_link I18n.t(:show)
|
198
|
+
page.find("div.ui-dialog").should #{check_attr_to_have} #checks if dialog is appeared
|
199
|
+
click_link "close" #close dialog
|
200
|
+
!page.find("div.ui-dialog").visible? #checks if dialog has been closed
|
201
|
+
click_link I18n.t(:destroy) #check ajax destroy
|
202
|
+
page.driver.browser.switch_to.alert.accept #confirms destroy
|
203
|
+
#save_and_open_page #uncomment to debug
|
204
|
+
page.find("div#list").should #{check_attr_to_not_have} #checks if content has been removed
|
205
|
+
!page.find("#tr\#{#{singular_table_name}.id}").visible? #checks if row has been hidden
|
206
|
+
end
|
207
|
+
end
|
205
208
|
FILE
|
206
209
|
end
|
207
210
|
|
208
211
|
file = "spec/factories.rb"
|
209
|
-
inject_into_file file, :
|
212
|
+
inject_into_file file, :before => " ### Insert below here other your factories ###" do
|
210
213
|
items = []
|
211
214
|
attributes.each do |attribute|
|
212
215
|
items << attribute_to_factories(attribute)
|
@@ -221,82 +224,6 @@ module Rails
|
|
221
224
|
|
222
225
|
end
|
223
226
|
|
224
|
-
protected
|
225
|
-
def authorization?
|
226
|
-
File.exists? "app/models/ability.rb"
|
227
|
-
end
|
228
|
-
def authentication?
|
229
|
-
return true if File.exists? "app/models/user.rb"
|
230
|
-
File.exists? "config/initializers/devise.rb"
|
231
|
-
end
|
232
|
-
def camel_case(str)
|
233
|
-
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
234
|
-
str.split('_').map { |i| i.capitalize }.join
|
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
|
-
|
300
227
|
end
|
301
228
|
end
|
302
229
|
end
|
@@ -1,38 +1,59 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
class <%= controller_class_name %>Controller < ApplicationController
|
3
|
-
<%= "before_filter :authenticate_user
|
4
|
-
<%= "load_and_authorize_resource" if authorization?
|
3
|
+
<%= "before_filter :authenticate_user!#{CRLF}" if authentication? -%>
|
4
|
+
<%= "load_and_authorize_resource#{CRLF}" if authorization? -%>
|
5
|
+
<%= "before_filter :load_parents#{CRLF}" if nested? -%>
|
6
|
+
|
7
|
+
<% if nested? -%>
|
8
|
+
def load_parents
|
9
|
+
<% base_parent_resources.each do |parent| -%>
|
10
|
+
@<%= parent %> = <%= parent.classify %>.find params[:<%= parent %>_id]
|
11
|
+
<% end -%>
|
12
|
+
end
|
13
|
+
<% end -%>
|
5
14
|
|
6
15
|
# GET <%= route_url %>
|
7
16
|
# GET <%= route_url %>.json
|
8
17
|
def index
|
9
18
|
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
|
10
|
-
|
19
|
+
conditions_fields = []
|
20
|
+
conditions_values = []
|
11
21
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
<%- attributes.each do |attribute| -%>
|
23
|
+
<% if nested? && (attribute.type == :references || attribute.type == :belongs_to) -%>
|
24
|
+
conditions_fields << "#{<%= class_name %>.table_name}.<%= base_parent_resources.last %>_id = ?"
|
25
|
+
conditions_values << @<%= base_parent_resources.last %>.id
|
26
|
+
<%- end -%>
|
27
|
+
<%- end -%>
|
16
28
|
|
29
|
+
if params[:<%= singular_table_name %>]
|
17
30
|
<%- attributes.each do |attribute| -%>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
<%- attr_name = case attribute.type
|
32
|
+
when :references, :belongs_to then "#{attribute.name}_id"
|
33
|
+
else attribute.name
|
34
|
+
end -%>
|
35
|
+
<%- conditions_operator_sign = case attribute.type
|
36
|
+
when :string, :text then "LIKE"
|
37
|
+
else "="
|
38
|
+
end -%>
|
39
|
+
<%- conditions_operator_value = case attribute.type
|
40
|
+
when :string, :text then "%"
|
41
|
+
else ""
|
42
|
+
end -%>
|
43
|
+
<% unless nested? && (attribute.type == :references || attribute.type == :belongs_to) -%>
|
44
|
+
|
45
|
+
if params[:<%= singular_table_name %>][:<%= attr_name %>] && params[:<%= singular_table_name %>][:<%= attr_name %>].length>0
|
46
|
+
conditions_fields << "#{<%= class_name %>.table_name}.<%= attr_name %> <%= conditions_operator_sign %> ?"
|
47
|
+
conditions_values << "<%= conditions_operator_value %>#{params[:<%= singular_table_name %>][:<%= attr_name %>]}<%= conditions_operator_value %>"
|
48
|
+
@<%= singular_table_name %>.<%= attr_name %> = params[:<%= singular_table_name %>][:<%= attr_name %>]
|
30
49
|
end
|
31
50
|
<%- end -%>
|
51
|
+
<%- end -%>
|
32
52
|
|
33
|
-
conditions = conditions_fields.join(' and ').to_a + conditions_values
|
34
53
|
end
|
35
54
|
|
55
|
+
conditions = conditions_fields.join(' and ').to_a + conditions_values
|
56
|
+
|
36
57
|
request.format = :csv if params[:commit] == 'Csv'
|
37
58
|
|
38
59
|
@<%= plural_table_name %> = case request.format
|
@@ -65,6 +86,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
65
86
|
respond_to do |format|
|
66
87
|
format.html # show.html.erb
|
67
88
|
format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
|
89
|
+
format.js
|
68
90
|
end
|
69
91
|
end
|
70
92
|
|
@@ -72,6 +94,9 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
72
94
|
# GET <%= route_url %>/new.json
|
73
95
|
def new
|
74
96
|
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
|
97
|
+
<%- if nested? -%>
|
98
|
+
@<%= singular_table_name %>.<%= last_parent %>_id = @<%= last_parent %>.id
|
99
|
+
<%- end -%>
|
75
100
|
|
76
101
|
respond_to do |format|
|
77
102
|
format.html # new.html.erb
|
@@ -88,10 +113,13 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
88
113
|
# POST <%= route_url %>.json
|
89
114
|
def create
|
90
115
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
|
116
|
+
<%- if nested? -%>
|
117
|
+
@<%= singular_table_name %>.<%= last_parent %>_id ||= @<%= last_parent %>.id
|
118
|
+
<%- end -%>
|
91
119
|
|
92
120
|
respond_to do |format|
|
93
121
|
if @<%= orm_instance.save %>
|
94
|
-
format.html { redirect_to
|
122
|
+
format.html { redirect_to <%= show_resource_path("@") %>, <%= key_value :notice, "I18n.t(:created, :model => I18n.t('models.#{singular_table_name}'))" %> }
|
95
123
|
format.json { render <%= key_value :json, "@#{singular_table_name}" %>, <%= key_value :status, ':created' %>, <%= key_value :location, "@#{singular_table_name}" %> }
|
96
124
|
else
|
97
125
|
format.html { render <%= key_value :action, '"new"' %> }
|
@@ -107,7 +135,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
107
135
|
|
108
136
|
respond_to do |format|
|
109
137
|
if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
|
110
|
-
format.html { redirect_to
|
138
|
+
format.html { redirect_to <%= show_resource_path("@") %>, <%= key_value :notice, "I18n.t(:updated, :model => I18n.t('models.#{singular_table_name}'))" %> }
|
111
139
|
format.json { head :ok }
|
112
140
|
else
|
113
141
|
format.html { render <%= key_value :action, '"edit"' %> }
|
@@ -123,7 +151,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
123
151
|
@<%= orm_instance.destroy %>
|
124
152
|
|
125
153
|
respond_to do |format|
|
126
|
-
format.html { redirect_to <%=
|
154
|
+
format.html { redirect_to <%= list_resources_path %> }
|
127
155
|
format.json { head :ok }
|
128
156
|
format.js
|
129
157
|
end
|
data/template.rb
CHANGED
@@ -27,7 +27,8 @@ if use_git
|
|
27
27
|
EOS
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
pagination = yes?("Pagination ?")
|
31
|
+
gem 'kaminari' if pagination
|
31
32
|
|
32
33
|
gem 'paperclip' if yes?("Attachment ?")
|
33
34
|
|
@@ -80,6 +81,8 @@ end
|
|
80
81
|
|
81
82
|
run "bundle install"
|
82
83
|
|
84
|
+
generate "kaminari:config" if pagination
|
85
|
+
|
83
86
|
generate "rspec:install" if rspec
|
84
87
|
|
85
88
|
generate "formtastic:install" if formtastic
|