adminpanel 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -7
  3. data/Rakefile +8 -7
  4. data/adminpanel.gemspec +6 -6
  5. data/app/controllers/adminpanel/application_controller.rb +1 -0
  6. data/app/controllers/concerns/adminpanel/facebook_actions.rb +1 -1
  7. data/app/controllers/concerns/adminpanel/sitemap_actions.rb +13 -0
  8. data/app/models/concerns/adminpanel/base.rb +1 -2
  9. data/app/models/concerns/adminpanel/facebook.rb +1 -1
  10. data/app/models/concerns/adminpanel/sitemap.rb +34 -0
  11. data/lib/adminpanel/version.rb +1 -1
  12. data/lib/generators/adminpanel/gallery/gallery_generator.rb +26 -28
  13. data/lib/generators/adminpanel/initialize/initialize_generator.rb +50 -52
  14. data/lib/generators/adminpanel/resource/resource_generator.rb +190 -193
  15. data/lib/tasks/adminpanel/adminpanel.rake +4 -4
  16. data/test/dummy/app/controllers/adminpanel/departments_controller.rb +13 -0
  17. data/test/dummy/app/models/adminpanel/department.rb +47 -0
  18. data/test/dummy/app/models/adminpanel/item.rb +38 -0
  19. data/test/dummy/app/models/adminpanel/mug.rb +1 -1
  20. data/test/dummy/app/models/adminpanel/salesman.rb +1 -0
  21. data/test/dummy/config/initializers/adminpanel_setup.rb +1 -0
  22. data/test/dummy/db/schema.rb +12 -0
  23. data/test/dummy/test/fixtures/adminpanel/mugs.yml +12 -0
  24. data/test/dummy/test/fixtures/adminpanel/products.yml +6 -0
  25. data/test/dummy/test/fixtures/adminpanel/salesmen.yml +12 -0
  26. data/test/features/shared/action_exclution_test.rb +20 -0
  27. data/test/features/shared/belongs_to_category_modal_test.rb +35 -0
  28. data/test/features/shared/belongs_to_non_category_modal_test.rb +41 -0
  29. data/test/features/shared/edit_test.rb +32 -0
  30. data/test/features/shared/has_many_through_category_modal_test.rb +35 -0
  31. data/test/features/shared/has_many_through_non_category_modal_test.rb +37 -0
  32. data/test/features/shared/index_test.rb +20 -0
  33. data/test/features/shared/new_test.rb +3 -3
  34. data/test/features/shared/show_test.rb +20 -0
  35. data/test/generators/gallery_generator_test.rb +39 -0
  36. data/test/generators/initialize_generator_test.rb +45 -0
  37. data/test/generators/resource_generator_test.rb +138 -0
  38. data/test/tasks/adminpanel_rake_test.rb +32 -0
  39. data/test/test_helper.rb +16 -23
  40. metadata +81 -70
  41. data/app/uploaders/adminpanel/image_uploader.rb +0 -58
  42. data/spec/features/galleries_pages_spec.rb +0 -110
  43. data/spec/features/section_pages_spec.rb +0 -36
  44. data/spec/features/shared_pages/edit_spec.rb +0 -48
  45. data/spec/features/shared_pages/index_spec.rb +0 -50
  46. data/spec/features/shared_pages/new_spec.rb +0 -128
  47. data/spec/features/shared_pages/show_spec.rb +0 -30
  48. data/spec/generators/gallery_generator_spec.rb +0 -48
  49. data/spec/generators/initialize_generator_spec.rb +0 -68
  50. data/spec/generators/resource_generator_spec.rb +0 -169
  51. data/spec/spec_helper.rb +0 -42
  52. data/spec/support/capybara_matchers.rb +0 -17
  53. data/spec/support/factories.rb +0 -52
  54. data/spec/support/helper_methods.rb +0 -30
  55. data/spec/support/shared_connection.rb +0 -10
  56. data/spec/tasks/adminpanel_rake_spec.rb +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8786bc62300628c7d87037f3e529408e44b4dd0
4
- data.tar.gz: dd2c11295e1b0b9d39f26d72697e05e7b8189a58
3
+ metadata.gz: 12212a53c9a9f2c010bfd19215a87d260a8fdf5c
4
+ data.tar.gz: f2c4698f3c330934d03727b23e71d1d8a30a3f6a
5
5
  SHA512:
6
- metadata.gz: 9c8a839e94618e65d911c6f8e4bd9667138660e46c78a746a670d54404f766d387d9ec13ff0e60d912f150fdbe2377e67cfd6bceead9395cd79f76994c83a312
7
- data.tar.gz: 1b2e8b33ebef3b4b535ca73df2c8067e02c0a42de5d919f55d4510a85d521e37abe657e097424434a1a400afc0dddfe32770e14520da84eccc127636cb66c9d9
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
- # namespace :test do
15
- # task :isolated do
16
- # Dir.glob("test/**/*_test.rb").all? do |file|
17
- # sh(Gem.ruby, '-w', '-Ilib:test', file)
18
- # end or raise "Failures"
19
- # end
20
- # end
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.add_dependency 'minitest'
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 'minitest-metadata'
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
@@ -8,6 +8,7 @@ module Adminpanel
8
8
  include Adminpanel::RestActions
9
9
  include Adminpanel::GalleryzableActions
10
10
  include Adminpanel::FacebookActions
11
+ include Adminpanel::SitemapActions
11
12
 
12
13
  layout 'admin'
13
14
 
@@ -3,7 +3,7 @@ module Adminpanel
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- before_filter :set_auths_count
6
+ before_filter :set_auths_count, only:[:index, :create, :update, :destroy, :show]
7
7
  end
8
8
 
9
9
  def fb_choose_page
@@ -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
@@ -13,7 +13,7 @@ module Adminpanel
13
13
  # )
14
14
  # end
15
15
  def fb_link
16
- 'www.google.com'
16
+ 'www.overwrite.fb_link.com'
17
17
  end
18
18
 
19
19
  # static(class) methods
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
@@ -1,39 +1,37 @@
1
1
  require 'rails/generators/active_record'
2
2
  module Adminpanel
3
- module Generators
4
- class GalleryGenerator < ActiveRecord::Generators::Base
5
- source_root File.expand_path("../templates", __FILE__)
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
- def generate_model
9
- template 'gallery_template.rb', "app/models/adminpanel/#{lower_name}.rb"
10
- end
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
- def generate_migration
17
- migration_template(
18
- 'gallery_migration.rb',
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
- private
25
- def reference_name
26
- name.singularize.downcase
27
- end
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
- def lower_name
30
- "#{reference_name}file"
31
- end
23
+ private
24
+ def reference_name
25
+ name.singularize.downcase
26
+ end
32
27
 
33
- def class_name
34
- "#{lower_name.capitalize}"
35
- end
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
- module Generators
4
- class InitializeGenerator < ActiveRecord::Generators::Base
5
- desc "Generate the migrations necessary to start the gem"
6
- source_root File.expand_path("../templates", __FILE__)
7
- argument :name, :type => :string, :default => "default", :require => false
8
- class_option :'skip-category',
9
- :type => :boolean,
10
- :aliases => '-c',
11
- :default => false,
12
- :desc => "Skip category skeleton and migration for it if true"
13
- class_option :'skip-section-uploader',
14
- :type => :boolean,
15
- :aliases => '-u',
16
- :default => false,
17
- :desc => 'Skip section uploader if true'
18
- class_option :'skip-migration',
19
- :type => :boolean,
20
- :aliases => '-m',
21
- :default => false,
22
- :desc => 'Skip initial migrations if true'
23
- class_option :'skip-setup',
24
- :type => :boolean,
25
- :aliases => '-p',
26
- :default => false,
27
- :desc => 'Skip setup if true'
28
- class_option :'skip-setup',
29
- :type => :boolean,
30
- :aliases => '-y',
31
- :default => false,
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
- def create_initializer
35
- if !options[:'skip-setup']
36
- copy_file 'adminpanel_setup.rb', 'config/initializers/adminpanel_setup.rb'
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
- def create_ability
41
- if !options[:'skip-ability']
42
- copy_file 'ability.rb', 'app/models/ability.rb'
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
- def create_category
47
- if !options[:'skip-category']
48
- copy_file "category_template.rb", 'app/models/adminpanel/category.rb'
49
- migration_template 'create_adminpanel_categories_table.rb', 'db/migrate/create_adminpanel_categories_table.rb'
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
- def create_section_uploader
54
- if !options[:'skip-section-uploader']
55
- copy_file "section_uploader.rb", 'app/uploaders/adminpanel/section_uploader.rb'
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
- def create_adminpanel_migration
60
- if !options[:'skip-migration']
61
- migration_template 'create_adminpanel_tables.rb', 'db/migrate/create_adminpanel_tables.rb'
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
- module Generators
5
- class ResourceGenerator < ActiveRecord::Generators::Base
6
- source_root File.expand_path("../templates", __FILE__)
7
- desc "Generate the resource files necessary to use a model"
8
- class_option :'include-gallery',
9
- :type => :boolean,
10
- :aliases => '-g',
11
- :default => true,
12
- :desc => 'Creates the gallery for this resource'
13
-
14
- argument :fields, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
15
-
16
- def change_fields_aliases
17
- fields.each do |attribute|
18
- type = attribute.split(':').second
19
- case type
20
- when 'wysiwyg'
21
- fields.delete(attribute)
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
- def generate_model
28
- template 'resource.rb', "app/models/adminpanel/#{lower_singularized_name}.rb"
29
- end
25
+ def generate_model
26
+ template 'resource.rb', "app/models/adminpanel/#{lower_singularized_name}.rb"
27
+ end
30
28
 
31
- def generate_controller
32
- if is_a_resource?
33
- template "controller.rb", "app/controllers/adminpanel/#{pluralized_name}_controller.rb"
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
- def generate_migrations
38
- parameters = fields
39
- parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
40
- invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
41
- end
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
- def generate_gallery
44
- if has_gallery? && is_a_resource?
45
- invoke 'adminpanel:gallery', [lower_singularized_name]
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
- def add_resource_to_config
50
- if setup_is_found? && is_a_resource?
51
- inject_into_file 'config/initializers/adminpanel_setup.rb',
52
- after: 'config.displayable_resources = [' do
53
- indent "\n:#{pluralized_name},", 4
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
- def print_messages
59
- puts "don't forget to restart your server"
60
- end
61
-
62
- private
57
+ def print_messages
58
+ puts "don't forget to restart your server"
59
+ end
63
60
 
64
- def setup_is_found?
65
- if Dir.exists?('config') && Dir.exists?('config/initializers') && File.exists?('config/initializers/adminpanel_setup.rb')
66
- true
67
- else
68
- false
69
- end
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
- def is_a_resource?
73
- fields.each do |attribute|
74
- assign_attributes_variables(attribute)
75
- if @attr_type != 'belongs_to'
76
- return true
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
- def has_gallery?
83
- options[:'include-gallery']
84
- end
80
+ def has_gallery?
81
+ options[:'gallery']
82
+ end
85
83
 
86
- def gallery_name
87
- "#{lower_singularized_name}file"
88
- end
84
+ def gallery_name
85
+ "#{lower_singularized_name}file"
86
+ end
89
87
 
90
- def lower_singularized_name
91
- name.singularize.downcase
92
- end
88
+ def lower_singularized_name
89
+ name.singularize.downcase
90
+ end
93
91
 
94
- def capitalized_resource
95
- lower_singularized_name.capitalize
96
- end
92
+ def capitalized_resource
93
+ lower_singularized_name.capitalize
94
+ end
97
95
 
98
- def pluralized_name
99
- "#{lower_singularized_name.pluralize}"
100
- end
96
+ def pluralized_name
97
+ "#{lower_singularized_name.pluralize}"
98
+ end
101
99
 
102
- def belongs_to_field(resource)
103
- "#{resource.singularize.downcase}_id"
104
- end
100
+ def belongs_to_field(resource)
101
+ "#{resource.singularize.downcase}_id"
102
+ end
105
103
 
106
- def has_many_field(resource)
107
- "#{resource.singularize.downcase}_ids"
108
- end
104
+ def has_many_field(resource)
105
+ "#{resource.singularize.downcase}_ids"
106
+ end
109
107
 
110
- def resource_class_name(resource)
111
- "#{resource.singularize.capitalize}"
112
- end
108
+ def resource_class_name(resource)
109
+ "#{resource.singularize.capitalize}"
110
+ end
113
111
 
114
- def assign_attributes_variables(attribute)
115
- @attr_field = attribute.split(":").first
116
- if attribute.split(":").second.nil?
117
- @attr_type = "string"
118
- else
119
- @attr_type = attribute.split(":").second
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
- def symbolized_attributes
124
- fields.map do |attribute|
125
- assign_attributes_variables(attribute)
126
- case @attr_type
127
- when 'belongs_to'
128
- ':' + belongs_to_field(@attr_field)
129
- when 'has_many'
130
- ':' + has_many_field(@attr_field)
131
- else
132
- ":#{attribute.split(':').first}"
133
- end
134
- end.join(",\n")
135
- end
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
- def get_attribute_hash
138
- fields.map do |attribute|
139
- assign_attributes_variables(attribute)
140
- send(@attr_type + '_form_hash')
141
- end.join(", \n")
142
- end
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
- def string_form_hash
145
- attribute_hash(@attr_field, 'text_field')
146
- end
142
+ def string_form_hash
143
+ attribute_hash(@attr_field, 'text_field')
144
+ end
147
145
 
148
- def float_form_hash
149
- attribute_hash(@attr_field, 'text_field')
150
- end
146
+ def float_form_hash
147
+ attribute_hash(@attr_field, 'text_field')
148
+ end
151
149
 
152
- def text_form_hash
153
- attribute_hash(@attr_field ,'wysiwyg_field')
154
- end
150
+ def text_form_hash
151
+ attribute_hash(@attr_field ,'wysiwyg_field')
152
+ end
155
153
 
156
- def integer_form_hash
157
- attribute_hash(@attr_field, 'number_field')
158
- end
154
+ def integer_form_hash
155
+ attribute_hash(@attr_field, 'number_field')
156
+ end
159
157
 
160
- def boolean_form_hash
161
- attribute_hash(@attr_field, 'boolean')
162
- end
158
+ def boolean_form_hash
159
+ attribute_hash(@attr_field, 'boolean')
160
+ end
163
161
 
164
- def datepicker_form_hash
165
- attribute_hash(@attr_field, 'datepicker')
166
- end
162
+ def datepicker_form_hash
163
+ attribute_hash(@attr_field, 'datepicker')
164
+ end
167
165
 
168
- def file_field_form_hash
169
- attribute_hash(gallery_name.pluralize, 'adminpanel_file_field')
170
- end
166
+ def file_field_form_hash
167
+ attribute_hash(gallery_name.pluralize, 'adminpanel_file_field')
168
+ end
171
169
 
172
- def belongs_to_form_hash
173
- attribute_hash(belongs_to_field(@attr_field), 'belongs_to', resource_class_name(@attr_field))
174
- end
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
- def has_many_form_hash
177
- attribute_hash(has_many_field(resource_class_name(@attr_field)), 'has_many', 'has_many model')
178
- end
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
- def attribute_hash(name, type, model = '')
181
- if model != ''
182
- model = model_type(model) + ",\n"
183
- end
184
- "{\n" +
185
- indent("'#{name}'" + " => {\n", 2) +
186
- indent(form_type(type), 4) + ",\n" +
187
- indent(label_type, 4) + ",\n" +
188
- indent(placeholder_type, 4) + ",\n" +
189
- indent(model, 4) +
190
- indent("}\n", 2) +
191
- '}'
192
- end
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
- def form_type(type)
195
- "'type' => '#{type}'"
196
- end
192
+ def form_type(type)
193
+ "'type' => '#{type}'"
194
+ end
197
195
 
198
- def label_type
199
- "'label' => '#{@attr_field}'"
200
- end
196
+ def label_type
197
+ "'label' => '#{@attr_field}'"
198
+ end
201
199
 
202
- def placeholder_type
203
- "'placeholder' => '#{@attr_field}'"
204
- end
200
+ def placeholder_type
201
+ "'placeholder' => '#{@attr_field}'"
202
+ end
205
203
 
206
- def model_type(type)
207
- "'model' => 'Adminpanel::#{type}'"
208
- end
204
+ def model_type(type)
205
+ "'model' => 'Adminpanel::#{type}'"
206
+ end
209
207
 
210
- def has_associations?
211
- fields.each do |attribute|
212
- assign_attributes_variables(attribute)
213
- if @attr_type == "images" || @attr_type == "belongs_to" || @attr_type == "has_many" || @attr_type == "has_many_through"
214
- return true
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
- def associations
221
- association = ""
222
- fields.each do |attribute|
223
- assign_attributes_variables(attribute)
224
- if @attr_type == "belongs_to"
225
- association = "#{association}#{belongs_to_association(@attr_field)}"
226
- elsif @attr_type == "has_many" || @attr_type == "has_many_through"
227
- association = "#{association}#{has_many_association(@attr_field)}"
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
- def has_many_association(field)
239
- return "# has_many :categorizations\n\t\t" +
240
- "# has_many :#{@attr_field}, " +
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
- def get_gallery
246
- return "\n\t\tmount_images :#{gallery_name.pluralize}\n"
247
- end
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