adminpanel 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -7
- data/Rakefile +8 -7
- data/adminpanel.gemspec +6 -6
- data/app/controllers/adminpanel/application_controller.rb +1 -0
- data/app/controllers/concerns/adminpanel/facebook_actions.rb +1 -1
- data/app/controllers/concerns/adminpanel/sitemap_actions.rb +13 -0
- data/app/models/concerns/adminpanel/base.rb +1 -2
- data/app/models/concerns/adminpanel/facebook.rb +1 -1
- data/app/models/concerns/adminpanel/sitemap.rb +34 -0
- data/lib/adminpanel/version.rb +1 -1
- data/lib/generators/adminpanel/gallery/gallery_generator.rb +26 -28
- data/lib/generators/adminpanel/initialize/initialize_generator.rb +50 -52
- data/lib/generators/adminpanel/resource/resource_generator.rb +190 -193
- data/lib/tasks/adminpanel/adminpanel.rake +4 -4
- data/test/dummy/app/controllers/adminpanel/departments_controller.rb +13 -0
- data/test/dummy/app/models/adminpanel/department.rb +47 -0
- data/test/dummy/app/models/adminpanel/item.rb +38 -0
- data/test/dummy/app/models/adminpanel/mug.rb +1 -1
- data/test/dummy/app/models/adminpanel/salesman.rb +1 -0
- data/test/dummy/config/initializers/adminpanel_setup.rb +1 -0
- data/test/dummy/db/schema.rb +12 -0
- data/test/dummy/test/fixtures/adminpanel/mugs.yml +12 -0
- data/test/dummy/test/fixtures/adminpanel/products.yml +6 -0
- data/test/dummy/test/fixtures/adminpanel/salesmen.yml +12 -0
- data/test/features/shared/action_exclution_test.rb +20 -0
- data/test/features/shared/belongs_to_category_modal_test.rb +35 -0
- data/test/features/shared/belongs_to_non_category_modal_test.rb +41 -0
- data/test/features/shared/edit_test.rb +32 -0
- data/test/features/shared/has_many_through_category_modal_test.rb +35 -0
- data/test/features/shared/has_many_through_non_category_modal_test.rb +37 -0
- data/test/features/shared/index_test.rb +20 -0
- data/test/features/shared/new_test.rb +3 -3
- data/test/features/shared/show_test.rb +20 -0
- data/test/generators/gallery_generator_test.rb +39 -0
- data/test/generators/initialize_generator_test.rb +45 -0
- data/test/generators/resource_generator_test.rb +138 -0
- data/test/tasks/adminpanel_rake_test.rb +32 -0
- data/test/test_helper.rb +16 -23
- metadata +81 -70
- data/app/uploaders/adminpanel/image_uploader.rb +0 -58
- data/spec/features/galleries_pages_spec.rb +0 -110
- data/spec/features/section_pages_spec.rb +0 -36
- data/spec/features/shared_pages/edit_spec.rb +0 -48
- data/spec/features/shared_pages/index_spec.rb +0 -50
- data/spec/features/shared_pages/new_spec.rb +0 -128
- data/spec/features/shared_pages/show_spec.rb +0 -30
- data/spec/generators/gallery_generator_spec.rb +0 -48
- data/spec/generators/initialize_generator_spec.rb +0 -68
- data/spec/generators/resource_generator_spec.rb +0 -169
- data/spec/spec_helper.rb +0 -42
- data/spec/support/capybara_matchers.rb +0 -17
- data/spec/support/factories.rb +0 -52
- data/spec/support/helper_methods.rb +0 -30
- data/spec/support/shared_connection.rb +0 -10
- data/spec/tasks/adminpanel_rake_spec.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12212a53c9a9f2c010bfd19215a87d260a8fdf5c
|
4
|
+
data.tar.gz: f2c4698f3c330934d03727b23e71d1d8a30a3f6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9ff9e24e0b7ce8e63c86f0599dc576a93cd6b1526733bf21b5d50276d5622d37f2148737bf5b5fdaf7e8ea9f8b0a199e373f7c3c45e5e0b1aa4c5d8b8cf76e3
|
7
|
+
data.tar.gz: d8a24e70bac9aeba5efe00103af7cc9708d31c0c9cfece3253d49a0129f4d4a76c8b8f744a5c9dd9ad0da8e83fb2d610cae2550439637061661bc5526b393e88
|
data/Gemfile
CHANGED
@@ -18,16 +18,15 @@ gem 'font-awesome-rails', '>= 4.0.3.1'
|
|
18
18
|
gem 'koala', '>= 1.9.0', '<= 2.0.0'
|
19
19
|
|
20
20
|
group :assets do
|
21
|
+
gem 'coffee-script', require: true
|
21
22
|
gem 'sass-rails', '>= 4.0.3', require: true
|
22
23
|
end
|
23
24
|
|
24
|
-
gem 'minitest'
|
25
25
|
group :development, :test do
|
26
|
+
gem 'minitest', '>= 5.3.4', '<= 6.0.0'
|
26
27
|
gem 'sqlite3', '>= 1.3.9', '<= 2.0.0', :platform => [:ruby, :mswin, :mingw]
|
27
|
-
gem 'minitest-emoji'
|
28
|
-
gem 'minitest-capybara'
|
29
|
-
gem 'mocha'
|
30
|
-
gem 'poltergeist'
|
31
|
-
gem 'parallel_tests'
|
32
|
-
# gem 'minitest-debugger'
|
28
|
+
gem 'minitest-emoji', '2.0.0'
|
29
|
+
gem 'minitest-capybara', '>= 0.6.1', '<= 1.0.0'
|
30
|
+
# gem 'mocha'
|
31
|
+
gem 'poltergeist', '>= 1.5.1', '<= 2.0.0'
|
33
32
|
end
|
data/Rakefile
CHANGED
@@ -11,10 +11,11 @@ Rake::TestTask.new do |t|
|
|
11
11
|
t.warning = false
|
12
12
|
end
|
13
13
|
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
#to run isolated tests...
|
15
|
+
namespace :test do
|
16
|
+
task :isolated do
|
17
|
+
Dir.glob("test/**/*_test.rb").all? do |file|
|
18
|
+
sh(Gem.ruby, '-w', '-Ilib:test', file)
|
19
|
+
end or raise "Failures"
|
20
|
+
end
|
21
|
+
end
|
data/adminpanel.gemspec
CHANGED
@@ -34,13 +34,13 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_dependency 'sass-rails', '>= 4.0.3', '<= 4.1.0'
|
35
35
|
spec.add_dependency 'font-awesome-rails', '>= 4.0.3.1', '<= 4.1.0'
|
36
36
|
spec.add_dependency 'koala', '>= 1.9.0', '<= 2.0.0'
|
37
|
+
spec.add_dependency 'coffee-script'
|
37
38
|
|
38
39
|
spec.add_development_dependency 'sqlite3', '>= 1.3.9', '<= 2.0.0'
|
39
|
-
spec.
|
40
|
-
spec.add_development_dependency 'minitest-emoji'
|
41
|
-
spec.add_development_dependency 'minitest-capybara'
|
42
|
-
spec.add_development_dependency 'mocha'
|
43
|
-
spec.add_development_dependency '
|
44
|
-
spec.add_development_dependency 'poltergeist'
|
40
|
+
spec.add_development_dependency 'minitest', '>= 5.3.4', '<= 6.0.0'
|
41
|
+
spec.add_development_dependency 'minitest-emoji', '2.0.0'
|
42
|
+
spec.add_development_dependency 'minitest-capybara', '>= 0.6.1', '<= 1.0.0'
|
43
|
+
# spec.add_development_dependency 'mocha'
|
44
|
+
spec.add_development_dependency 'poltergeist', '>= 1.5.1', '<= 2.0.0'
|
45
45
|
# spec.add_development_dependency 'minitest-debugger'
|
46
46
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Adminpanel
|
2
|
+
module SitemapActions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
before_filter :set_default_host, only:[:create, :update, :destroy]
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
def set_default_host
|
10
|
+
Rails.application.routes.default_url_options[:host] = request.host
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -4,7 +4,6 @@ module Adminpanel
|
|
4
4
|
#instance methods
|
5
5
|
# static(class) methods
|
6
6
|
module ClassMethods
|
7
|
-
|
8
7
|
def mount_images(relation)
|
9
8
|
has_many relation, :dependent => :destroy
|
10
9
|
accepts_nested_attributes_for relation, :allow_destroy => true
|
@@ -100,7 +99,7 @@ module Adminpanel
|
|
100
99
|
false
|
101
100
|
end
|
102
101
|
end
|
103
|
-
|
102
|
+
|
104
103
|
def fb_share?
|
105
104
|
false
|
106
105
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Adminpanel
|
2
|
+
module Sitemap
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include Rails.application.routes.url_helpers
|
5
|
+
|
6
|
+
included do
|
7
|
+
after_create :ping_engines
|
8
|
+
after_update :ping_engines
|
9
|
+
after_destroy :ping_engines
|
10
|
+
end
|
11
|
+
|
12
|
+
def ping_urls
|
13
|
+
{
|
14
|
+
google: "http://www.google.com/webmasters/tools/ping?sitemap=%s",
|
15
|
+
ask: "http://submissions.ask.com/ping?sitemap=%s",
|
16
|
+
bing: "http://www.bing.com/webmaster/ping.aspx?siteMap=%s"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def ping_engines
|
21
|
+
logger.info Time.now
|
22
|
+
ping_urls.each do |name, url|
|
23
|
+
request = url % CGI.escape("#{root_url}/sitemap.xml")
|
24
|
+
logger.info " Pinging #{name} with #{request}"
|
25
|
+
if Rails.env == "production"
|
26
|
+
response = Net::HTTP.get_response(URI.parse(request))
|
27
|
+
logger.info " #{response.code}: #{response.message}"
|
28
|
+
logger.info " Body: #{response.body}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/adminpanel/version.rb
CHANGED
@@ -1,39 +1,37 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
module Adminpanel
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
desc "Generate the resource files necessary to use a model"
|
3
|
+
class GalleryGenerator < ActiveRecord::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
desc "Generate the resource files necessary to use a model"
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def generate_uploader
|
13
|
-
template 'uploader.rb', "app/uploaders/adminpanel/#{lower_name}_uploader.rb"
|
14
|
-
end
|
7
|
+
def generate_model
|
8
|
+
template 'gallery_template.rb', "app/models/adminpanel/#{lower_name}.rb"
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
"db/migrate/create_adminpanel_#{lower_name.pluralize}.rb"
|
20
|
-
)
|
21
|
-
puts "don't forget to add the form_field, the relationship and #{lower_name}s_attributes it to the permited params"
|
22
|
-
end
|
11
|
+
def generate_uploader
|
12
|
+
template 'uploader.rb', "app/uploaders/adminpanel/#{lower_name}_uploader.rb"
|
13
|
+
end
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
def generate_migration
|
16
|
+
migration_template(
|
17
|
+
'gallery_migration.rb',
|
18
|
+
"db/migrate/create_adminpanel_#{lower_name.pluralize}.rb"
|
19
|
+
)
|
20
|
+
puts "don't forget to add the form_field, the relationship and #{lower_name}s_attributes it to the permited params"
|
21
|
+
end
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
private
|
24
|
+
def reference_name
|
25
|
+
name.singularize.downcase
|
26
|
+
end
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
def lower_name
|
29
|
+
"#{reference_name}file"
|
30
|
+
end
|
36
31
|
|
32
|
+
def class_name
|
33
|
+
"#{lower_name.capitalize}"
|
37
34
|
end
|
35
|
+
|
38
36
|
end
|
39
37
|
end
|
@@ -1,67 +1,65 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
module Adminpanel
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
:desc => 'Skip cancan\'s ability.rb'
|
3
|
+
class InitializeGenerator < ActiveRecord::Generators::Base
|
4
|
+
desc "Generate the migrations necessary to start the gem"
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
6
|
+
argument :name, :type => :string, :default => "default", :require => false
|
7
|
+
class_option :'skip-category',
|
8
|
+
:type => :boolean,
|
9
|
+
:aliases => '-c',
|
10
|
+
:default => false,
|
11
|
+
:desc => "Skip category skeleton and migration for it if true"
|
12
|
+
class_option :'skip-section-uploader',
|
13
|
+
:type => :boolean,
|
14
|
+
:aliases => '-u',
|
15
|
+
:default => false,
|
16
|
+
:desc => 'Skip section uploader if true'
|
17
|
+
class_option :'skip-migration',
|
18
|
+
:type => :boolean,
|
19
|
+
:aliases => '-m',
|
20
|
+
:default => false,
|
21
|
+
:desc => 'Skip initial migrations if true'
|
22
|
+
class_option :'skip-setup',
|
23
|
+
:type => :boolean,
|
24
|
+
:aliases => '-p',
|
25
|
+
:default => false,
|
26
|
+
:desc => 'Skip setup if true'
|
27
|
+
class_option :'skip-setup',
|
28
|
+
:type => :boolean,
|
29
|
+
:aliases => '-y',
|
30
|
+
:default => false,
|
31
|
+
:desc => 'Skip cancan\'s ability.rb'
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
33
|
+
def create_initializer
|
34
|
+
if !options[:'skip-setup']
|
35
|
+
copy_file 'adminpanel_setup.rb', 'config/initializers/adminpanel_setup.rb'
|
38
36
|
end
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
39
|
+
def create_ability
|
40
|
+
if !options[:'skip-ability']
|
41
|
+
copy_file 'ability.rb', 'app/models/ability.rb'
|
44
42
|
end
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
45
|
+
def create_category
|
46
|
+
if !options[:'skip-category']
|
47
|
+
copy_file "category_template.rb", 'app/models/adminpanel/category.rb'
|
48
|
+
migration_template 'create_adminpanel_categories_table.rb', 'db/migrate/create_adminpanel_categories_table.rb'
|
51
49
|
end
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
52
|
+
def create_section_uploader
|
53
|
+
if !options[:'skip-section-uploader']
|
54
|
+
copy_file "section_uploader.rb", 'app/uploaders/adminpanel/section_uploader.rb'
|
57
55
|
end
|
56
|
+
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
58
|
+
def create_adminpanel_migration
|
59
|
+
if !options[:'skip-migration']
|
60
|
+
migration_template 'create_adminpanel_tables.rb', 'db/migrate/create_adminpanel_tables.rb'
|
63
61
|
end
|
64
|
-
|
65
62
|
end
|
63
|
+
|
66
64
|
end
|
67
65
|
end
|
@@ -1,251 +1,248 @@
|
|
1
|
-
# require "action_view"
|
2
1
|
require 'rails/generators/active_record'
|
3
2
|
module Adminpanel
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
fields << attribute.split(':').first + ':' + 'text'
|
23
|
-
end
|
3
|
+
class ResourceGenerator < ActiveRecord::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
desc "Generate the resource files necessary to use a model"
|
6
|
+
class_option :'gallery',
|
7
|
+
:type => :boolean,
|
8
|
+
:aliases => '-g',
|
9
|
+
:default => true,
|
10
|
+
:desc => 'Creates the gallery for this resource'
|
11
|
+
|
12
|
+
argument :fields, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
|
13
|
+
|
14
|
+
def change_fields_aliases
|
15
|
+
fields.each do |attribute|
|
16
|
+
type = attribute.split(':').second
|
17
|
+
case type
|
18
|
+
when 'wysiwyg'
|
19
|
+
fields.delete(attribute)
|
20
|
+
fields << attribute.split(':').first + ':' + 'text'
|
24
21
|
end
|
25
22
|
end
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
def generate_model
|
26
|
+
template 'resource.rb', "app/models/adminpanel/#{lower_singularized_name}.rb"
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
29
|
+
def generate_controller
|
30
|
+
if is_a_resource?
|
31
|
+
template "controller.rb", "app/controllers/adminpanel/#{pluralized_name}_controller.rb"
|
35
32
|
end
|
33
|
+
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
def generate_migration
|
36
|
+
parameters = fields
|
37
|
+
parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
|
38
|
+
invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
|
39
|
+
puts parameters if ENV['RAILS_ENV']
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
42
|
+
def generate_gallery
|
43
|
+
if has_gallery? && is_a_resource?
|
44
|
+
invoke 'adminpanel:gallery', [lower_singularized_name]
|
47
45
|
end
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
48
|
+
def add_resource_to_config
|
49
|
+
if setup_is_found? && is_a_resource?
|
50
|
+
inject_into_file 'config/initializers/adminpanel_setup.rb',
|
51
|
+
after: 'config.displayable_resources = [' do
|
52
|
+
indent "\n:#{pluralized_name},", 4
|
55
53
|
end
|
56
54
|
end
|
55
|
+
end
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
private
|
57
|
+
def print_messages
|
58
|
+
puts "don't forget to restart your server"
|
59
|
+
end
|
63
60
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
private
|
62
|
+
def setup_is_found?
|
63
|
+
if Dir.exists?('config') && Dir.exists?('config/initializers') && File.exists?('config/initializers/adminpanel_setup.rb')
|
64
|
+
true
|
65
|
+
else
|
66
|
+
false
|
70
67
|
end
|
68
|
+
end
|
71
69
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
70
|
+
def is_a_resource?
|
71
|
+
fields.each do |attribute|
|
72
|
+
assign_attributes_variables(attribute)
|
73
|
+
if @attr_type != 'belongs_to'
|
74
|
+
return true
|
78
75
|
end
|
79
|
-
false
|
80
76
|
end
|
77
|
+
false
|
78
|
+
end
|
81
79
|
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
def has_gallery?
|
81
|
+
options[:'gallery']
|
82
|
+
end
|
85
83
|
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
def gallery_name
|
85
|
+
"#{lower_singularized_name}file"
|
86
|
+
end
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
def lower_singularized_name
|
89
|
+
name.singularize.downcase
|
90
|
+
end
|
93
91
|
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
def capitalized_resource
|
93
|
+
lower_singularized_name.capitalize
|
94
|
+
end
|
97
95
|
|
98
|
-
|
99
|
-
|
100
|
-
|
96
|
+
def pluralized_name
|
97
|
+
"#{lower_singularized_name.pluralize}"
|
98
|
+
end
|
101
99
|
|
102
|
-
|
103
|
-
|
104
|
-
|
100
|
+
def belongs_to_field(resource)
|
101
|
+
"#{resource.singularize.downcase}_id"
|
102
|
+
end
|
105
103
|
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
def has_many_field(resource)
|
105
|
+
"#{resource.singularize.downcase}_ids"
|
106
|
+
end
|
109
107
|
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
def resource_class_name(resource)
|
109
|
+
"#{resource.singularize.capitalize}"
|
110
|
+
end
|
113
111
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
112
|
+
def assign_attributes_variables(attribute)
|
113
|
+
@attr_field = attribute.split(":").first
|
114
|
+
if attribute.split(":").second.nil?
|
115
|
+
@attr_type = "string"
|
116
|
+
else
|
117
|
+
@attr_type = attribute.split(":").second
|
121
118
|
end
|
119
|
+
end
|
122
120
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
121
|
+
def symbolized_attributes
|
122
|
+
fields.map do |attribute|
|
123
|
+
assign_attributes_variables(attribute)
|
124
|
+
case @attr_type
|
125
|
+
when 'belongs_to'
|
126
|
+
':' + belongs_to_field(@attr_field)
|
127
|
+
when 'has_many'
|
128
|
+
':' + has_many_field(@attr_field)
|
129
|
+
else
|
130
|
+
":#{attribute.split(':').first}"
|
131
|
+
end
|
132
|
+
end.join(",\n")
|
133
|
+
end
|
136
134
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
135
|
+
def get_attribute_hash
|
136
|
+
fields.map do |attribute|
|
137
|
+
assign_attributes_variables(attribute)
|
138
|
+
send(@attr_type + '_form_hash')
|
139
|
+
end.join(", \n")
|
140
|
+
end
|
143
141
|
|
144
|
-
|
145
|
-
|
146
|
-
|
142
|
+
def string_form_hash
|
143
|
+
attribute_hash(@attr_field, 'text_field')
|
144
|
+
end
|
147
145
|
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
def float_form_hash
|
147
|
+
attribute_hash(@attr_field, 'text_field')
|
148
|
+
end
|
151
149
|
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
def text_form_hash
|
151
|
+
attribute_hash(@attr_field ,'wysiwyg_field')
|
152
|
+
end
|
155
153
|
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
def integer_form_hash
|
155
|
+
attribute_hash(@attr_field, 'number_field')
|
156
|
+
end
|
159
157
|
|
160
|
-
|
161
|
-
|
162
|
-
|
158
|
+
def boolean_form_hash
|
159
|
+
attribute_hash(@attr_field, 'boolean')
|
160
|
+
end
|
163
161
|
|
164
|
-
|
165
|
-
|
166
|
-
|
162
|
+
def datepicker_form_hash
|
163
|
+
attribute_hash(@attr_field, 'datepicker')
|
164
|
+
end
|
167
165
|
|
168
|
-
|
169
|
-
|
170
|
-
|
166
|
+
def file_field_form_hash
|
167
|
+
attribute_hash(gallery_name.pluralize, 'adminpanel_file_field')
|
168
|
+
end
|
171
169
|
|
172
|
-
|
173
|
-
|
174
|
-
|
170
|
+
def belongs_to_form_hash
|
171
|
+
attribute_hash(belongs_to_field(@attr_field), 'belongs_to', resource_class_name(@attr_field))
|
172
|
+
end
|
175
173
|
|
176
|
-
|
177
|
-
|
178
|
-
|
174
|
+
def has_many_form_hash
|
175
|
+
attribute_hash(has_many_field(resource_class_name(@attr_field)), 'has_many', 'has_many model')
|
176
|
+
end
|
179
177
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
178
|
+
def attribute_hash(name, type, model = '')
|
179
|
+
if model != ''
|
180
|
+
model = model_type(model) + ",\n"
|
181
|
+
end
|
182
|
+
"{\n" +
|
183
|
+
indent("'#{name}'" + " => {\n", 2) +
|
184
|
+
indent(form_type(type), 4) + ",\n" +
|
185
|
+
indent(label_type, 4) + ",\n" +
|
186
|
+
indent(placeholder_type, 4) + ",\n" +
|
187
|
+
indent(model, 4) +
|
188
|
+
indent("}\n", 2) +
|
189
|
+
'}'
|
190
|
+
end
|
193
191
|
|
194
|
-
|
195
|
-
|
196
|
-
|
192
|
+
def form_type(type)
|
193
|
+
"'type' => '#{type}'"
|
194
|
+
end
|
197
195
|
|
198
|
-
|
199
|
-
|
200
|
-
|
196
|
+
def label_type
|
197
|
+
"'label' => '#{@attr_field}'"
|
198
|
+
end
|
201
199
|
|
202
|
-
|
203
|
-
|
204
|
-
|
200
|
+
def placeholder_type
|
201
|
+
"'placeholder' => '#{@attr_field}'"
|
202
|
+
end
|
205
203
|
|
206
|
-
|
207
|
-
|
208
|
-
|
204
|
+
def model_type(type)
|
205
|
+
"'model' => 'Adminpanel::#{type}'"
|
206
|
+
end
|
209
207
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
end
|
208
|
+
def has_associations?
|
209
|
+
fields.each do |attribute|
|
210
|
+
assign_attributes_variables(attribute)
|
211
|
+
if @attr_type == "images" || @attr_type == "belongs_to" || @attr_type == "has_many" || @attr_type == "has_many_through"
|
212
|
+
return true
|
216
213
|
end
|
217
|
-
return false
|
218
214
|
end
|
215
|
+
return false
|
216
|
+
end
|
219
217
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
end
|
229
|
-
|
218
|
+
def associations
|
219
|
+
association = ""
|
220
|
+
fields.each do |attribute|
|
221
|
+
assign_attributes_variables(attribute)
|
222
|
+
if @attr_type == "belongs_to"
|
223
|
+
association = "#{association}#{belongs_to_association(@attr_field)}"
|
224
|
+
elsif @attr_type == "has_many" || @attr_type == "has_many_through"
|
225
|
+
association = "#{association}#{has_many_association(@attr_field)}"
|
230
226
|
end
|
231
|
-
association
|
232
|
-
end
|
233
227
|
|
234
|
-
def belongs_to_association(field)
|
235
|
-
"belongs_to :#{field.singularize.downcase}\n\t\t"
|
236
228
|
end
|
229
|
+
association
|
230
|
+
end
|
237
231
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
":through => :categorizations, " +
|
242
|
-
":dependent => :destroy\n\t\t"
|
243
|
-
end
|
232
|
+
def belongs_to_association(field)
|
233
|
+
"belongs_to :#{field.singularize.downcase}\n\t\t"
|
234
|
+
end
|
244
235
|
|
245
|
-
|
246
|
-
|
247
|
-
|
236
|
+
def has_many_association(field)
|
237
|
+
return "# has_many :categorizations\n\t\t" +
|
238
|
+
"# has_many :#{@attr_field}, " +
|
239
|
+
":through => :categorizations, " +
|
240
|
+
":dependent => :destroy\n\t\t"
|
241
|
+
end
|
248
242
|
|
243
|
+
def get_gallery
|
244
|
+
return "\n\t\tmount_images :#{gallery_name.pluralize}\n"
|
249
245
|
end
|
246
|
+
|
250
247
|
end
|
251
248
|
end
|