active_leonardo 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGELOG +2 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +157 -0
  4. data/active_template.rb +88 -0
  5. data/lib/generators/active_leonardo.rb +334 -0
  6. data/lib/generators/erb/leosca/leosca_generator.rb +122 -0
  7. data/lib/generators/leolay/USAGE +21 -0
  8. data/lib/generators/leolay/install_generator.rb +16 -0
  9. data/lib/generators/leolay/leolay_generator.rb +368 -0
  10. data/lib/generators/leolay/templates/app/admin/users.rb +63 -0
  11. data/lib/generators/leolay/templates/app/assets/javascripts/custom.js +10 -0
  12. data/lib/generators/leolay/templates/app/helpers/layout_helper.rb +27 -0
  13. data/lib/generators/leolay/templates/app/views/admin/users/_form.html.erb +21 -0
  14. data/lib/generators/leolay/templates/config.rb +11 -0
  15. data/lib/generators/leolay/templates/config/locales/en.yml +271 -0
  16. data/lib/generators/leolay/templates/config/locales/it.yml +298 -0
  17. data/lib/generators/leolay/templates/lib/development_mail_interceptor.rb +6 -0
  18. data/lib/generators/leolay/templates/lib/upd_activeadmin.rb +65 -0
  19. data/lib/generators/leolay/templates/lib/upd_array.rb +25 -0
  20. data/lib/generators/leolay/templates/styles/active/images/logo.png +0 -0
  21. data/lib/generators/leolay/templates/styles/active/images/style/Thumbs.db +0 -0
  22. data/lib/generators/leolay/templates/styles/active/images/style/ico_v.png +0 -0
  23. data/lib/generators/leolay/templates/styles/active/images/style/ico_x.png +0 -0
  24. data/lib/generators/leolay/templates/styles/active/stylesheets/app/_enviroment.css.scss +25 -0
  25. data/lib/generators/leolay/templates/styles/active/stylesheets/app/custom_active_admin.css.scss +23 -0
  26. data/lib/generators/leolay/templates/styles/active/stylesheets/app/stylesheet.css.scss +51 -0
  27. data/lib/generators/leolay/templates/styles/active/views/layout/_message.html.erb +3 -0
  28. data/lib/generators/leolay/templates/styles/active/views/layout/_session.html.erb +10 -0
  29. data/lib/generators/leolay/templates/styles/active/views/layout/application.html.erb +45 -0
  30. data/lib/generators/leosca/USAGE +23 -0
  31. data/lib/generators/leosca/install_generator.rb +16 -0
  32. data/lib/generators/rails/leosca/USAGE +40 -0
  33. data/lib/generators/rails/leosca/leosca_generator.rb +56 -0
  34. data/lib/generators/rails/leosca/templates/leosca.css +56 -0
  35. data/lib/generators/rails/leosca_controller/USAGE +23 -0
  36. data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +197 -0
  37. data/lib/generators/rails/leosca_controller/templates/controller.rb +3 -0
  38. metadata +117 -0
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ 0.0.1 (May 23th, 2012) Marco Mastrodonato
2
+ * First release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Marco Mastrodonato
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,157 @@
1
+ = Leolay Generators
2
+
3
+ A layout and customized scaffold generator for Rails 3 to combine with active admin gem
4
+ It generates the layout, the style, the internationalization and it helps you to startup active_admin gems
5
+
6
+
7
+ == Install
8
+
9
+ gem install active_leonardo
10
+
11
+ or
12
+
13
+ rails new ActiveLeo -m http://dl.dropbox.com/u/52600966/active_template.rb
14
+
15
+
16
+ == Usage
17
+
18
+ Once you install the gem, the generators will be available to all Rails applications on your system.
19
+
20
+ To run the generator, go to your rails project directory and call it using rails generate or destroy command:
21
+ rails generate leolay or rails destroy leolay
22
+ rails generate leosca or rails destroy leosca
23
+
24
+ PS: leosca destroy do not remove variables parts like time values inserted into feed
25
+
26
+ PPS: You can run it more times and right like scaffold, it's smart and won't generate tons of identical code (thanks thor)
27
+
28
+ === Step by step
29
+
30
+ 1. Firstly, create layout and initialize your project:
31
+ rails new ActiveLeo -m http://dl.dropbox.com/u/52600966/active_template.rb
32
+ (You can also find a template into gem root folder)
33
+
34
+ Answer y to all gems you need.
35
+ After the questions will start generations.
36
+ There will be a conflict on locales/en.yml which you must force if it is the first generation.
37
+
38
+ Will be:
39
+ * Created a default layout like active admin
40
+ * Created i18n files
41
+ * Created user management on active admin
42
+ * Customized application.rb to exclude javascript and stylesheet for every resource you will create
43
+
44
+
45
+
46
+ 2. You will get an application ready to work:
47
+ run rails s and try it on http://localhost:3000
48
+
49
+ if you get this message:
50
+ _undefined local variable or method `new_user_registration_path'_
51
+ **be sure user model have :registerable devise's module** otherwise add it or you have to remove registerable code from app\views\application\_session.html.erb
52
+ you also may have to restart server: Ctrl+C and rails s once again
53
+
54
+ now go into admin section:
55
+ run rails s and try it on http://localhost:3000/admin
56
+
57
+ You can login as three different profiles loaded with a previous db:seed:
58
+
59
+ email: admin@activeleo.com, password: abcd1234
60
+ [this profile can do everything]
61
+ or
62
+ email: manager@activeleo.com, password: abcd1234
63
+ [can read, create and update]
64
+ or
65
+ email: user@activeleo.com, password: abcd1234
66
+ [can read, create, update and destroy]
67
+
68
+
69
+
70
+ 3. Create your resource:
71
+ rails g leosca product name:string description:text active:boolean items:integer price:decimal
72
+
73
+ This will act as a normal scaffold and has more new features:
74
+ * will be invoked new leosca_controller which is a customized scaffold_controller
75
+ * attributes will be insert into i18n files for a quick translation
76
+ * seeds will be created for you to populate new table
77
+ * invoke active admin generator to add the new resource with a custom configuration to work with cancan
78
+
79
+
80
+
81
+ 4. Apply to db as always you do:
82
+ rake db:migrate
83
+ rake db:seed
84
+
85
+
86
+
87
+ That's all!
88
+ The new application is ready to be customized to suit your needs:
89
+ * start to develop user front end
90
+ * take advantage of active admin and its dsl to quickly setup administration section
91
+
92
+ If you get this message:
93
+ __Can't mass-assign protected attributes: foo_id, bar_id__
94
+ just add it to attr_accessible inside your model
95
+
96
+
97
+
98
+ **If you login with admin profile you can also manage users**, you only have to add :roles to attr_accessible inside user's model
99
+
100
+
101
+
102
+ You could also customize leonardo templates: both views and controller.
103
+ To copy under your project folder run:
104
+ rails g leosca:install
105
+
106
+ Then go to lib\generators\erb to edit erb views like you would do with original scaffold.
107
+ Go to lib\generators\rails if you want to customize more.
108
+
109
+
110
+ For more information about usage:
111
+
112
+ rails g leolay --help
113
+
114
+ rails g leosca --help
115
+
116
+
117
+ === Example:
118
+
119
+ leolay:
120
+
121
+ rails generate leolay
122
+ rails generate leolay --skip-authentication --skip-authorization
123
+
124
+ leosca:
125
+
126
+ rails generate leosca product name:string
127
+ rails generate leosca product name:string --skip-seeds
128
+ rails generate leosca product name:string --seeds=60 => if you need more records
129
+
130
+ if you made a mistake and want to start from scratch just replace generate with destroy to remove all files and inserted code
131
+
132
+ PS: Of course, these options are in addition to those provided by the original scaffold
133
+
134
+
135
+ === Available layout
136
+
137
+ * active [default]
138
+
139
+
140
+ == Tutorial
141
+
142
+ That what do you think is??? :)
143
+
144
+
145
+
146
+ == Found a bug?
147
+
148
+ If you are having a problem please submit an issue at m.mastrodonato@gmail.com
149
+
150
+
151
+ == Rails 2 and Rails 3.0.x
152
+
153
+ This Generators does not work with versions earlier 3.1
154
+
155
+
156
+
157
+
@@ -0,0 +1,88 @@
1
+ #########################################################
2
+ # 2012 Marco Mastrodonato(c)
3
+ # This is a Rails 3.1+ template to use with activeleonardo gem
4
+ # https://rubygems.org/gems/Activeleonardo
5
+ #
6
+ # USAGE: rails new yourappname -m active_template.rb
7
+ #
8
+ # -------------------------------------------------------
9
+ #
10
+ #########################################################
11
+
12
+ puts '*' * 40
13
+ puts "* Processing template..."
14
+ puts '*' * 40
15
+
16
+ use_git = yes?("Do you use git ?")
17
+ if use_git
18
+ git :init
19
+ file ".gitignore", <<-EOS.gsub(/^ /, '')
20
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
21
+ #
22
+ # If you find yourself ignoring temporary files generated by your text editor
23
+ # or operating system, you probably want to add a global ignore instead:
24
+ # git config --global core.excludesfile ~/.gitignore_global
25
+
26
+ # Ignore bundler config
27
+ /.bundle
28
+ # Ignore the default SQLite database.
29
+ /db/*.sqlite3
30
+ # Ignore all logfiles and tempfiles.
31
+ /log/*.log
32
+ /tmp
33
+ /nbproject
34
+ /.idea
35
+ lib/tasks/files/*
36
+ /*.cmd
37
+ /*.dat
38
+ EOS
39
+ end
40
+
41
+ gem "activeadmin"
42
+ gem "meta_search"
43
+ gem "active_leonardo"
44
+
45
+ gem 'state_machine' if yes?("Do you have to handle states ?")
46
+
47
+ authorization = yes?("Authorization ?")
48
+ gem 'cancan' if authorization
49
+
50
+ authentication = yes?("Authentication ?")
51
+
52
+ #home = yes?("Generate controller home ? (raccomanded)")
53
+ home = true
54
+
55
+ if yes?("Bundle install ?")
56
+ dir = ask(" Insert folder name to install locally: [blank=default gems path]")
57
+ run "bundle install #{"--path=#{dir}" unless dir.empty?}"
58
+ end
59
+
60
+ generate "active_admin:install #{authentication ? "User" : "--skip-users"}"
61
+
62
+ if authorization
63
+ generate "cancan:ability"
64
+ generate "migration", "AddRolesMaskToUsers", "roles_mask:integer"
65
+ end
66
+
67
+ generate "leolay",
68
+ "active", #specify theme
69
+ (authorization ? "" : "--skip-authorization"),
70
+ (authentication ? "" : "--skip-authentication"),
71
+
72
+
73
+ if home
74
+ generate "controller", "home", "index"
75
+ route "root :to => 'home#index'"
76
+ end
77
+
78
+ File.unlink "public/index.html"
79
+
80
+ rake "db:create:all"
81
+ rake "db:migrate"
82
+ rake "db:seed"
83
+
84
+ #rake "gems:unpack" if yes?("Unpack to vendor/gems ?")
85
+
86
+ git :add => ".", :commit => "-m 'initial commit'" if use_git
87
+
88
+ puts "ENJOY!"
@@ -0,0 +1,334 @@
1
+ module ActiveLeonardo
2
+ module Base
3
+ protected
4
+ def authorization?
5
+ File.exists? "app/models/ability.rb"
6
+ end
7
+ def authentication?
8
+ return true if File.exists? "app/models/user.rb"
9
+ File.exists? "config/initializers/devise.rb"
10
+ end
11
+ def activeadmin?
12
+ File.exists? "config/initializers/active_admin.rb"
13
+ end
14
+ #def formtastic?
15
+ # return false unless options.formtastic?
16
+ # File.exists? "config/initializers/formtastic.rb"
17
+ #end
18
+ #def jquery_ui?
19
+ # File.exists? "vendor/assets/javascripts/jquery-ui"
20
+ #end
21
+ #def pagination?
22
+ # File.exists? "config/initializers/kaminari_config.rb"
23
+ #end
24
+ end
25
+
26
+ module Leosca
27
+
28
+ protected
29
+
30
+ def attribute_to_hash(attribute)
31
+ name = case attribute.type
32
+ when :references, :belongs_to then ":#{attribute.name}_id"
33
+ else ":#{attribute.name}"
34
+ end
35
+ value = case attribute.type
36
+ when :boolean then "true"
37
+ when :integer then "#"
38
+ when :float, :decimal then "#.46"
39
+ when :references, :belongs_to then "#"
40
+ when :date then "#{Time.now.strftime("%Y-%m-%d 00:00:00.000")}".inspect
41
+ when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
42
+ when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
43
+ else "#{attribute.name.titleize}\#".inspect
44
+ end
45
+ " #{name} => #{value}"
46
+ end
47
+ #def attribute_to_factories(attribute)
48
+ # spaces = 34
49
+ # space_association = " " * (spaces-11).abs
50
+ # space_sequence = " " * (spaces-attribute.name.size-11).abs
51
+ # space_other = " " * (spaces-attribute.name.size).abs
52
+ # name = case attribute.type
53
+ # when :references, :belongs_to then "#{singular_table_name[0..0]}.association#{space_association}"
54
+ # when :boolean, :datetime, :time, :timestamp
55
+ # then "#{singular_table_name[0..0]}.#{attribute.name}#{space_other}"
56
+ # else "#{singular_table_name[0..0]}.sequence(:#{attribute.name})#{space_sequence}"
57
+ # end
58
+ # value = case attribute.type
59
+ # when :boolean then "true"
60
+ # when :integer then "{|n| n }"
61
+ # when :float, :decimal then "{|n| n }"
62
+ # when :references, :belongs_to then ":#{attribute.name}"
63
+ # when :date then "{|n| n.month.ago }"
64
+ # when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
65
+ # when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
66
+ # else "{|n| \"#{attribute.name.titleize}\#{n}\" }"
67
+ # end
68
+ # " #{name}#{value}"
69
+ #end
70
+ #def attribute_to_requests(attribute, object_id=nil)
71
+ # object_id ||= "#{singular_table_name}_#{attribute.name}"
72
+ # object_id = object_id.gsub('#', "\#{#{singular_table_name}.id}").gsub('name', attribute.name)
73
+ # case attribute.type
74
+ # when :boolean then "check \"#{object_id}\" if #{singular_table_name}.#{attribute.name}"
75
+ # when :references, :belongs_to then "select #{singular_table_name}.#{attribute.name}.name, :from => \"#{object_id}_id\""
76
+ # when :datetime, :time, :timestamp
77
+ # then ""
78
+ # when :date then "fill_in \"#{object_id}\", :with => #{singular_table_name}.#{attribute.name}.strftime('%d-%m-%Y')"
79
+ # else "fill_in \"#{object_id}\", :with => #{singular_table_name}.#{attribute.name}"
80
+ # end
81
+ #end
82
+ #def attribute_to_erb(attribute, object)
83
+ # case attribute.name
84
+ # 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>"
85
+ # else
86
+ # case attribute.type
87
+ # when :boolean then "<%= #{object}.#{attribute.name} ? style_image_tag(\"ico_v.png\", :class => \"ico_true\") : style_image_tag(\"ico_x.png\", :class => \"ico_false\") %>"
88
+ # when :references, :belongs_to then "<%= link_to(#{object}.#{attribute.name}.try(:name) || \"#\#{#{object}.#{attribute.name}.try(:id)}\", #{object}.#{attribute.name}, :remote => @remote) %>"
89
+ # when :integer then "<%= number_with_delimiter #{object}.#{attribute.name} %>"
90
+ # when :decimal then "<%= number_to_currency #{object}.#{attribute.name} %>"
91
+ # when :float then "<%= number_with_precision #{object}.#{attribute.name} %>"
92
+ # when :date then "<%= #{object}.#{attribute.name}.strftime('%d-%m-%Y') if #{object}.#{attribute.name} %>"
93
+ # when :datetime then "<%= #{object}.#{attribute.name}.strftime('%d-%m-%Y %H:%M:%S') if #{object}.#{attribute.name} %>"
94
+ # when :time, :timestamp then "<%= #{object}.#{attribute.name}.strftime('%H:%M:%S') if #{object}.#{attribute.name} %>"
95
+ # else "<%= #{object}.#{attribute.name} %>"
96
+ # end
97
+ # end
98
+ #end
99
+ #def get_attr_to_match(view=:list)
100
+ # #attributes.each do |attribute|
101
+ # # case attribute.type
102
+ # # when :string, :text then
103
+ # # return "have_content(#{singular_table_name}.#{attribute.name})",
104
+ # # "have_no_content(#{singular_table_name}.#{attribute.name})"
105
+ # # end
106
+ # #end
107
+ # attr = get_attr_to_check(view)
108
+ # return "have_content(#{singular_table_name}.#{attr})",
109
+ # "have_no_content(#{singular_table_name}.#{attr})" if attr
110
+ #
111
+ # #If there are not string or text attributes
112
+ # case view
113
+ # when :list
114
+ # return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')"
115
+ # when :show
116
+ # return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')"
117
+ # end
118
+ #end
119
+ #def get_attr_to_check(view=:list)
120
+ # case view
121
+ # when :something
122
+ # else
123
+ # attributes.each{|a| case a.type when :string, :text then return a.name end}
124
+ # attributes.each{|a| case a.type when :references, :belongs_to, :datetime then nil else return a.name end}
125
+ # end
126
+ #end
127
+ #def fill_form_with_values(object_id=nil)
128
+ # items = []
129
+ # attributes.each{|a|items << " #{attribute_to_requests(a, object_id)}"}
130
+ # items
131
+ #end
132
+ end
133
+
134
+ #module Nested
135
+ # protected
136
+ #
137
+ # #Add leonardo namespace to class_path
138
+ # #def class_path
139
+ # # super + base_namespaces
140
+ # #end
141
+ #
142
+ # #product => products_path
143
+ # #product under category => category_products_path(@category)
144
+ # #product under brand/category => brand_category_products_path(@brand, @category)
145
+ # def list_resources_path
146
+ # "#{underscore_resource_path(:parent_singular_resource_plural)}_path(#{formatted_parent_resources("@")})"
147
+ # end
148
+ #
149
+ # #product under category => category_products_path(category)
150
+ # #product under brand/category => brand_category_products_path(@brand, category)
151
+ # #TODO: figure out how to build links for a particular resource in the path
152
+ # def list_resources_path_back
153
+ # return unless nested?
154
+ # "#{underscore_resource_path(:parent_singular_resource_plural)}_path(#{formatted_parent_resources("@").reverse.sub(/@/, "").reverse})"
155
+ # end
156
+ #
157
+ # #product => "product"
158
+ # #product under category => "[@category, product]"
159
+ # #product under brand/category => "[@brand, @category, product]"
160
+ # def destroy_resource_path(prefix_resource="")
161
+ # formatted_resource_path("@", prefix_resource, "[]")
162
+ # end
163
+ #
164
+ # #product => "product"
165
+ # #product under category => "[@category, product]"
166
+ # #product under brand/category => "[@brand, @category, product]"
167
+ # def show_resource_path(prefix_resource="")
168
+ # formatted_resource_path("@", prefix_resource, "[]")
169
+ # end
170
+ #
171
+ # #product => "@product"
172
+ # #product under category => "[@category, @product]"
173
+ # #product under brand/category => "[@brand, @category, @product]"
174
+ # def form_resource_path
175
+ # formatted_resource_path("@", "@", "[]")
176
+ # end
177
+ #
178
+ # #product => new_product_path
179
+ # #product under category => new_category_product_path(@category)
180
+ # #product under brand/category => new_brand_category_product_path(@brand, @category)
181
+ # def new_resource_path
182
+ # "new_#{underscore_resource_path}_path(#{formatted_parent_resources("@")})"
183
+ # end
184
+ #
185
+ # #product => edit_product_path(@product)
186
+ # #product under category => edit_category_product_path(@category, @product)
187
+ # #product under brand/category => edit_brand_category_product_path(@brand, @category, @product)
188
+ # def edit_resource_path(prefix_resource="")
189
+ # "edit_#{underscore_resource_path}_path(#{formatted_resource_path("@", prefix_resource)})"
190
+ # end
191
+ #
192
+ # #product under brand/category => "[brand, category, product]" or "[@brand, @category, @product]" or "@brand, @category, @product" or [product.brand, product.category, product]
193
+ # def formatted_resource_path(prefix_parent="", prefix_resource="", delimiter="", resource=nil)
194
+ # formatted_resource_base resource_path(prefix_parent, prefix_resource, resource), delimiter
195
+ # end
196
+ #
197
+ # #product under brand/category => "[brand, category]" or "[@brand, @category]" or "@brand, @category" or product.brand, product.category
198
+ # def formatted_parent_resources(prefix_parent="", delimiter="", resource=nil)
199
+ # prefix_parent = "#{resource}." if resource
200
+ # formatted_resource_base parent_resources(prefix_parent), delimiter
201
+ # end
202
+ #
203
+ # def formatted_resource_base(resources, delimiter="")
204
+ # str_resources = resources.join(', ')
205
+ # resources.size > 1 ? "#{delimiter[0..0]}#{str_resources}#{delimiter[1..1]}" : str_resources
206
+ # end
207
+ #
208
+ # #product under brand/category => "brand_category_product"
209
+ # def underscore_resource_path(names=:all_singular)
210
+ # case names
211
+ # when :all_singular
212
+ # resource_path.join('_')
213
+ # #when :all_plural
214
+ # #who needs?
215
+ # when :parent_singular_resource_plural
216
+ # resource_path.join('_').pluralize
217
+ # else
218
+ # "#{names.to_s}_not_supported"
219
+ # end
220
+ # end
221
+ #
222
+ # #product under brand/category => ["brand", "category", "product"] or ["@brand", "@category", "@product"]
223
+ # def resource_path(prefix_parent="", prefix_resource="", resource=nil, prefix_namespace="")
224
+ # if resource
225
+ # prefix_parent = "#{resource}."
226
+ # else
227
+ # resource = singular_table_name
228
+ # end
229
+ #
230
+ # prefix_namespace = ":" if prefix_namespace.empty? && prefix_parent.size>0
231
+ #
232
+ # if nested?
233
+ # (base_namespaces(prefix_namespace) + parent_resources(prefix_parent)) << "#{prefix_resource}#{resource}"
234
+ # else
235
+ # base_namespaces(prefix_namespace) << "#{prefix_resource}#{resource}"
236
+ # end
237
+ # end
238
+ #
239
+ # #product under brand/category => "categories"
240
+ # def plural_last_parent
241
+ # plural_parent_resources.last
242
+ # end
243
+ #
244
+ # #product under brand/category => ["brands", "categories"] or ["@brands", "@categories"]
245
+ # def plural_parent_resources(prefix_parent="")
246
+ # base_parent_resources.map{|m| "#{prefix_parent}#{m.pluralize}"}
247
+ # end
248
+ #
249
+ # #product under brand/category => ["brand", "category"] or ["@brand", "@category"]
250
+ # def parent_resources(prefix_parent="")
251
+ # base_parent_resources.map{|m| "#{prefix_parent}#{m}"}
252
+ # end
253
+ #
254
+ # #product under brand/category => "category"
255
+ # def last_parent
256
+ # base_parent_resources.last
257
+ # end
258
+ #
259
+ # #product under brand/category => ["brand", "category"]
260
+ # def base_parent_resources
261
+ # return [] unless options[:under].present?
262
+ # options[:under].split('/').map{|m| m.underscore}
263
+ # end
264
+ #
265
+ # def nested?
266
+ # options[:under].present?
267
+ # end
268
+ #
269
+ # ### NAMESPACE ###
270
+ # def leospaced?
271
+ # options[:leospace].present?
272
+ # end
273
+ #
274
+ # def base_namespaces(prefix="")
275
+ # return [] unless options[:leospace].present?
276
+ # options[:leospace].split('/').map{|m| "#{prefix}#{m.underscore}"}
277
+ # end
278
+ #
279
+ # def last_namespace(prefix="")
280
+ # base_namespaces(prefix).last
281
+ # end
282
+ #
283
+ # def formatted_namespace_path(separator='/')
284
+ # return "" unless leospaced?
285
+ # "#{base_namespaces.join(separator)}#{separator}"
286
+ # end
287
+ #
288
+ # module Test
289
+ # protected
290
+ # #Add parent(s) param(s) to request
291
+ # #get :index for a product under category => get :index, :category_id => product.category_id.to_s
292
+ # def nested_params_http_request(value=nil)
293
+ # return unless nested?
294
+ # ", " << base_parent_resources.map{|m| ":#{m}_id => #{value ? value.to_s.inspect : "#{file_name}.#{m}_id.to_s"}"}.join(', ')
295
+ # end
296
+ #
297
+ # #Create new parent(s) and add it to request
298
+ # #get :index for a product under category => get :index, :category_id => Factory(:category).id.to_s
299
+ # def nested_params_http_request_new_parent
300
+ # return unless nested?
301
+ # ", " << base_parent_resources.map{|m| ":#{m}_id => Factory(:#{m}).id.to_s"}.join(', ')
302
+ # end
303
+ #
304
+ # #product => products_path
305
+ # #product under category => category_products_path(product.category)
306
+ # #product under brand/category => brand_category_products_path(product.brand, product.category)
307
+ # def list_resources_path_test(resource=nil, prefix_parent=nil)
308
+ # unless prefix_parent
309
+ # resource ||= singular_table_name
310
+ # prefix_parent = "#{resource}."
311
+ # end
312
+ # "#{underscore_resource_path(:parent_singular_resource_plural)}_path(#{formatted_parent_resources(prefix_parent, "", resource)})"
313
+ # end
314
+ #
315
+ # #product => "product"
316
+ # #product under category => "[category, product]" or "[product.category, product]"
317
+ # #product under brand/category => "[brand, category, product]" or "[product.brand, product.category, product]"
318
+ # def show_resource_path_test(resource=nil, prefix_parent=nil, prefix_resource="")
319
+ # resource ||= singular_table_name
320
+ # prefix_parent = prefix_parent || "#{resource}."
321
+ # formatted_resource_path(prefix_parent, prefix_resource, "[]", resource)
322
+ # end
323
+ #
324
+ # #product => new_product_path
325
+ # #product under category => new_category_product_path(product.category)
326
+ # #product under brand/category => new_brand_category_product_path(product.brand, product.category)
327
+ # def new_resource_path_test(resource=nil, prefix_parent=nil)
328
+ # resource ||= singular_table_name
329
+ # prefix_parent = prefix_parent || "#{resource}."
330
+ # "new_#{underscore_resource_path}_path(#{formatted_parent_resources(prefix_parent, "",resource)})"
331
+ # end
332
+ # end
333
+ #end
334
+ end