active_leonardo 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ed43cceaa12e2fb49d8596d40108d1556237036
4
- data.tar.gz: ef2f16bd7946187764a3c7f82bb437cd22ad8841
3
+ metadata.gz: a51e2a1f9b84ce890c72d1e8d44be29a946648e2
4
+ data.tar.gz: 4c03750211817703963ac3ce96a1e6f8e55f4abb
5
5
  SHA512:
6
- metadata.gz: d4135cc1e61eebc8ec5d6fbcf40cf1edee7f862195e82b156356c3b8c68fa63fe39fce4a594fd3625efe1a3a7e6269d69c1603c8978b7af11560ebcd24a83789
7
- data.tar.gz: 2d621a882ea57190b99eece3ea93bee59ea45e6e1571fab5685008271091279f545f0967f6242c23df60e3b474ec45a29324a38ec46910091a66c91237edcd43
6
+ metadata.gz: 9940dc8d3f77a4c7536b7f5f3c110c0cdd379ae296ffa348bca765aa464c25dbade1220ba3aaa886d0a157dca8ce22240cebd5c3c042074924a4217eeb55d356
7
+ data.tar.gz: 49eccbf92752be422046b168683d5e4098da61853af49ff7aa598505d9e1c744fb34df22ba95ce5fbaf6adedab7c183f6f21d40b506ee1bf70b920d5934b9dac
@@ -1,4 +1,9 @@
1
- 0.2.2.pre [☰](https://github.com/marcomd/Active_Leonardo/compare/v0.2.1...v0.2.2) March 12th, 2014
1
+ 0.2.3 [☰](https://github.com/marcomd/Active_Leonardo/compare/v0.2.2...v0.2.3) March 21th, 2014
2
+ ------------------------------
3
+ * Improved rake test to iterate several rails versions (currently 3.2.x and 4.0.x)
4
+ * Code improvements
5
+
6
+ 0.2.2 [☰](https://github.com/marcomd/Active_Leonardo/compare/v0.2.1...v0.2.2) March 12th, 2014
2
7
  ------------------------------
3
8
  * Added suite test
4
9
  * Travis integration
@@ -16,7 +16,8 @@ puts '*' * 40
16
16
 
17
17
  test_mode = nil
18
18
  ARGV.each{|arg| test_mode = true if arg == "test_mode"}
19
- puts "**** Starting in test mode! ****" if test_mode
19
+ app_path = ARGV[0]
20
+ puts "**** Starting app into #{app_path} in test mode! ****" if test_mode
20
21
 
21
22
  use_git = test_mode || yes?("Do you use git ?")
22
23
 
@@ -47,7 +48,11 @@ if use_git
47
48
  end
48
49
 
49
50
  gem "activeadmin", git: 'http://github.com/gregbell/active_admin.git'
50
- gem "active_leonardo"
51
+ if test_mode
52
+ gem "active_leonardo", :path => "../../."
53
+ else
54
+ gem "active_leonardo"
55
+ end
51
56
  gem "jquery-turbolinks"
52
57
  gem "bourbon"
53
58
 
@@ -38,347 +38,149 @@ module ActiveLeonardo
38
38
 
39
39
  module Leosca
40
40
 
41
- protected
42
-
43
- def attribute_to_hash(attribute)
44
- name = case attribute.type
45
- when :references, :belongs_to then ":#{attribute.name}_id"
46
- else ":#{attribute.name}"
41
+ module Seed
42
+ protected
43
+ def attribute_to_hash(attribute)
44
+ name = case attribute.type
45
+ when :references, :belongs_to then ":#{attribute.name}_id"
46
+ else ":#{attribute.name}"
47
+ end
48
+ value = case attribute.type
49
+ when :boolean then "true"
50
+ when :integer then "#"
51
+ when :float, :decimal then "#.46"
52
+ when :references, :belongs_to then "rand(#{attribute.name}_from..#{attribute.name}_to)"
53
+ when :date then "#{Time.now.strftime("%Y-%m-%d 00:00:00.000")}".inspect
54
+ when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
55
+ when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
56
+ else "#{attribute.name.titleize}\#".inspect
57
+ end
58
+ " #{name} => #{value}"
47
59
  end
48
- value = case attribute.type
49
- when :boolean then "true"
50
- when :integer then "#"
51
- when :float, :decimal then "#.46"
52
- when :references, :belongs_to then "rand(#{attribute.name}_from..#{attribute.name}_to)"
53
- when :date then "#{Time.now.strftime("%Y-%m-%d 00:00:00.000")}".inspect
54
- when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
55
- when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
56
- else "#{attribute.name.titleize}\#".inspect
60
+ def attribute_to_range(attribute)
61
+ case attribute.type
62
+ when :references, :belongs_to then "#{attribute.name}_from = #{attribute.name.classify}.first.id; #{attribute.name}_to = #{attribute.name.classify}.last.id#{CRLF}"
63
+ else ""
64
+ end
57
65
  end
58
- " #{name} => #{value}"
59
- end
60
- def attribute_to_range(attribute)
61
- case attribute.type
62
- when :references, :belongs_to then "#{attribute.name}_from = #{attribute.name.classify}.first.id; #{attribute.name}_to = #{attribute.name.classify}.last.id#{CRLF}"
63
- else ""
66
+ def attributes_accessible(attributes, class_name)
67
+ selected = attributes.select {|attribute| [:references, :belongs_to].include?(attribute.type) ? true : false }
68
+ if selected.empty?
69
+ ""
70
+ else
71
+ "#{class_name}.attr_accessible " <<
72
+ selected.map{|attribute| ":#{attribute.name}_id"}.join(', ') <<
73
+ CRLF
74
+ end
64
75
  end
65
76
  end
66
- def attribute_to_factories(attribute)
67
- spaces = 34
68
- space_association = " " * (spaces-11).abs
69
- space_sequence = " " * (spaces-attribute.name.size-11).abs
70
- space_other = " " * (spaces-attribute.name.size).abs
71
- name = case attribute.type
72
- when :references, :belongs_to then "#{singular_table_name[0..0]}.association#{space_association}"
73
- when :boolean, :datetime, :time, :timestamp
74
- then "#{singular_table_name[0..0]}.#{attribute.name}#{space_other}"
75
- else "#{singular_table_name[0..0]}.sequence(:#{attribute.name})#{space_sequence}"
76
- end
77
- value = case attribute.type
78
- when :boolean then "true"
79
- when :integer then "{|n| n }"
80
- when :float, :decimal then "{|n| n }"
81
- when :references, :belongs_to then ":#{attribute.name}"
82
- when :date then "{|n| n.month.ago }"
83
- when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
84
- when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
85
- else "{|n| \"#{attribute.name.titleize}\#{n}\" }"
77
+
78
+ module Rspec
79
+ protected
80
+ def attribute_to_factories(attribute)
81
+ spaces = 34
82
+ space_association = " " * (spaces-11).abs
83
+ space_sequence = " " * (spaces-attribute.name.size-11).abs
84
+ space_other = " " * (spaces-attribute.name.size).abs
85
+ name = case attribute.type
86
+ when :references, :belongs_to then "#{singular_table_name[0..0]}.association#{space_association}"
87
+ when :boolean, :datetime, :time, :timestamp
88
+ then "#{singular_table_name[0..0]}.#{attribute.name}#{space_other}"
89
+ else "#{singular_table_name[0..0]}.sequence(:#{attribute.name})#{space_sequence}"
90
+ end
91
+ value = case attribute.type
92
+ when :boolean then "true"
93
+ when :integer then "{|n| n }"
94
+ when :float, :decimal then "{|n| n }"
95
+ when :references, :belongs_to then ":#{attribute.name}"
96
+ when :date then "{|n| n.month.ago }"
97
+ when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
98
+ when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
99
+ else "{|n| \"#{attribute.name.titleize}\#{n}\" }"
100
+ end
101
+ " #{name}#{value}"
86
102
  end
87
- " #{name}#{value}"
88
- end
89
- def attribute_to_requests(attribute, object_id=nil)
90
- object_id ||= "#{singular_table_name}_#{attribute.name}"
91
- object_id = object_id.gsub('#', "\#{#{singular_table_name}.id}").gsub('name', attribute.name)
92
- case attribute.type
93
- when :boolean then "check \"#{object_id}\" if #{singular_table_name}.#{attribute.name}"
94
- when :references, :belongs_to then "select #{singular_table_name}.#{attribute.name}.name, :from => \"#{object_id}_id\""
95
- when :datetime, :time, :timestamp
96
- then ""
97
- when :date then "fill_in \"#{object_id}\", :with => #{singular_table_name}.#{attribute.name}.strftime('%d-%m-%Y')"
98
- else "fill_in \"#{object_id}\", :with => #{singular_table_name}.#{attribute.name}"
103
+ def attribute_to_requests(attribute, object_id=nil)
104
+ object_id ||= "#{singular_table_name}_#{attribute.name}"
105
+ object_id = object_id.gsub('#', "\#{#{singular_table_name}.id}").gsub('name', attribute.name)
106
+ case attribute.type
107
+ when :boolean then "check \"#{object_id}\" if #{singular_table_name}.#{attribute.name}"
108
+ when :references, :belongs_to then "select #{singular_table_name}.#{attribute.name}.name, :from => \"#{object_id}_id\""
109
+ when :datetime, :time, :timestamp
110
+ then ""
111
+ when :date then "fill_in \"#{object_id}\", :with => #{singular_table_name}.#{attribute.name}.strftime('%d-%m-%Y')"
112
+ else "fill_in \"#{object_id}\", :with => #{singular_table_name}.#{attribute.name}"
113
+ end
99
114
  end
100
- end
101
- #def attribute_to_erb(attribute, object)
102
- # case attribute.name
103
- # when "state" then "<span class=\"state generic <%= #{object}.state_name.to_s %>\"><%= t(\"states.generic.\#{#{object}.state_name.to_s}\") %></span><span style=\"display:block;\"></span>"
104
- # else
105
- # case attribute.type
106
- # when :boolean then "<%= #{object}.#{attribute.name} ? style_image_tag(\"ico_v.png\", :class => \"ico_true\") : style_image_tag(\"ico_x.png\", :class => \"ico_false\") %>"
107
- # when :references, :belongs_to then "<%= link_to(#{object}.#{attribute.name}.try(:name) || \"#\#{#{object}.#{attribute.name}.try(:id)}\", #{object}.#{attribute.name}, :remote => @remote) %>"
108
- # when :integer then "<%= number_with_delimiter #{object}.#{attribute.name} %>"
109
- # when :decimal then "<%= number_to_currency #{object}.#{attribute.name} %>"
110
- # when :float then "<%= number_with_precision #{object}.#{attribute.name} %>"
111
- # when :date then "<%= #{object}.#{attribute.name}.strftime('%d-%m-%Y') if #{object}.#{attribute.name} %>"
112
- # when :datetime then "<%= #{object}.#{attribute.name}.strftime('%d-%m-%Y %H:%M:%S') if #{object}.#{attribute.name} %>"
113
- # when :time, :timestamp then "<%= #{object}.#{attribute.name}.strftime('%H:%M:%S') if #{object}.#{attribute.name} %>"
114
- # else "<%= #{object}.#{attribute.name} %>"
115
- # end
116
- # end
117
- #end
118
- def get_attr_to_match(view=:list)
119
- #attributes.each do |attribute|
120
- # case attribute.type
121
- # when :string, :text then
122
- # return "have_content(#{singular_table_name}.#{attribute.name})",
123
- # "have_no_content(#{singular_table_name}.#{attribute.name})"
124
- # end
125
- #end
126
- attr = get_attr_to_check(view)
127
- return "have_content(#{singular_table_name}.#{attr})",
128
- "have_no_content(#{singular_table_name}.#{attr})" if attr
129
115
 
130
- #If there are not string or text attributes
131
- case view
132
- when :list
133
- return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')"
134
- when :show
135
- return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')"
116
+ def get_attr_to_match(view=:list)
117
+ #attributes.each do |attribute|
118
+ # case attribute.type
119
+ # when :string, :text then
120
+ # return "have_content(#{singular_table_name}.#{attribute.name})",
121
+ # "have_no_content(#{singular_table_name}.#{attribute.name})"
122
+ # end
123
+ #end
124
+ attr = get_attr_to_check(view)
125
+ return "have_content(#{singular_table_name}.#{attr})",
126
+ "have_no_content(#{singular_table_name}.#{attr})" if attr
127
+
128
+ #If there are not string or text attributes
129
+ case view
130
+ when :list
131
+ return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')"
132
+ when :show
133
+ return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')"
134
+ end
136
135
  end
137
- end
138
- def get_attr_to_check(view=:list)
139
- case view
140
- when :something
141
- else
142
- attributes.each{|a| case a.type when :string, :text then return a.name end}
143
- attributes.each{|a| case a.type when :references, :belongs_to, :datetime then nil else return a.name end}
136
+ def get_attr_to_check(view=:list)
137
+ case view
138
+ when :something
139
+ else
140
+ attributes.each{|a| case a.type when :string, :text then return a.name end}
141
+ attributes.each{|a| case a.type when :references, :belongs_to, :datetime then nil else return a.name end}
142
+ end
143
+ end
144
+ def fill_form_with_values(object_id=nil)
145
+ items = []
146
+ attributes.each{|a|items << " #{attribute_to_requests(a, object_id)}"}
147
+ items
144
148
  end
145
- end
146
- def fill_form_with_values(object_id=nil)
147
- items = []
148
- attributes.each{|a|items << " #{attribute_to_requests(a, object_id)}"}
149
- items
150
- end
151
- end
152
149
 
153
- #module Nested
154
- # protected
155
- #
156
- # #Add leonardo namespace to class_path
157
- # #def class_path
158
- # # super + base_namespaces
159
- # #end
160
- #
161
- # #product => products_path
162
- # #product under category => category_products_path(@category)
163
- # #product under brand/category => brand_category_products_path(@brand, @category)
164
- # def list_resources_path
165
- # "#{underscore_resource_path(:parent_singular_resource_plural)}_path(#{formatted_parent_resources("@")})"
166
- # end
167
- #
168
- # #product under category => category_products_path(category)
169
- # #product under brand/category => brand_category_products_path(@brand, category)
170
- # #TODO: figure out how to build links for a particular resource in the path
171
- # def list_resources_path_back
172
- # return unless nested?
173
- # "#{underscore_resource_path(:parent_singular_resource_plural)}_path(#{formatted_parent_resources("@").reverse.sub(/@/, "").reverse})"
174
- # end
175
- #
176
- # #product => "product"
177
- # #product under category => "[@category, product]"
178
- # #product under brand/category => "[@brand, @category, product]"
179
- # def destroy_resource_path(prefix_resource="")
180
- # formatted_resource_path("@", prefix_resource, "[]")
181
- # end
182
- #
183
- # #product => "product"
184
- # #product under category => "[@category, product]"
185
- # #product under brand/category => "[@brand, @category, product]"
186
- # def show_resource_path(prefix_resource="")
187
- # formatted_resource_path("@", prefix_resource, "[]")
188
- # end
189
- #
190
- # #product => "@product"
191
- # #product under category => "[@category, @product]"
192
- # #product under brand/category => "[@brand, @category, @product]"
193
- # def form_resource_path
194
- # formatted_resource_path("@", "@", "[]")
195
- # end
196
- #
197
- # #product => new_product_path
198
- # #product under category => new_category_product_path(@category)
199
- # #product under brand/category => new_brand_category_product_path(@brand, @category)
200
- # def new_resource_path
201
- # "new_#{underscore_resource_path}_path(#{formatted_parent_resources("@")})"
202
- # end
203
- #
204
- # #product => edit_product_path(@product)
205
- # #product under category => edit_category_product_path(@category, @product)
206
- # #product under brand/category => edit_brand_category_product_path(@brand, @category, @product)
207
- # def edit_resource_path(prefix_resource="")
208
- # "edit_#{underscore_resource_path}_path(#{formatted_resource_path("@", prefix_resource)})"
209
- # end
210
- #
211
- # #product under brand/category => "[brand, category, product]" or "[@brand, @category, @product]" or "@brand, @category, @product" or [product.brand, product.category, product]
212
- # def formatted_resource_path(prefix_parent="", prefix_resource="", delimiter="", resource=nil)
213
- # formatted_resource_base resource_path(prefix_parent, prefix_resource, resource), delimiter
214
- # end
215
- #
216
- # #product under brand/category => "[brand, category]" or "[@brand, @category]" or "@brand, @category" or product.brand, product.category
217
- # def formatted_parent_resources(prefix_parent="", delimiter="", resource=nil)
218
- # prefix_parent = "#{resource}." if resource
219
- # formatted_resource_base parent_resources(prefix_parent), delimiter
220
- # end
221
- #
222
- # def formatted_resource_base(resources, delimiter="")
223
- # str_resources = resources.join(', ')
224
- # resources.size > 1 ? "#{delimiter[0..0]}#{str_resources}#{delimiter[1..1]}" : str_resources
225
- # end
226
- #
227
- # #product under brand/category => "brand_category_product"
228
- # def underscore_resource_path(names=:all_singular)
229
- # case names
230
- # when :all_singular
231
- # resource_path.join('_')
232
- # #when :all_plural
233
- # #who needs?
234
- # when :parent_singular_resource_plural
235
- # resource_path.join('_').pluralize
236
- # else
237
- # "#{names.to_s}_not_supported"
238
- # end
239
- # end
240
- #
241
- # #product under brand/category => ["brand", "category", "product"] or ["@brand", "@category", "@product"]
242
- # def resource_path(prefix_parent="", prefix_resource="", resource=nil, prefix_namespace="")
243
- # if resource
244
- # prefix_parent = "#{resource}."
245
- # else
246
- # resource = singular_table_name
247
- # end
248
- #
249
- # prefix_namespace = ":" if prefix_namespace.empty? && prefix_parent.size>0
250
- #
251
- # if nested?
252
- # (base_namespaces(prefix_namespace) + parent_resources(prefix_parent)) << "#{prefix_resource}#{resource}"
253
- # else
254
- # base_namespaces(prefix_namespace) << "#{prefix_resource}#{resource}"
255
- # end
256
- # end
257
- #
258
- # #product under brand/category => "categories"
259
- # def plural_last_parent
260
- # plural_parent_resources.last
261
- # end
262
- #
263
- # #product under brand/category => ["brands", "categories"] or ["@brands", "@categories"]
264
- # def plural_parent_resources(prefix_parent="")
265
- # base_parent_resources.map{|m| "#{prefix_parent}#{m.pluralize}"}
266
- # end
267
- #
268
- # #product under brand/category => ["brand", "category"] or ["@brand", "@category"]
269
- # def parent_resources(prefix_parent="")
270
- # base_parent_resources.map{|m| "#{prefix_parent}#{m}"}
271
- # end
272
- #
273
- # #product under brand/category => "category"
274
- # def last_parent
275
- # base_parent_resources.last
276
- # end
277
- #
278
- # #product under brand/category => ["brand", "category"]
279
- # def base_parent_resources
280
- # return [] unless options[:under].present?
281
- # options[:under].split('/').map{|m| m.underscore}
282
- # end
283
- #
284
- # def nested?
285
- # options[:under].present?
286
- # end
287
- #
288
- # ### NAMESPACE ###
289
- # def leospaced?
290
- # options[:leospace].present?
291
- # end
292
- #
293
- # def base_namespaces(prefix="")
294
- # return [] unless options[:leospace].present?
295
- # options[:leospace].split('/').map{|m| "#{prefix}#{m.underscore}"}
296
- # end
297
- #
298
- # def last_namespace(prefix="")
299
- # base_namespaces(prefix).last
300
- # end
301
- #
302
- # def formatted_namespace_path(separator='/')
303
- # return "" unless leospaced?
304
- # "#{base_namespaces.join(separator)}#{separator}"
305
- # end
306
- #
307
- # module Test
308
- # protected
309
- # #Add parent(s) param(s) to request
310
- # #get :index for a product under category => get :index, :category_id => product.category_id.to_s
311
- # def nested_params_http_request(value=nil)
312
- # return unless nested?
313
- # ", " << base_parent_resources.map{|m| ":#{m}_id => #{value ? value.to_s.inspect : "#{file_name}.#{m}_id.to_s"}"}.join(', ')
314
- # end
315
- #
316
- # #Create new parent(s) and add it to request
317
- # #get :index for a product under category => get :index, :category_id => Factory(:category).id.to_s
318
- # def nested_params_http_request_new_parent
319
- # return unless nested?
320
- # ", " << base_parent_resources.map{|m| ":#{m}_id => Factory(:#{m}).id.to_s"}.join(', ')
321
- # end
322
- #
323
- # #product => products_path
324
- # #product under category => category_products_path(product.category)
325
- # #product under brand/category => brand_category_products_path(product.brand, product.category)
326
- # def list_resources_path_test(resource=nil, prefix_parent=nil)
327
- # unless prefix_parent
328
- # resource ||= singular_table_name
329
- # prefix_parent = "#{resource}."
330
- # end
331
- # "#{underscore_resource_path(:parent_singular_resource_plural)}_path(#{formatted_parent_resources(prefix_parent, "", resource)})"
332
- # end
333
- #
334
- # #product => "product"
335
- # #product under category => "[category, product]" or "[product.category, product]"
336
- # #product under brand/category => "[brand, category, product]" or "[product.brand, product.category, product]"
337
- # def show_resource_path_test(resource=nil, prefix_parent=nil, prefix_resource="")
338
- # resource ||= singular_table_name
339
- # prefix_parent = prefix_parent || "#{resource}."
340
- # formatted_resource_path(prefix_parent, prefix_resource, "[]", resource)
341
- # end
342
- #
343
- # #product => new_product_path
344
- # #product under category => new_category_product_path(product.category)
345
- # #product under brand/category => new_brand_category_product_path(product.brand, product.category)
346
- # def new_resource_path_test(resource=nil, prefix_parent=nil)
347
- # resource ||= singular_table_name
348
- # prefix_parent = prefix_parent || "#{resource}."
349
- # "new_#{underscore_resource_path}_path(#{formatted_parent_resources(prefix_parent, "",resource)})"
350
- # end
351
- # end
352
- #end
353
- module Test
354
- protected
355
- def get_activespace
356
- activespace ||= options[:activespace]
357
- "#{activespace}_" if activespace
358
150
  end
359
151
 
360
- #product => activespace_products_path
361
- def list_resources_path_test(resource=nil)
362
- resource ||= plural_table_name
363
- "#{get_activespace}#{resource}_path"
364
- end
152
+ module Locale
153
+ protected
154
+ def attributes_to_list(attributes, file_name)
155
+ content = "#{CRLF} #{file_name}:#{CRLF}"
156
+ attributes.each do |attribute|
157
+ content << " #{attribute.name}: \"#{attribute.name.humanize}\"#{CRLF}"
158
+ end
159
+ content
160
+ end
365
161
 
366
- #product => "[:activespace, product]"
367
- def show_resource_path_test(resource=nil)
368
- resource ||= singular_table_name
369
- "[:#{options[:activespace]}, #{resource}]"
370
- end
162
+ def attributes_to_hints(attributes, file_name)
163
+ content = "#{CRLF} #{file_name}:#{CRLF}"
164
+ attributes.each do |attribute|
165
+ attr_name = attribute.name.humanize
166
+ case attribute.type
167
+ when :integer, :decimal, :float
168
+ content << " #{attribute.name}: \"Fill the #{attr_name} with a#{"n" if attribute.type == :integer} #{attribute.type.to_s} number\"#{CRLF}"
169
+ when :boolean
170
+ content << " #{attribute.name}: \"Select if this #{file_name} should be #{attr_name} or not\"#{CRLF}"
171
+ when :string, :text
172
+ content << " #{attribute.name}: \"Choose a good #{attr_name} for this #{file_name}\"#{CRLF}"
173
+ when :date, :datetime, :time, :timestamp
174
+ content << " #{attribute.name}: \"Choose a #{attribute.type.to_s} for #{attr_name}\"#{CRLF}"
175
+ else
176
+ content << " #{attribute.name}: \"Choose a #{attr_name}\"#{CRLF}"
177
+ end
178
+ end
179
+ content
180
+ end
371
181
 
372
- #product => new_activespace_product_path
373
- def new_resource_path_test(resource=nil)
374
- resource ||= singular_table_name
375
- "new_#{get_activespace}#{resource}_path"
376
182
  end
377
183
 
378
- #product => edit_activespace_product_path
379
- def edit_resource_path_test(resource=nil)
380
- resource ||= singular_table_name
381
- "edit_#{get_activespace}#{resource}_path(#{resource})"
382
- end
383
184
  end
185
+
384
186
  end
@@ -9,6 +9,9 @@ module Rails
9
9
  class LeoscaControllerGenerator < ::Rails::Generators::ScaffoldControllerGenerator
10
10
  include ::ActiveLeonardo::Base
11
11
  include ::ActiveLeonardo::Leosca
12
+ include ::ActiveLeonardo::Leosca::Locale
13
+ include ::ActiveLeonardo::Leosca::Rspec
14
+ include ::ActiveLeonardo::Leosca::Seed
12
15
 
13
16
  source_root File.expand_path('../templates', __FILE__)
14
17
  argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
@@ -38,16 +41,7 @@ module Rails
38
41
 
39
42
  #Fields name
40
43
  inject_into_file file, :after => "#Attributes zone - do not remove" do
41
- content = "#{CRLF} #{file_name}:#{CRLF}"
42
- attributes.each do |attribute|
43
- content << " #{attribute.name}: \"#{attribute.name.humanize}\"#{CRLF}"
44
- end
45
- #content << " op_new: \"New #{singular_table_name}\"#{CRLF}"
46
- #content << " op_edit: \"Editing #{singular_table_name}\"#{CRLF}"
47
- #content << " op_edit_multiple: \"Editing #{plural_table_name}\"#{CRLF}"
48
- #content << " op_copy: \"Creating new #{plural_table_name}\"#{CRLF}"
49
- #content << " op_index: \"Listing #{plural_table_name}\"#{CRLF}"
50
- content
44
+ attributes_to_list(attributes, file_name)
51
45
  end
52
46
 
53
47
  #Model name
@@ -61,23 +55,7 @@ module Rails
61
55
 
62
56
  #Formtastic
63
57
  inject_into_file file, :after => " hints:" do
64
- content = "#{CRLF} #{file_name}:#{CRLF}"
65
- attributes.each do |attribute|
66
- attr_name = attribute.name.humanize
67
- case attribute.type
68
- when :integer, :decimal, :float
69
- content << " #{attribute.name}: \"Fill the #{attr_name} with a#{"n" if attribute.type == :integer} #{attribute.type.to_s} number\"#{CRLF}"
70
- when :boolean
71
- content << " #{attribute.name}: \"Select if this #{file_name} should be #{attr_name} or not\"#{CRLF}"
72
- when :string, :text
73
- content << " #{attribute.name}: \"Choose a good #{attr_name} for this #{file_name}\"#{CRLF}"
74
- when :date, :datetime, :time, :timestamp
75
- content << " #{attribute.name}: \"Choose a #{attribute.type.to_s} for #{attr_name}\"#{CRLF}"
76
- else
77
- content << " #{attribute.name}: \"Choose a #{attr_name}\"#{CRLF}"
78
- end
79
- end
80
- content
58
+ attributes_to_hints(attributes, file_name)
81
59
  end
82
60
 
83
61
  end
@@ -107,15 +85,14 @@ module Rails
107
85
  file = "db/seeds.rb"
108
86
  append_file file do
109
87
  items = []
110
- attributes.each do |attribute|
111
- items << attribute_to_hash(attribute)
112
- end
88
+ attributes.each{|attribute| items << attribute_to_hash(attribute)}
113
89
  row = "{ #{items.join(', ')} }"
114
90
 
115
91
  #TODO: to have different values for every row
116
92
  content = "#{CRLF}### Created by leosca controller generator ### #{CRLF}"
117
- attributes.each do |attribute|
118
- content << attribute_to_range(attribute)
93
+ attributes.each{|attribute| content << attribute_to_range(attribute)}
94
+ if /^3./ === Rails.version
95
+ content << attributes_accessible(attributes, class_name)
119
96
  end
120
97
  content << "#{class_name}.create([#{CRLF}"
121
98
  options[:seeds_elements].to_i.times do |n|
@@ -132,16 +109,24 @@ module Rails
132
109
  invoke "active_admin:resource", [singular_table_name]
133
110
  file = "app/admin/#{singular_table_name}.rb"
134
111
 
112
+ if /^4./ === Rails.version
113
+ inject_into_file file, :after => "ActiveAdmin.register #{class_name} do" do
114
+ <<-FILE.gsub(/^ /, '')
115
+
116
+ permit_params do
117
+ permitted = [#{attributes.map{|attr| ":#{attr.name}"}.join(', ')}]
118
+ permitted
119
+ end
120
+
121
+ FILE
122
+ end
123
+ end
124
+
135
125
  inject_into_file file, :after => "ActiveAdmin.register #{class_name} do" do
136
126
  <<-FILE.gsub(/^ /, '')
137
127
 
138
128
  menu :if => proc{ can?(:read, #{class_name}) }
139
129
 
140
- permit_params do
141
- permitted = [#{attributes.map{|attr| ":#{attr.name}"}.join(', ')}]
142
- permitted
143
- end
144
-
145
130
  controller do
146
131
  load_resource :except => :index
147
132
  end
@@ -149,6 +134,7 @@ module Rails
149
134
 
150
135
  FILE
151
136
  end if authorization? && File.exists?(file)
137
+
152
138
  end
153
139
 
154
140
  def update_specs
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_leonardo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Mastrodonato, Marco Longhitano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-14 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activeadmin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.3
13
41
  description: This generator help you to create new Rails applications to combine with
14
42
  active admin gem. It generates application structure to easily get the internationalization
15
43
  and authorization.