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
data/CHANGELOG
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
+
1.6.0 (September 16th, 2011) Marco Mastrodonato
|
2
|
+
* Nested resource: use new option rails g leosca product --under=category field:type
|
3
|
+
* Improved views data format
|
4
|
+
* Added ajax mode for show view managed by jquery-ui dialog
|
5
|
+
* Updated specs for namespaced resource and other improvements
|
6
|
+
* Several little improvements
|
7
|
+
|
8
|
+
|
9
|
+
|
1
10
|
1.5.0 (September 6th, 2011) Marco Mastrodonato
|
2
11
|
* Added Rspec support with requests to check ajax => All green if you use formtastic views (associations with select)
|
3
12
|
* New template
|
4
13
|
* Little improvements
|
5
14
|
|
6
|
-
Next release:
|
7
|
-
* Nested resource
|
8
|
-
* Code improvements
|
9
15
|
|
10
16
|
|
11
17
|
1.4.1 (August 25th, 2011) Marco Mastrodonato
|
data/lib/generators/base.rb
CHANGED
@@ -1,28 +1,266 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
puts 'ok'
|
4
|
-
end
|
1
|
+
module Leonardo
|
2
|
+
module Leosca
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
protected
|
5
|
+
def authorization?
|
6
|
+
File.exists? "app/models/ability.rb"
|
7
|
+
end
|
8
|
+
def authentication?
|
9
|
+
return true if File.exists? "app/models/user.rb"
|
10
|
+
File.exists? "config/initializers/devise.rb"
|
11
|
+
end
|
12
|
+
def formtastic?
|
13
|
+
return false unless options.formtastic?
|
14
|
+
File.exists? "config/initializers/formtastic.rb"
|
15
|
+
end
|
16
|
+
def jquery_ui?
|
17
|
+
File.exists? "vendor/assets/javascripts/jquery-ui"
|
18
|
+
end
|
19
|
+
def pagination?
|
20
|
+
File.exists? "config/initializers/kaminari_config.rb"
|
21
|
+
end
|
22
|
+
def attribute_to_hash(attribute)
|
23
|
+
name = case attribute.type
|
24
|
+
when :references, :belongs_to then ":#{attribute.name}_id"
|
25
|
+
else ":#{attribute.name}"
|
26
|
+
end
|
27
|
+
value = case attribute.type
|
28
|
+
when :boolean then "true"
|
29
|
+
when :integer then "#"
|
30
|
+
when :float, :decimal then "#.46"
|
31
|
+
when :references, :belongs_to then "#"
|
32
|
+
when :date then "#{Time.now.strftime("%Y-%m-%d 00:00:00.000")}".inspect
|
33
|
+
when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
|
34
|
+
when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
|
35
|
+
else "#{attribute.name.titleize}\#".inspect
|
36
|
+
end
|
37
|
+
" #{name} => #{value}"
|
38
|
+
end
|
39
|
+
def attribute_to_factories(attribute)
|
40
|
+
str_space = " " * (20-attribute.name.size).abs
|
41
|
+
name = case attribute.type
|
42
|
+
when :references, :belongs_to then "#{singular_table_name[0..0]}.association #{str_space}"
|
43
|
+
when :boolean, :datetime, :time, :timestamp
|
44
|
+
then "#{singular_table_name[0..0]}.#{attribute.name} #{str_space}"
|
45
|
+
else "#{singular_table_name[0..0]}.sequence(:#{attribute.name})#{str_space}"
|
46
|
+
end
|
47
|
+
value = case attribute.type
|
48
|
+
when :boolean then "true"
|
49
|
+
when :integer then "{|n| n }"
|
50
|
+
when :float, :decimal then "{|n| n }"
|
51
|
+
when :references, :belongs_to then ":#{attribute.name}"
|
52
|
+
when :date then "{|n| n.month.ago }"
|
53
|
+
when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
|
54
|
+
when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
|
55
|
+
else "{|n| \"#{attribute.name.titleize}\#{n}\" }"
|
56
|
+
end
|
57
|
+
" #{name} #{value}"
|
58
|
+
end
|
59
|
+
def attribute_to_requests(attribute)
|
60
|
+
case attribute.type
|
61
|
+
when :boolean then " check '#{singular_table_name}_#{attribute.name}' if #{singular_table_name}.#{attribute.name}"
|
62
|
+
when :references, :belongs_to then " select #{singular_table_name}.#{attribute.name}.name, :from => '#{singular_table_name}_#{attribute.name}_id'"
|
63
|
+
when :datetime, :time, :timestamp
|
64
|
+
then ""
|
65
|
+
when :date then " fill_in '#{singular_table_name}_#{attribute.name}', :with => #{singular_table_name}.#{attribute.name}.strftime('%d-%m-%Y')"
|
66
|
+
else " fill_in '#{singular_table_name}_#{attribute.name}', :with => #{singular_table_name}.#{attribute.name}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
def attribute_to_erb(attribute, object)
|
70
|
+
case attribute.type
|
71
|
+
when :boolean then "<%= #{object}.#{attribute.name} ? style_image_tag(\"ico_v.png\", :class => \"ico_true\") : style_image_tag(\"ico_x.png\", :class => \"ico_false\") %>"
|
72
|
+
when :references, :belongs_to then "<%= link_to((#{object}.#{attribute.name}.try(:name) || \"\#{t('models.#{attribute.name}')} \#{#{object}.#{attribute.name}.try(:id)}\"), #{object}.#{attribute.name}) %>"
|
73
|
+
when :integer then "<%= number_with_delimiter #{object}.#{attribute.name} %>"
|
74
|
+
when :decimal then "<%= number_to_currency #{object}.#{attribute.name} %>"
|
75
|
+
when :float then "<%= number_with_precision #{object}.#{attribute.name} %>"
|
76
|
+
when :date then "<%= #{object}.#{attribute.name}.strftime('%d-%m-%Y') if #{object}.#{attribute.name} %>"
|
77
|
+
when :datetime then "<%= #{object}.#{attribute.name}.strftime('%d-%m-%Y %H:%M:%S') if #{object}.#{attribute.name} %>"
|
78
|
+
when :time, :timestamp then "<%= #{object}.#{attribute.name}.strftime('%H:%M:%S') if #{object}.#{attribute.name} %>"
|
79
|
+
else "<%= #{object}.#{attribute.name} %>"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
def get_attr_to_match(view=:list)
|
83
|
+
attributes.each do |attribute|
|
84
|
+
return "have_content(#{singular_table_name}.#{attribute.name})",
|
85
|
+
"have_no_content(#{singular_table_name}.#{attribute.name})" if attribute.type==:string
|
86
|
+
end
|
87
|
+
#If there are not string attributes
|
88
|
+
case view
|
89
|
+
when :list
|
90
|
+
return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')"
|
91
|
+
when :show
|
92
|
+
return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
def plural_path_file_name
|
96
|
+
(class_path + [plural_table_name]).join('/')
|
97
|
+
end
|
21
98
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
99
|
+
|
100
|
+
module Nested
|
101
|
+
protected
|
102
|
+
|
103
|
+
#product under brand/category => "brand_category_product"
|
104
|
+
def underscore_resource_path(names=:all_singular)
|
105
|
+
case names
|
106
|
+
when :all_singular
|
107
|
+
resource_path.join('_')
|
108
|
+
when :all_plural
|
109
|
+
#who needs?
|
110
|
+
when :parent_singular_resource_plural
|
111
|
+
resource_path.join('_').pluralize
|
112
|
+
else
|
113
|
+
"#{names.to_s}_not_supported"
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
#product => products_path
|
119
|
+
#product under category => category_products_path(@category)
|
120
|
+
#product under brand/category => brand_category_products_path(@brand, @category)
|
121
|
+
def list_resources_path
|
122
|
+
"#{underscore_resource_path(:parent_singular_resource_plural)}_path(#{formatted_parent_resources("@")})"
|
123
|
+
end
|
124
|
+
|
125
|
+
#product => "product"
|
126
|
+
#product under category => "[@category, product]"
|
127
|
+
#product under brand/category => "[@brand, @category, product]"
|
128
|
+
def destroy_resource_path(prefix_resource="")
|
129
|
+
formatted_resource_path("@", prefix_resource, "[]")
|
130
|
+
end
|
131
|
+
|
132
|
+
#product => "product"
|
133
|
+
#product under category => "[@category, product]"
|
134
|
+
#product under brand/category => "[@brand, @category, product]"
|
135
|
+
def show_resource_path(prefix_resource="")
|
136
|
+
formatted_resource_path("@", prefix_resource, "[]")
|
137
|
+
end
|
138
|
+
|
139
|
+
#product => "@product"
|
140
|
+
#product under category => "[@category, @product]"
|
141
|
+
#product under brand/category => "[@brand, @category, @product]"
|
142
|
+
def form_resource_path
|
143
|
+
formatted_resource_path("@", "@", "[]")
|
144
|
+
end
|
145
|
+
|
146
|
+
#product => new_product_path
|
147
|
+
#product under category => new_category_product_path(@category)
|
148
|
+
#product under brand/category => new_brand_category_product_path(@brand, @category)
|
149
|
+
def new_resource_path
|
150
|
+
"new_#{underscore_resource_path}_path(#{formatted_parent_resources("@")})"
|
151
|
+
end
|
152
|
+
|
153
|
+
#product => edit_product_path(@product)
|
154
|
+
#product under category => edit_category_product_path(@category, @product)
|
155
|
+
#product under brand/category => edit_brand_category_product_path(@brand, @category, @product)
|
156
|
+
def edit_resource_path(prefix_resource="")
|
157
|
+
"edit_#{underscore_resource_path}_path(#{formatted_resource_path("@", prefix_resource)})"
|
158
|
+
end
|
159
|
+
|
160
|
+
#product under brand/category => "[brand, category, product]" or "[@brand, @category, @product]" or "@brand, @category, @product" or [product.brand, product.category, product]
|
161
|
+
def formatted_resource_path(prefix_parent="", prefix_resource="", delimiter="", resource=nil)
|
162
|
+
formatted_resource_base resource_path(prefix_parent, prefix_resource, resource), delimiter
|
163
|
+
end
|
164
|
+
|
165
|
+
#product under brand/category => "[brand, category]" or "[@brand, @category]" or "@brand, @category" or product.brand, product.category
|
166
|
+
def formatted_parent_resources(prefix_parent="", delimiter="", resource=nil)
|
167
|
+
prefix_parent = "#{resource}." if resource
|
168
|
+
formatted_resource_base parent_resources(prefix_parent), delimiter
|
169
|
+
end
|
170
|
+
|
171
|
+
def formatted_resource_base(resources, delimiter="")
|
172
|
+
str_resources = resources.join(', ')
|
173
|
+
resources.size > 1 ? "#{delimiter[0..0]}#{str_resources}#{delimiter[1..1]}" : str_resources
|
174
|
+
end
|
175
|
+
|
176
|
+
#product under brand/category => ["brand", "category", "product"] or ["@brand", "@category", "@product"]
|
177
|
+
def resource_path(prefix_parent="", prefix_resource="", resource=nil)
|
178
|
+
if resource
|
179
|
+
prefix_parent = "#{resource}."
|
180
|
+
else
|
181
|
+
resource = singular_table_name
|
182
|
+
end
|
183
|
+
|
184
|
+
if nested?
|
185
|
+
parent_resources(prefix_parent) << "#{prefix_resource}#{resource}"
|
186
|
+
else
|
187
|
+
["#{prefix_resource}#{resource}"]
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
#product under brand/category => "categories"
|
192
|
+
def plural_last_parent
|
193
|
+
plural_parent_resources.last
|
194
|
+
end
|
195
|
+
|
196
|
+
#product under brand/category => ["brands", "categories"] or ["@brands", "@categories"]
|
197
|
+
def plural_parent_resources(prefix_parent="")
|
198
|
+
base_parent_resources.map{|m| "#{prefix_parent}#{m.pluralize}"}
|
199
|
+
end
|
200
|
+
|
201
|
+
#product under brand/category => ["brand", "category"] or ["@brand", "@category"]
|
202
|
+
def parent_resources(prefix_parent="")
|
203
|
+
base_parent_resources.map{|m| "#{prefix_parent}#{m}"}
|
204
|
+
end
|
205
|
+
|
206
|
+
#product under brand/category => "category"
|
207
|
+
def last_parent
|
208
|
+
base_parent_resources.last
|
209
|
+
end
|
210
|
+
|
211
|
+
#product under brand/category => ["brand", "category"]
|
212
|
+
def base_parent_resources
|
213
|
+
options[:under].split('/').map{|m| m.underscore}
|
214
|
+
end
|
215
|
+
|
216
|
+
def nested?
|
217
|
+
options[:under].present?
|
218
|
+
end
|
219
|
+
|
220
|
+
module Test
|
221
|
+
protected
|
222
|
+
#Add parent(s) param(s) to request
|
223
|
+
#get :index for a product under category => get :index, :category_id => product.category_id.to_s
|
224
|
+
def nested_params_http_request(value=nil)
|
225
|
+
return unless nested?
|
226
|
+
", " << base_parent_resources.map{|m| ":#{m}_id => #{value ? value.to_s.inspect : "#{file_name}.#{m}_id.to_s"}"}.join(', ')
|
227
|
+
end
|
228
|
+
|
229
|
+
#Create new parent(s) and add it to request
|
230
|
+
#get :index for a product under category => get :index, :category_id => Factory(:category).id.to_s
|
231
|
+
def nested_params_http_request_new_parent
|
232
|
+
return unless nested?
|
233
|
+
", " << base_parent_resources.map{|m| ":#{m}_id => Factory(:#{m}).id.to_s"}.join(', ')
|
234
|
+
end
|
235
|
+
|
236
|
+
#product => products_path
|
237
|
+
#product under category => category_products_path(product.category)
|
238
|
+
#product under brand/category => brand_category_products_path(product.brand, product.category)
|
239
|
+
def list_resources_path_test(resource=nil, prefix_parent=nil)
|
240
|
+
unless prefix_parent
|
241
|
+
resource = resource || singular_table_name
|
242
|
+
prefix_parent = "#{resource}."
|
243
|
+
end
|
244
|
+
"#{underscore_resource_path(:parent_singular_resource_plural)}_path(#{formatted_parent_resources(prefix_parent, "", resource)})"
|
245
|
+
end
|
246
|
+
|
247
|
+
#product => "product"
|
248
|
+
#product under category => "[category, product]" or "[product.category, product]"
|
249
|
+
#product under brand/category => "[brand, category, product]" or "[product.brand, product.category, product]"
|
250
|
+
def show_resource_path_test(resource=nil, prefix_parent=nil, prefix_resource="")
|
251
|
+
resource = resource || singular_table_name
|
252
|
+
prefix_parent = prefix_parent || "#{resource}."
|
253
|
+
formatted_resource_path(prefix_parent, prefix_resource, "[]", resource)
|
254
|
+
end
|
255
|
+
|
256
|
+
#product => new_product_path
|
257
|
+
#product under category => new_category_product_path(product.category)
|
258
|
+
#product under brand/category => new_brand_category_product_path(product.brand, product.category)
|
259
|
+
def new_resource_path_test(resource=nil, prefix_parent=nil)
|
260
|
+
resource = resource || singular_table_name
|
261
|
+
prefix_parent = prefix_parent || "#{resource}."
|
262
|
+
"new_#{underscore_resource_path}_path(#{formatted_parent_resources(prefix_parent, "",resource)})"
|
263
|
+
end
|
264
|
+
end
|
27
265
|
end
|
28
266
|
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'rails/generators/erb'
|
2
2
|
require 'rails/generators/resource_helpers'
|
3
|
+
require File.join(File.dirname(__FILE__), '../../base')
|
3
4
|
|
4
5
|
module Erb
|
5
6
|
module Generators
|
6
7
|
class LeoscaGenerator < Base
|
7
8
|
include Rails::Generators::ResourceHelpers
|
9
|
+
include ::Leonardo::Leosca
|
10
|
+
include ::Leonardo::Nested
|
8
11
|
#puts 'erb:leosca'
|
9
12
|
|
10
13
|
source_root File.expand_path('../templates', __FILE__)
|
@@ -12,6 +15,7 @@ module Erb
|
|
12
15
|
class_option :authorization, :type => :boolean, :default => true, :description => "Add code to manage authorization with cancan"
|
13
16
|
class_option :remote, :type => :boolean, :default => true, :description => "Enable ajax. You can also do later set remote to true into index view."
|
14
17
|
class_option :formtastic, :type => :boolean, :default => true, :description => "Create forms to manage with formtastic gem"
|
18
|
+
class_option :under, :type => :string, :default => "", :banner => "brand/category"
|
15
19
|
|
16
20
|
def create_root_folder
|
17
21
|
empty_directory File.join("app/views", controller_file_path)
|
@@ -35,13 +39,46 @@ module Erb
|
|
35
39
|
template filename_source, File.join("app/views", controller_file_path, filename)
|
36
40
|
end
|
37
41
|
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_layout_html
|
45
|
+
file = "app/views/layouts/_#{CONFIG[:default_style]}.html.erb"
|
46
|
+
if nested?
|
47
|
+
inject_into_file file, :after => "<!-- Insert below here other #{last_parent} elements -->#{CRLF}" do
|
48
|
+
<<-FILE.gsub(/^ /, '')
|
49
|
+
#{"<% if can?(:read, #{class_name}) && controller.controller_path == '#{controller_name}' -%>" if authorization?}
|
50
|
+
<li class="active"><%= t('models.#{plural_table_name}') %></li>
|
51
|
+
<!-- Insert below here other #{singular_table_name} elements -->
|
52
|
+
#{"<% end -%>" if authorization?}
|
53
|
+
FILE
|
54
|
+
end if File.exists?(file)
|
55
|
+
else
|
56
|
+
inject_into_file file, :after => "<!-- Insert below other elements -->#{CRLF}" do
|
57
|
+
<<-FILE.gsub(/^ /, '')
|
58
|
+
#{"<% if can?(:read, #{class_name}) -%>" if authorization?}
|
59
|
+
<li class="<%= controller.controller_path == '#{controller_name}' ? 'active' : '' %>"><a href="<%= #{plural_table_name}_path %>"><%= t('models.#{plural_table_name}') %></a></li>
|
60
|
+
<!-- Insert below here other #{singular_table_name} elements -->
|
61
|
+
#{"<% end -%>" if authorization?}
|
62
|
+
FILE
|
63
|
+
end if File.exists?(file)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def update_parent_views
|
68
|
+
return unless nested?
|
69
|
+
file = "app/views/#{plural_last_parent}/_list.erb"
|
70
|
+
inject_into_file file, :before => "<!-- Manage section, do not remove this tag -->" do
|
71
|
+
<<-FILE.gsub(/^ /, '')
|
72
|
+
<td><%= link_to t('models.#{plural_table_name}'), #{underscore_resource_path :parent_singular_resource_plural}_path(#{last_parent}) %></td>
|
38
73
|
|
74
|
+
FILE
|
75
|
+
end if File.exists?(file)
|
39
76
|
end
|
40
77
|
|
41
78
|
protected
|
42
79
|
|
43
80
|
def available_views
|
44
|
-
%w(index edit show new _form _list destroy)
|
81
|
+
%w(index edit show new _form _list destroy _show)
|
45
82
|
end
|
46
83
|
|
47
84
|
def filenames_all_formats(name, paths=[], formats=[:html, :js, nil])
|
@@ -61,27 +98,6 @@ module Erb
|
|
61
98
|
[name, format, parser].compact.join(".")
|
62
99
|
end
|
63
100
|
|
64
|
-
def authorization?
|
65
|
-
File.exists? "app/models/ability.rb"
|
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
|
75
|
-
def formtastic?
|
76
|
-
return false unless options.formtastic?
|
77
|
-
File.exists? "config/initializers/formtastic.rb"
|
78
|
-
end
|
79
|
-
def jquery_ui?
|
80
|
-
File.exists? "vendor/assets/javascripts/jquery-ui"
|
81
|
-
end
|
82
|
-
def pagination?
|
83
|
-
File.exists? "config/initializers/kaminari_config.rb"
|
84
|
-
end
|
85
101
|
end
|
86
102
|
end
|
87
103
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%%= form_for(
|
1
|
+
<%%= form_for(<%= form_resource_path %>) do |f| %>
|
2
2
|
<%% if @<%= singular_table_name %>.errors.any? %>
|
3
3
|
<div id="error_explanation">
|
4
4
|
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
@@ -11,12 +11,23 @@
|
|
11
11
|
</div>
|
12
12
|
<%% end %>
|
13
13
|
|
14
|
-
|
14
|
+
<%- attributes.each do |attribute| -%>
|
15
15
|
<div class="field">
|
16
16
|
<%%= f.label :<%= attribute.name %>, t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %><br />
|
17
|
+
<%- case attribute.type
|
18
|
+
when :references, :belongs_to -%>
|
19
|
+
<%% if @<%= singular_table_name %>.new_record? -%>
|
20
|
+
<%%= f.collection_select :<%= attribute.name %>_id, <%= attribute.name.classify %>.all, :id, :name, :prompt => true if can?(:manage, <%=class_name %>) %>
|
21
|
+
<%% else -%>
|
22
|
+
<%%= f.collection_select :<%= attribute.name %>_id, <%= attribute.name.classify %>.all, :id, :name, :prompt => true %>
|
23
|
+
<%% end -%>
|
24
|
+
<%- when :date -%>
|
25
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> <%=", :class => \"calendar\"" if jquery_ui?%> %>
|
26
|
+
<%- else -%>
|
17
27
|
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
28
|
+
<%- end -%>
|
18
29
|
</div>
|
19
|
-
|
30
|
+
<%- end -%>
|
20
31
|
<div class="actions">
|
21
32
|
<%%= f.submit :class => 'button large' %>
|
22
33
|
</div>
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<%- if pagination?
|
1
|
+
<%- if pagination? %>
|
2
2
|
<%%= paginate @<%= plural_table_name %>, :remote => remote %>
|
3
|
-
<%- end
|
3
|
+
<%- end %>
|
4
4
|
<div class="separator"></div>
|
5
5
|
|
6
6
|
<table class='user' cellspacing='0'>
|
@@ -15,36 +15,29 @@
|
|
15
15
|
</tr>
|
16
16
|
</thead>
|
17
17
|
<tbody>
|
18
|
-
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>|
|
18
|
+
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| -%>
|
19
19
|
<tr id="tr<%%= <%= singular_table_name %>.id %>" class="<%%= cycle("odd", "even")%>">
|
20
20
|
<%- attributes.each do |attribute| -%>
|
21
|
-
|
22
|
-
when :boolean -%>
|
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>
|
24
|
-
<%- when :references, :belongs_to -%>
|
25
|
-
<%% link_name = <%= singular_table_name %>.<%= attribute.name %>.try(:name) || <%= singular_table_name %>.<%= attribute.name %>.try(:id) %>
|
26
|
-
<td><%%= link_to(link_name, <%= singular_table_name %>.<%= attribute.name %> ) %></td>
|
27
|
-
<%- else -%>
|
28
|
-
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
|
29
|
-
<%- end -%>
|
21
|
+
<td><%= attribute_to_erb(attribute, singular_table_name) -%></td>
|
30
22
|
<%- end -%>
|
31
|
-
|
23
|
+
<!-- Manage section, do not remove this tag -->
|
24
|
+
<td><%%= link_to t(:show), <%= show_resource_path %><%= ", :remote => remote" if jquery_ui? %> %></td>
|
32
25
|
<%- if authorization? -%>
|
33
|
-
|
26
|
+
<%%- if can? :update, <%= singular_table_name %> -%>
|
34
27
|
<%- end -%>
|
35
|
-
<td><%%= link_to t(:edit),
|
28
|
+
<td><%%= link_to t(:edit), <%= edit_resource_path %> %></td>
|
36
29
|
<%- if authorization? -%>
|
37
|
-
|
30
|
+
<%%- end -%>
|
38
31
|
<%- end -%>
|
39
32
|
<%- if authorization? -%>
|
40
|
-
|
33
|
+
<%%- if can? :destroy, <%= singular_table_name %> -%>
|
41
34
|
<%- end -%>
|
42
|
-
<td><%%= link_to t(:destroy), <%=
|
35
|
+
<td><%%= link_to t(:destroy), <%= destroy_resource_path %>, <%= key_value :confirm, "t(:sure?)" %>, <%= key_value :method, ":delete" %>, :remote => remote %></td>
|
43
36
|
<%- if authorization? -%>
|
44
|
-
|
37
|
+
<%%- end -%>
|
45
38
|
<%- end -%>
|
46
39
|
</tr>
|
47
|
-
<%% end
|
40
|
+
<%% end -%>
|
48
41
|
</tbody>
|
49
42
|
</table>
|
50
43
|
|
@@ -1,11 +1,9 @@
|
|
1
|
-
<%% secondary_navigation({:value => link_to(t(:list), <%=
|
2
|
-
({:value => link_to(t(:add),
|
1
|
+
<%% secondary_navigation({:value => link_to(t(:list), <%= list_resources_path %>)},
|
2
|
+
({:value => link_to(t(:add), <%= new_resource_path %>)}<%= " if can?(:create, @#{singular_table_name})" if authorization? %>),
|
3
3
|
{:value => t(:edit), :active => true},
|
4
|
-
{:value => link_to(t(:show),
|
4
|
+
{:value => link_to(t(:show), <%= show_resource_path("@") %>)}
|
5
5
|
) %>
|
6
6
|
|
7
7
|
<%% title t('attributes.<%= singular_table_name %>.op_edit') %>
|
8
8
|
|
9
9
|
<%%= render 'form' %>
|
10
|
-
<!--<%%#= link_to t(:show), @<%= singular_table_name %> %> |-->
|
11
|
-
<!--<%%#= link_to t(:back), <%= index_helper %>_path %>-->
|
@@ -1,11 +1,17 @@
|
|
1
|
-
<%%= semantic_form_for(
|
1
|
+
<%%= semantic_form_for(<%= form_resource_path %>) do |f| %>
|
2
2
|
<%%= f.inputs do %>
|
3
3
|
<%- attributes.each do |attribute| -%>
|
4
4
|
<%- case attribute.type
|
5
|
-
when :
|
6
|
-
|
7
|
-
|
5
|
+
when :references, :belongs_to -%>
|
6
|
+
<%% if @<%= singular_table_name %>.new_record? -%>
|
7
|
+
<%%= f.input :<%= attribute.name %> if can?(:manage, <%=class_name %>) %>
|
8
|
+
<%% else -%>
|
8
9
|
<%%= f.input :<%= attribute.name %> %>
|
10
|
+
<%% end -%>
|
11
|
+
<%- when :date -%>
|
12
|
+
<%%= f.input :<%= attribute.name %>, :as => :string, :input_html => { :class => 'calendar', :maxlength => 10 } %>
|
13
|
+
<%- else -%>
|
14
|
+
<%%= f.input :<%= attribute.name %> %>
|
9
15
|
<%- end -%>
|
10
16
|
<%- end -%>
|
11
17
|
<%% end %>
|
@@ -1,16 +1,28 @@
|
|
1
1
|
<%% secondary_navigation({:value => t(:list), :active => true},
|
2
|
-
({:value => link_to(t(:add),
|
2
|
+
({:value => link_to(t(:add), <%= new_resource_path %> )}<%= " if can?(:create, @#{singular_table_name})" if authorization? %>)
|
3
3
|
) %>
|
4
4
|
|
5
|
-
<%% title t('attributes.<%= singular_table_name %>.op_index') %>
|
5
|
+
<%% title t('attributes.<%= singular_table_name %>.op_index'<%= ", {:parent => \"#{last_parent}\", :name => @#{last_parent}.try(:name) || @#{last_parent}.try(:id)}" if nested? -%>) %>
|
6
6
|
|
7
7
|
<%% remote = <%= options.remote? %> %>
|
8
|
-
<%%= form_for
|
8
|
+
<%%= form_for <%= show_resource_path("@") %>, :remote => remote, :html => { :method => :get, :id => "form_search" } do |f| %>
|
9
9
|
<div class="filter-container">
|
10
10
|
<%- attributes.each do |attribute| -%>
|
11
11
|
<div class="filter-field">
|
12
|
+
<%- case attribute.type -%>
|
13
|
+
<%- when :references, :belongs_to -%>
|
14
|
+
<%- unless nested? -%>
|
15
|
+
<b><%%= f.label :<%= attribute.name %>, t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %></b><br />
|
16
|
+
<%- end -%>
|
17
|
+
<%- else -%>
|
12
18
|
<b><%%= f.label :<%= attribute.name %>, t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %></b><br />
|
19
|
+
<%- end -%>
|
20
|
+
|
13
21
|
<%- case attribute.type -%>
|
22
|
+
<%- when :references, :belongs_to -%>
|
23
|
+
<%- unless nested? -%>
|
24
|
+
<%%= f.collection_select :<%= attribute.name %>_id, <%= attribute.name.classify %>.all, :id, :name, :prompt => true %>
|
25
|
+
<%- end -%>
|
14
26
|
<%- when :boolean -%>
|
15
27
|
<%%= radio_button("<%= singular_table_name %>", "<%= attribute.name %>", "1", {:checked => (@<%= singular_table_name %>.<%= attribute.name %>)}) %><%%= label_tag "<%= singular_table_name %>_<%= attribute.name %>_1", t(:yes) %><br />
|
16
28
|
<%%= radio_button("<%= singular_table_name %>", "<%= attribute.name %>", "0", {:checked => (!@<%= singular_table_name %>.<%= attribute.name %>)}) %><%%= label_tag "<%= singular_table_name %>_<%= attribute.name %>_0", t(:no) %><br />
|
@@ -22,7 +34,6 @@
|
|
22
34
|
<%- else -%>
|
23
35
|
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
24
36
|
<%- end -%>
|
25
|
-
|
26
37
|
</div>
|
27
38
|
<%- end -%>
|
28
39
|
<div style="clear:both;">
|
@@ -1,25 +1,8 @@
|
|
1
|
-
<%% secondary_navigation({:value => link_to(t(:list)
|
2
|
-
({:value => link_to(t(:add),
|
3
|
-
({:value => link_to(t(:edit),
|
4
|
-
{:value
|
1
|
+
<%% secondary_navigation({:value => link_to(t(:list), <%= list_resources_path %>)},
|
2
|
+
({:value => link_to(t(:add), <%= new_resource_path %>)}<%= " if can?(:create, @#{singular_table_name})" if authorization? %>),
|
3
|
+
({:value => link_to(t(:edit), <%= edit_resource_path("@") %>)}<%= " if can?(:update, @#{singular_table_name})" if authorization? %>),
|
4
|
+
{:value => t(:show), :active => true}
|
5
5
|
)%>
|
6
6
|
|
7
|
-
|
8
|
-
<% attributes.each do |attribute| -%>
|
9
|
-
<tr>
|
10
|
-
<%- case attribute.type
|
11
|
-
when :boolean -%>
|
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", :class => "ico_true") : style_image_tag("ico_x.png", :class => "ico_false") %></td>
|
14
|
-
<%- when :references, :belongs_to -%>
|
15
|
-
<%% link_name = @<%= singular_table_name %>.<%= attribute.name %>.try(:name) || @<%= singular_table_name %>.<%= attribute.name %>.try(:id) %>
|
16
|
-
<td><b><%%= t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %>:</b></td>
|
17
|
-
<td><%%= link_to(link_name, @<%= singular_table_name %>.<%= attribute.name %> ) %></td>
|
18
|
-
<%- else -%>
|
19
|
-
<td><b><%%= t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %>:</b></td>
|
20
|
-
<td><%%= @<%= singular_table_name %>.<%= attribute.name %> %></td>
|
21
|
-
<%- end -%>
|
22
|
-
</tr>
|
23
|
-
<% end -%>
|
24
|
-
</table>
|
7
|
+
<%%= render 'show' %>
|
25
8
|
|