active_leonardo 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +48 -43
- data/LICENSE +19 -19
- data/README.md +173 -173
- data/active_template.rb +157 -141
- data/lib/generators/active_leonardo.rb +383 -383
- data/lib/generators/erb/leosca/leosca_generator.rb +122 -122
- data/lib/generators/leolay/USAGE +21 -21
- data/lib/generators/leolay/leolay_generator.rb +420 -420
- data/lib/generators/leolay/templates/app/admin/users.rb +87 -87
- data/lib/generators/leolay/templates/spec/helpers/application_helpers.rb +13 -13
- data/lib/generators/leolay/templates/spec/support/devise.rb +4 -4
- data/lib/generators/leolay/templates/styles/active/stylesheets/app/custom_active_admin.css.scss +27 -27
- data/lib/generators/leosca/USAGE +23 -23
- data/lib/generators/rails/leosca/USAGE +39 -39
- data/lib/generators/rails/leosca/leosca_generator.rb +55 -55
- data/lib/generators/rails/leosca/templates/leosca.css +56 -56
- data/lib/generators/rails/leosca_controller/USAGE +23 -23
- data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +192 -192
- data/lib/generators/rails/leosca_controller/templates/controller.rb +3 -3
- data/lib/generators/rspec/leointegration/leointegration_generator.rb +35 -35
- data/lib/generators/rspec/leointegration/templates/admin/feature.rb +67 -67
- data/lib/generators/rspec/leointegration/templates/feature.rb +9 -9
- data/lib/generators/rspec/leosca/leosca_generator.rb +57 -57
- data/lib/generators/rspec/leosca/templates/admin/controller_spec.rb +181 -181
- data/lib/generators/rspec/leosca/templates/admin/edit_spec.rb +31 -31
- data/lib/generators/rspec/leosca/templates/admin/index_spec.rb +32 -32
- data/lib/generators/rspec/leosca/templates/admin/new_spec.rb +30 -30
- data/lib/generators/rspec/leosca/templates/admin/routing_spec.rb +39 -39
- data/lib/generators/rspec/leosca/templates/admin/show_spec.rb +28 -28
- data/lib/generators/rspec/leosca/templates/controller_spec.rb +168 -168
- data/lib/generators/rspec/leosca/templates/edit_spec.rb +31 -31
- data/lib/generators/rspec/leosca/templates/index_spec.rb +32 -32
- data/lib/generators/rspec/leosca/templates/new_spec.rb +30 -30
- data/lib/generators/rspec/leosca/templates/routing_spec.rb +39 -39
- data/lib/generators/rspec/leosca/templates/show_spec.rb +28 -28
- metadata +3 -3
data/active_template.rb
CHANGED
@@ -1,141 +1,157 @@
|
|
1
|
-
#########################################################
|
2
|
-
#
|
3
|
-
# This is a Rails
|
4
|
-
# https://rubygems.org/gems/
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
puts
|
14
|
-
puts
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
/
|
33
|
-
/
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
/*.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
gem "
|
44
|
-
gem "
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
gem "
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
gem
|
64
|
-
gem
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
if
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
if
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
generate "
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
1
|
+
#########################################################
|
2
|
+
# 2014 Marco Mastrodonato(c)
|
3
|
+
# This is a Rails 4.0 template to use with activeleonardo gem
|
4
|
+
# https://rubygems.org/gems/active_leonardo
|
5
|
+
# https://github.com/marcomd/Active_Leonardo
|
6
|
+
#
|
7
|
+
# USAGE: rails new yourappname -m active_template.rb
|
8
|
+
#
|
9
|
+
# -------------------------------------------------------
|
10
|
+
#
|
11
|
+
#########################################################
|
12
|
+
|
13
|
+
puts '*' * 40
|
14
|
+
puts "* Processing template..."
|
15
|
+
puts '*' * 40
|
16
|
+
|
17
|
+
use_git = yes?("Do you use git ?")
|
18
|
+
if use_git
|
19
|
+
git :init
|
20
|
+
file ".gitignore", <<-EOS.gsub(/^ /, '')
|
21
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
22
|
+
#
|
23
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
24
|
+
# or operating system, you probably want to add a global ignore instead:
|
25
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
26
|
+
|
27
|
+
# Ignore bundler config
|
28
|
+
/.bundle
|
29
|
+
# Ignore the default SQLite database.
|
30
|
+
/db/*.sqlite3
|
31
|
+
# Ignore all logfiles and tempfiles.
|
32
|
+
/log/*.log
|
33
|
+
/tmp
|
34
|
+
/nbproject
|
35
|
+
/.idea
|
36
|
+
lib/tasks/files/*
|
37
|
+
/*.cmd
|
38
|
+
/*.dat
|
39
|
+
/config/initializers/secret_token.rb
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
|
43
|
+
gem "activeadmin", git: 'http://github.com/gregbell/active_admin.git'
|
44
|
+
gem "active_leonardo"
|
45
|
+
gem "jquery-turbolinks"
|
46
|
+
gem "bourbon"
|
47
|
+
|
48
|
+
easy_develop = yes?("Do you want to make development easier?")
|
49
|
+
if easy_develop
|
50
|
+
gem "rack-mini-profiler", :group => :development
|
51
|
+
gem "better_errors", :group => :development
|
52
|
+
gem "awesome_print", :group => :development
|
53
|
+
end
|
54
|
+
|
55
|
+
#use_editor = yes?("Do you want a wysihtml editor?")
|
56
|
+
#if use_editor
|
57
|
+
# gem 'activeadmin-dragonfly', git: 'http://192.30.252.131/stefanoverna/activeadmin-dragonfly'
|
58
|
+
# gem 'activeadmin-wysihtml5', git: 'http://192.30.252.131/stefanoverna/activeadmin-wysihtml5'
|
59
|
+
#end
|
60
|
+
|
61
|
+
easy_develop = yes?("Do you want to make development easier?")
|
62
|
+
if easy_develop
|
63
|
+
gem "rack-mini-profiler"
|
64
|
+
gem "jquery-turbolinks"
|
65
|
+
gem "awesome_print"
|
66
|
+
end
|
67
|
+
|
68
|
+
#use_editor = yes?("Do you want a wysihtml editor?")
|
69
|
+
#if use_editor
|
70
|
+
# gem 'activeadmin-dragonfly', git: 'https://github.com/stefanoverna/activeadmin-dragonfly'
|
71
|
+
# gem 'activeadmin-wysihtml5', git: 'https://github.com/stefanoverna/activeadmin-wysihtml5'
|
72
|
+
#end
|
73
|
+
|
74
|
+
rspec = yes?("Add rspec as testing framework ?")
|
75
|
+
if rspec
|
76
|
+
gem 'rspec-rails', :group => [:test, :development]
|
77
|
+
gem 'capybara', :group => :test
|
78
|
+
gem 'launchy', :group => :test
|
79
|
+
gem 'database_cleaner', :group => :test
|
80
|
+
if /1.8.*/ === RUBY_VERSION
|
81
|
+
gem 'factory_girl', '2.6.4', :group => :test
|
82
|
+
gem 'factory_girl_rails', '1.7.0', :group => :test
|
83
|
+
else
|
84
|
+
gem 'factory_girl_rails', :group => :test
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
authentication = yes?("Authentication ?")
|
89
|
+
model_name = authorization = nil
|
90
|
+
if authentication
|
91
|
+
default_model_name = "User"
|
92
|
+
model_name = ask(" Insert model name: [#{default_model_name}]")
|
93
|
+
if model_name.empty? || model_name == 'y'
|
94
|
+
model_name = default_model_name
|
95
|
+
else
|
96
|
+
model_name = model_name.classify
|
97
|
+
stdout = <<-REMEM.gsub(/^ /, '')
|
98
|
+
*************************************************************************
|
99
|
+
Remember to add your auth class when you use active leonardo's generator.
|
100
|
+
For example:
|
101
|
+
rails g leosca Product name price:decimal --auth_class=#{model_name}
|
102
|
+
*************************************************************************
|
103
|
+
REMEM
|
104
|
+
p stdout
|
105
|
+
end
|
106
|
+
|
107
|
+
authorization = yes?("Authorization ?")
|
108
|
+
if authorization
|
109
|
+
gem "cancan"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
gem 'state_machine' if yes?("Do you have to handle states ?")
|
114
|
+
|
115
|
+
dashboard_root = yes?("Would you use dashboard as root ? (recommended)")
|
116
|
+
home = yes?("Ok. Would you create home controller as root ?") unless dashboard_root
|
117
|
+
|
118
|
+
if yes?("Bundle install ?")
|
119
|
+
dir = ask(" Insert folder name to install locally: [blank=default gems path]")
|
120
|
+
run "bundle install #{"--path=#{dir}" unless dir.empty? || dir=='y'}"
|
121
|
+
end
|
122
|
+
|
123
|
+
generate "rspec:install" if rspec
|
124
|
+
|
125
|
+
generate "active_admin:install #{authentication ? model_name : "--skip-users"}"
|
126
|
+
|
127
|
+
if authorization
|
128
|
+
generate "cancan:ability"
|
129
|
+
generate "migration", "AddRolesMaskTo#{model_name}", "roles_mask:integer"
|
130
|
+
end
|
131
|
+
|
132
|
+
generate "leolay",
|
133
|
+
"active", #specify theme
|
134
|
+
"--auth_class=#{model_name}",
|
135
|
+
(rspec ? nil : "--skip-rspec"),
|
136
|
+
(authorization ? nil : "--skip-authorization"),
|
137
|
+
(authentication ? nil : "--skip-authentication")
|
138
|
+
|
139
|
+
|
140
|
+
if dashboard_root
|
141
|
+
route "root :to => 'admin/dashboard#index'"
|
142
|
+
elsif home
|
143
|
+
generate "controller", "home", "index"
|
144
|
+
route "root :to => 'home#index'"
|
145
|
+
end
|
146
|
+
|
147
|
+
rake "db:create:all"
|
148
|
+
rake "db:migrate"
|
149
|
+
rake "db:seed"
|
150
|
+
|
151
|
+
#rake "gems:unpack" if yes?("Unpack to vendor/gems ?")
|
152
|
+
if use_git
|
153
|
+
git :add => "."
|
154
|
+
git :commit => %Q{ -m "Initial commit" }
|
155
|
+
end
|
156
|
+
|
157
|
+
puts "ENJOY!"
|
@@ -1,384 +1,384 @@
|
|
1
|
-
module ActiveLeonardo
|
2
|
-
module Base
|
3
|
-
protected
|
4
|
-
def authorization_file
|
5
|
-
"app/models/ability.rb"
|
6
|
-
end
|
7
|
-
def authorization?
|
8
|
-
File.exists? authorization_file
|
9
|
-
end
|
10
|
-
def authentication_file auth_class="User"
|
11
|
-
"app/models/#{auth_class.downcase}.rb"
|
12
|
-
end
|
13
|
-
def authentication? auth_class="User"
|
14
|
-
return true if File.exists? authentication_file(auth_class)
|
15
|
-
File.exists? "config/initializers/devise.rb"
|
16
|
-
end
|
17
|
-
def activeadmin_file
|
18
|
-
"config/initializers/active_admin.rb"
|
19
|
-
end
|
20
|
-
def activeadmin?
|
21
|
-
File.exists? activeadmin_file
|
22
|
-
end
|
23
|
-
def auth_class
|
24
|
-
return unless options[:auth_class]
|
25
|
-
options[:auth_class].classify
|
26
|
-
end
|
27
|
-
#def formtastic?
|
28
|
-
# return false unless options.formtastic?
|
29
|
-
# File.exists? "config/initializers/formtastic.rb"
|
30
|
-
#end
|
31
|
-
#def jquery_ui?
|
32
|
-
# File.exists? "vendor/assets/javascripts/jquery-ui"
|
33
|
-
#end
|
34
|
-
#def pagination?
|
35
|
-
# File.exists? "config/initializers/kaminari_config.rb"
|
36
|
-
#end
|
37
|
-
end
|
38
|
-
|
39
|
-
module Leosca
|
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}"
|
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}"
|
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 ""
|
64
|
-
end
|
65
|
-
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}\" }"
|
86
|
-
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}"
|
99
|
-
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
|
-
|
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')"
|
136
|
-
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}
|
144
|
-
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
|
-
|
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
|
-
end
|
359
|
-
|
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
|
365
|
-
|
366
|
-
#product => "[:activespace, product]"
|
367
|
-
def show_resource_path_test(resource=nil)
|
368
|
-
resource ||= singular_table_name
|
369
|
-
"[:#{options[:activespace]}, #{resource}]"
|
370
|
-
end
|
371
|
-
|
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
|
-
end
|
377
|
-
|
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
|
-
end
|
1
|
+
module ActiveLeonardo
|
2
|
+
module Base
|
3
|
+
protected
|
4
|
+
def authorization_file
|
5
|
+
"app/models/ability.rb"
|
6
|
+
end
|
7
|
+
def authorization?
|
8
|
+
File.exists? authorization_file
|
9
|
+
end
|
10
|
+
def authentication_file auth_class="User"
|
11
|
+
"app/models/#{auth_class.downcase}.rb"
|
12
|
+
end
|
13
|
+
def authentication? auth_class="User"
|
14
|
+
return true if File.exists? authentication_file(auth_class)
|
15
|
+
File.exists? "config/initializers/devise.rb"
|
16
|
+
end
|
17
|
+
def activeadmin_file
|
18
|
+
"config/initializers/active_admin.rb"
|
19
|
+
end
|
20
|
+
def activeadmin?
|
21
|
+
File.exists? activeadmin_file
|
22
|
+
end
|
23
|
+
def auth_class
|
24
|
+
return unless options[:auth_class]
|
25
|
+
options[:auth_class].classify
|
26
|
+
end
|
27
|
+
#def formtastic?
|
28
|
+
# return false unless options.formtastic?
|
29
|
+
# File.exists? "config/initializers/formtastic.rb"
|
30
|
+
#end
|
31
|
+
#def jquery_ui?
|
32
|
+
# File.exists? "vendor/assets/javascripts/jquery-ui"
|
33
|
+
#end
|
34
|
+
#def pagination?
|
35
|
+
# File.exists? "config/initializers/kaminari_config.rb"
|
36
|
+
#end
|
37
|
+
end
|
38
|
+
|
39
|
+
module Leosca
|
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}"
|
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}"
|
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 ""
|
64
|
+
end
|
65
|
+
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}\" }"
|
86
|
+
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}"
|
99
|
+
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
|
+
|
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')"
|
136
|
+
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}
|
144
|
+
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
|
+
|
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
|
+
end
|
359
|
+
|
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
|
365
|
+
|
366
|
+
#product => "[:activespace, product]"
|
367
|
+
def show_resource_path_test(resource=nil)
|
368
|
+
resource ||= singular_table_name
|
369
|
+
"[:#{options[:activespace]}, #{resource}]"
|
370
|
+
end
|
371
|
+
|
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
|
+
end
|
377
|
+
|
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
|
+
end
|
384
384
|
end
|