ecm_sliders2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +35 -0
  4. data/Rakefile +27 -0
  5. data/app/helpers/ecm/sliders_helper.rb +10 -0
  6. data/app/helpers/markup_helper.rb +7 -0
  7. data/app/models/ecm/sliders/item.rb +36 -0
  8. data/app/models/ecm/sliders/slider.rb +40 -0
  9. data/app/views/ecm/sliders/sliders/_slider.haml +3 -0
  10. data/config/locales/de.yml +52 -0
  11. data/config/locales/en.yml +52 -0
  12. data/config/routes.rb +6 -0
  13. data/db/migrate/001_create_ecm_sliders_sliders.rb +14 -0
  14. data/db/migrate/002_create_ecm_sliders_items.rb +14 -0
  15. data/lib/ecm/sliders/configuration.rb +23 -0
  16. data/lib/ecm/sliders/engine.rb +7 -0
  17. data/lib/ecm/sliders/routing.rb +14 -0
  18. data/lib/ecm/sliders/version.rb +6 -0
  19. data/lib/ecm_sliders2.rb +17 -0
  20. data/lib/generators/ecm/sliders/install/install_generator.rb +21 -0
  21. data/lib/generators/ecm/sliders/install/templates/initializer.rb +39 -0
  22. data/lib/generators/ecm/sliders/install/templates/routes.source +5 -0
  23. data/lib/tasks/ecm_sliders_tasks.rake +67 -0
  24. data/spec/controllers/ecm/sliders/sliders_controller_spec.rb +23 -0
  25. data/spec/dummy/README.rdoc +261 -0
  26. data/spec/dummy/Rakefile +7 -0
  27. data/spec/dummy/app/admin/admin_users.rb +20 -0
  28. data/spec/dummy/app/admin/dashboards.rb +33 -0
  29. data/spec/dummy/app/assets/javascripts/active_admin.js +1 -0
  30. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  31. data/spec/dummy/app/assets/javascripts/bootstrap.min.js +6 -0
  32. data/spec/dummy/app/assets/stylesheets/active_admin.css.scss +29 -0
  33. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  34. data/spec/dummy/app/assets/stylesheets/bootstrap.min.css +727 -0
  35. data/spec/dummy/app/assets/stylesheets/ecm.sliders.css +9 -0
  36. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  37. data/spec/dummy/app/helpers/application_helper.rb +7 -0
  38. data/spec/dummy/app/models/admin_user.rb +11 -0
  39. data/spec/dummy/app/views/layouts/application.html.erb +37 -0
  40. data/spec/dummy/config.ru +4 -0
  41. data/spec/dummy/config/application.rb +69 -0
  42. data/spec/dummy/config/boot.rb +10 -0
  43. data/spec/dummy/config/database.yml +25 -0
  44. data/spec/dummy/config/environment.rb +5 -0
  45. data/spec/dummy/config/environments/development.rb +37 -0
  46. data/spec/dummy/config/environments/production.rb +67 -0
  47. data/spec/dummy/config/environments/test.rb +37 -0
  48. data/spec/dummy/config/initializers/active_admin.rb +154 -0
  49. data/spec/dummy/config/initializers/active_admin_footer_patch.rb +12 -0
  50. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/spec/dummy/config/initializers/devise.rb +232 -0
  52. data/spec/dummy/config/initializers/ecm_sliders.rb +39 -0
  53. data/spec/dummy/config/initializers/inflections.rb +15 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  56. data/spec/dummy/config/initializers/session_store.rb +8 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/de.yml +163 -0
  59. data/spec/dummy/config/locales/devise.en.yml +58 -0
  60. data/spec/dummy/config/locales/en.yml +5 -0
  61. data/spec/dummy/config/routes.rb +65 -0
  62. data/spec/dummy/db/migrate/20120922100801_create_ecm_sliders_sliders.ecm_sliders_engine.rb +20 -0
  63. data/spec/dummy/db/migrate/20120922100802_create_ecm_sliders_items.ecm_sliders_engine.rb +25 -0
  64. data/spec/dummy/db/migrate/20120922105221_devise_create_admin_users.rb +52 -0
  65. data/spec/dummy/db/migrate/20120922105247_create_admin_notes.rb +17 -0
  66. data/spec/dummy/db/migrate/20120922105248_move_admin_notes_to_comments.rb +25 -0
  67. data/spec/dummy/db/schema.rb +75 -0
  68. data/spec/dummy/lib/locale_generator.rb +194 -0
  69. data/spec/dummy/lib/tasks/stub_locales.rake +32 -0
  70. data/spec/dummy/public/404.html +26 -0
  71. data/spec/dummy/public/422.html +26 -0
  72. data/spec/dummy/public/500.html +25 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/spec/dummy/script/rails +6 -0
  75. data/spec/factories/ecm/sliders/items.rb +14 -0
  76. data/spec/factories/ecm/sliders/sliders.rb +10 -0
  77. data/spec/features/ecm/sliders/slider_items_admin_spec.rb +172 -0
  78. data/spec/features/ecm/sliders/sliders_admin_spec.rb +170 -0
  79. data/spec/files/ecm/sliders/items/example.png +0 -0
  80. data/spec/helpers/ecm/sliders_helper_spec.rb +36 -0
  81. data/spec/models/ecm/sliders/item_spec.rb +49 -0
  82. data/spec/models/ecm/sliders/slider_spec.rb +97 -0
  83. data/spec/models/generic_spec.rb +34 -0
  84. data/spec/requests/ecm/sliders/sliders_spec.rb +28 -0
  85. data/spec/routing/ecm/sliders/routes_spec.rb +11 -0
  86. data/spec/spec_helper.rb +38 -0
  87. data/spec/support/active_admin/sign_in_helper.rb +18 -0
  88. data/spec/support/capybara.rb +1 -0
  89. data/spec/support/factory_girl.rb +6 -0
  90. data/spec/support/ffaker.rb +1 -0
  91. data/spec/support/shoulda.rb +1 -0
  92. data/spec/views/ecm/sliders/sliders/index_spec.rb +20 -0
  93. metadata +344 -0
@@ -0,0 +1,58 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ errors:
5
+ messages:
6
+ expired: "has expired, please request a new one"
7
+ not_found: "not found"
8
+ already_confirmed: "was already confirmed, please try signing in"
9
+ not_locked: "was not locked"
10
+ not_saved:
11
+ one: "1 error prohibited this %{resource} from being saved:"
12
+ other: "%{count} errors prohibited this %{resource} from being saved:"
13
+
14
+ devise:
15
+ failure:
16
+ already_authenticated: 'You are already signed in.'
17
+ unauthenticated: 'You need to sign in or sign up before continuing.'
18
+ unconfirmed: 'You have to confirm your account before continuing.'
19
+ locked: 'Your account is locked.'
20
+ invalid: 'Invalid email or password.'
21
+ invalid_token: 'Invalid authentication token.'
22
+ timeout: 'Your session expired, please sign in again to continue.'
23
+ inactive: 'Your account was not activated yet.'
24
+ sessions:
25
+ signed_in: 'Signed in successfully.'
26
+ signed_out: 'Signed out successfully.'
27
+ passwords:
28
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
29
+ updated: 'Your password was changed successfully. You are now signed in.'
30
+ updated_not_active: 'Your password was changed successfully.'
31
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
32
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
33
+ confirmations:
34
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
35
+ send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
36
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
37
+ registrations:
38
+ signed_up: 'Welcome! You have signed up successfully.'
39
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
40
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
41
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
42
+ updated: 'You updated your account successfully.'
43
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
44
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
45
+ unlocks:
46
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
47
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
48
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
49
+ omniauth_callbacks:
50
+ success: 'Successfully authenticated from %{kind} account.'
51
+ failure: 'Could not authenticate you from %{kind} because "%{reason}".'
52
+ mailer:
53
+ confirmation_instructions:
54
+ subject: 'Confirmation instructions'
55
+ reset_password_instructions:
56
+ subject: 'Reset password instructions'
57
+ unlock_instructions:
58
+ subject: 'Unlock Instructions'
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,65 @@
1
+ Dummy::Application.routes.draw do
2
+ ActiveAdmin.routes(self)
3
+
4
+ devise_for :admin_users, ActiveAdmin::Devise.config
5
+
6
+ Ecm::Sliders::Routing.routes(self)
7
+
8
+ root :to => "ecm/sliders/sliders#index"
9
+ # The priority is based upon order of creation:
10
+ # first created -> highest priority.
11
+
12
+ # Sample of regular route:
13
+ # match 'products/:id' => 'catalog#view'
14
+ # Keep in mind you can assign values other than :controller and :action
15
+
16
+ # Sample of named route:
17
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
18
+ # This route can be invoked with purchase_url(:id => product.id)
19
+
20
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
21
+ # resources :products
22
+
23
+ # Sample resource route with options:
24
+ # resources :products do
25
+ # member do
26
+ # get 'short'
27
+ # post 'toggle'
28
+ # end
29
+ #
30
+ # collection do
31
+ # get 'sold'
32
+ # end
33
+ # end
34
+
35
+ # Sample resource route with sub-resources:
36
+ # resources :products do
37
+ # resources :comments, :sales
38
+ # resource :seller
39
+ # end
40
+
41
+ # Sample resource route with more complex sub-resources
42
+ # resources :products do
43
+ # resources :comments
44
+ # resources :sales do
45
+ # get 'recent', :on => :collection
46
+ # end
47
+ # end
48
+
49
+ # Sample resource route within a namespace:
50
+ # namespace :admin do
51
+ # # Directs /admin/products/* to Admin::ProductsController
52
+ # # (app/controllers/admin/products_controller.rb)
53
+ # resources :products
54
+ # end
55
+
56
+ # You can have the root of your site routed with "root"
57
+ # just remember to delete public/index.html.
58
+ # root :to => 'welcome#index'
59
+
60
+ # See how all your routes lay out with "rake routes"
61
+
62
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
63
+ # Note: This route will make all actions in every controller accessible via GET requests.
64
+ # match ':controller(/:action(/:id))(.:format)'
65
+ end
@@ -0,0 +1,20 @@
1
+ # This migration comes from ecm_sliders_engine (originally 1)
2
+ class CreateEcmSlidersSliders < ActiveRecord::Migration[4.2]
3
+ def change
4
+ create_table :ecm_sliders_sliders do |t|
5
+ t.string :locale
6
+ t.string :name
7
+ t.text :description
8
+ t.boolean :auto_start
9
+ t.decimal :interval, :precision => 8, :scale => 2
10
+
11
+ # friendly id
12
+ t.string :slug
13
+
14
+ # associations
15
+ t.integer :ecm_sliders_items_count, :default => 0, :null => false
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # This migration comes from ecm_sliders_engine (originally 2)
2
+ class CreateEcmSlidersItems < ActiveRecord::Migration[4.2]
3
+ def change
4
+ create_table :ecm_sliders_items do |t|
5
+ t.text :body
6
+ t.string :url
7
+ t.integer :position
8
+
9
+ # acts as markup
10
+ t.string :markup_language
11
+
12
+ # associations
13
+ t.references :ecm_sliders_slider
14
+
15
+ # paperclip
16
+ t.string :image_file_name
17
+ t.integer :image_file_size
18
+ t.string :image_content_type
19
+ t.timestamp :image_updated_at
20
+ t.string :image_fingerprint
21
+
22
+ t.timestamps
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,52 @@
1
+ class DeviseCreateAdminUsers < ActiveRecord::Migration[4.2]
2
+ def migrate(direction)
3
+ super
4
+ # Create a default user
5
+ AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password') if direction == :up
6
+ end
7
+
8
+ def change
9
+ create_table(:admin_users) do |t|
10
+ ## Database authenticatable
11
+ t.string :email, :null => false, :default => ""
12
+ t.string :encrypted_password, :null => false, :default => ""
13
+
14
+ ## Recoverable
15
+ t.string :reset_password_token
16
+ t.datetime :reset_password_sent_at
17
+
18
+ ## Rememberable
19
+ t.datetime :remember_created_at
20
+
21
+ ## Trackable
22
+ t.integer :sign_in_count, :default => 0
23
+ t.datetime :current_sign_in_at
24
+ t.datetime :last_sign_in_at
25
+ t.string :current_sign_in_ip
26
+ t.string :last_sign_in_ip
27
+
28
+ ## Confirmable
29
+ # t.string :confirmation_token
30
+ # t.datetime :confirmed_at
31
+ # t.datetime :confirmation_sent_at
32
+ # t.string :unconfirmed_email # Only if using reconfirmable
33
+
34
+ ## Lockable
35
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
36
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
37
+ # t.datetime :locked_at
38
+
39
+ ## Token authenticatable
40
+ # t.string :authentication_token
41
+
42
+
43
+ t.timestamps
44
+ end
45
+
46
+ add_index :admin_users, :email, :unique => true
47
+ add_index :admin_users, :reset_password_token, :unique => true
48
+ # add_index :admin_users, :confirmation_token, :unique => true
49
+ # add_index :admin_users, :unlock_token, :unique => true
50
+ # add_index :admin_users, :authentication_token, :unique => true
51
+ end
52
+ end
@@ -0,0 +1,17 @@
1
+ class CreateAdminNotes < ActiveRecord::Migration[4.2]
2
+ def self.up
3
+ create_table :admin_notes do |t|
4
+ t.string :resource_id, :null => false
5
+ t.string :resource_type, :null => false
6
+ t.references :admin_user, :polymorphic => true
7
+ t.text :body
8
+ t.timestamps
9
+ end
10
+ add_index :admin_notes, [:resource_type, :resource_id]
11
+ add_index :admin_notes, [:admin_user_type, :admin_user_id]
12
+ end
13
+
14
+ def self.down
15
+ drop_table :admin_notes
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ class MoveAdminNotesToComments < ActiveRecord::Migration[4.2]
2
+ def self.up
3
+ remove_index :admin_notes, [:admin_user_type, :admin_user_id]
4
+ rename_table :admin_notes, :active_admin_comments
5
+ rename_column :active_admin_comments, :admin_user_type, :author_type
6
+ rename_column :active_admin_comments, :admin_user_id, :author_id
7
+ add_column :active_admin_comments, :namespace, :string
8
+ add_index :active_admin_comments, [:namespace]
9
+ add_index :active_admin_comments, [:author_type, :author_id]
10
+
11
+ # Update all the existing comments to the default namespace
12
+ say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
13
+ execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'"
14
+ end
15
+
16
+ def self.down
17
+ remove_index :active_admin_comments, :column => [:author_type, :author_id]
18
+ remove_index :active_admin_comments, :column => [:namespace]
19
+ remove_column :active_admin_comments, :namespace
20
+ rename_column :active_admin_comments, :author_id, :admin_user_id
21
+ rename_column :active_admin_comments, :author_type, :admin_user_type
22
+ rename_table :active_admin_comments, :admin_notes
23
+ add_index :admin_notes, [:admin_user_type, :admin_user_id]
24
+ end
25
+ end
@@ -0,0 +1,75 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20120922105248) do
14
+
15
+ create_table "active_admin_comments", :force => true do |t|
16
+ t.string "resource_id", :null => false
17
+ t.string "resource_type", :null => false
18
+ t.integer "author_id"
19
+ t.string "author_type"
20
+ t.text "body"
21
+ t.datetime "created_at", :null => false
22
+ t.datetime "updated_at", :null => false
23
+ t.string "namespace"
24
+ end
25
+
26
+ add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id"
27
+ add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace"
28
+ add_index "active_admin_comments", ["resource_type", "resource_id"], :name => "index_admin_notes_on_resource_type_and_resource_id"
29
+
30
+ create_table "admin_users", :force => true do |t|
31
+ t.string "email", :default => "", :null => false
32
+ t.string "encrypted_password", :default => "", :null => false
33
+ t.string "reset_password_token"
34
+ t.datetime "reset_password_sent_at"
35
+ t.datetime "remember_created_at"
36
+ t.integer "sign_in_count", :default => 0
37
+ t.datetime "current_sign_in_at"
38
+ t.datetime "last_sign_in_at"
39
+ t.string "current_sign_in_ip"
40
+ t.string "last_sign_in_ip"
41
+ t.datetime "created_at", :null => false
42
+ t.datetime "updated_at", :null => false
43
+ end
44
+
45
+ add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
46
+ add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
47
+
48
+ create_table "ecm_sliders_items", :force => true do |t|
49
+ t.text "body"
50
+ t.string "url"
51
+ t.integer "position"
52
+ t.string "markup_language"
53
+ t.integer "ecm_sliders_slider_id"
54
+ t.string "image_file_name"
55
+ t.integer "image_file_size"
56
+ t.string "image_content_type"
57
+ t.datetime "image_updated_at"
58
+ t.string "image_fingerprint"
59
+ t.datetime "created_at", :null => false
60
+ t.datetime "updated_at", :null => false
61
+ end
62
+
63
+ create_table "ecm_sliders_sliders", :force => true do |t|
64
+ t.string "locale"
65
+ t.string "name"
66
+ t.text "description"
67
+ t.boolean "auto_start"
68
+ t.decimal "interval", :precision => 8, :scale => 2
69
+ t.string "slug"
70
+ t.integer "ecm_sliders_items_count", :default => 0, :null => false
71
+ t.datetime "created_at", :null => false
72
+ t.datetime "updated_at", :null => false
73
+ end
74
+
75
+ end
@@ -0,0 +1,194 @@
1
+ class Hash
2
+ def dig(*path)
3
+ path.inject(self) do |location, key|
4
+ location.respond_to?(:keys) ? location[key] : nil
5
+ end
6
+ end
7
+ end
8
+
9
+ class LocaleGenerator
10
+ attr_accessor :model_constant, :instance, :existing_content, :locale, :new_locale
11
+
12
+ def initialize(model_constant, locale)
13
+ @model_constant = model_constant
14
+ @locale = locale
15
+ @instance = @model_constant.new
16
+ @existing_content = {}
17
+ @new_locale = true
18
+
19
+ load_file
20
+ end
21
+
22
+ # Gets the attribute names from the active record model without 'id'
23
+ def new_attribute_translation_keys
24
+ model_constant.attribute_names.sort.delete_if {|key, value| key == 'id' }
25
+ end
26
+
27
+ # Returns a hash with attribute names and empty translations
28
+ def new_attributes_hashed
29
+ new_attribute_translation_keys.reduce({}) { |h, a| h.merge({ a => nil} ) }
30
+ end
31
+
32
+ # Returns the model name for the translation hash
33
+ def model_name_for_translation
34
+ model_constant.to_s.underscore
35
+ end
36
+
37
+ # fresh from the database
38
+ def new_translations_full_hash
39
+ {
40
+ locale.to_s => {
41
+ "activerecord" => {
42
+ "attributes" => {
43
+ model_name_for_translation => new_attributes_hashed
44
+ },
45
+ "models" => {
46
+ model_name_for_translation => {
47
+ "one" => nil,
48
+ "other" => nil
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ end
55
+
56
+ # returns a hash with new attributes
57
+ def new_translations_attributes
58
+ new_translations_full_hash.dig(locale.to_s, 'activerecord', 'attributes', model_name_for_translation)
59
+ end
60
+
61
+ # returns an array with new attribute names
62
+ def new_translations_attributes_keys
63
+ new_translations_attributes.keys
64
+ end
65
+
66
+ # returns a hash with new model names
67
+ def new_translations_model_names
68
+ new_translations_full_hash.dig(locale.to_s, 'activerecord', 'models', model_name_for_translation)
69
+ end
70
+
71
+ # returns an array with new model names
72
+ def new_translations_model_name_keys
73
+ new_translations_model_names.keys
74
+ end
75
+
76
+ # creates a suiting filename for the model
77
+ def filename
78
+ File.join("config", "locales", model_constant.to_s.underscore.gsub('/', '.') + "." + locale.to_s + ".yml")
79
+ end
80
+
81
+ # loads the translations from file
82
+ def load_file
83
+ return false unless File.exists?(filename)
84
+ self.existing_content = YAML.load_file(filename)
85
+ self.new_locale = false
86
+ return true
87
+ end
88
+
89
+ # Returns true if no suiting locale file was found
90
+ def new_locale?
91
+ new_locale
92
+ end
93
+
94
+ # Saves the merged translations to a locale file
95
+ def save_file
96
+ File.open(filename, 'w') do |out|
97
+ YAML.dump(merged_translations_full_hash, out)
98
+ end
99
+ end
100
+
101
+ # Returns the complete hash of existing (loaded) translations
102
+ def existing_translations_full_hash
103
+ existing_content
104
+ end
105
+
106
+ # Returns a hash with the existing attribute translations
107
+ def existing_translations_attributes
108
+ existing_translations_attributes = existing_content.dig(locale.to_s, 'activerecord', 'attributes', model_name_for_translation) if existing_content.respond_to?(:dig)
109
+ if existing_translations_attributes.nil?
110
+ return {}
111
+ else
112
+ return existing_translations_attributes
113
+ end
114
+ end
115
+
116
+ # Returns a hash with the existing model names
117
+ def existing_model_names
118
+ existing_model_names = existing_content.dig(locale.to_s, 'activerecord', 'models', model_name_for_translation) if existing_content.respond_to?(:dig)
119
+ if existing_model_names.nil?
120
+ return { "one" => nil, "other" => nil }
121
+ else
122
+ return existing_model_names
123
+ end
124
+ end
125
+
126
+ # Returns an array with the existing attribute keys
127
+ def existing_translations_attributes_keys
128
+ existing_translations_attributes.keys
129
+ end
130
+
131
+ # Returns an array with the existing model_names
132
+ def existing_model_names_keys
133
+ existing_model_names.keys
134
+ end
135
+
136
+ # # Returns the hash with existing (loaded) model names or an empty hash.
137
+ # def existing_translations_model_names
138
+ # existing_translations_model_names = existing_translations_full_hash.dig(locale.to_s, "activerecord", "models")
139
+ # if existing_translations_model_names.nil?
140
+ # return {}
141
+ # else
142
+ # return existing_translations_model_names
143
+ # end
144
+ # end
145
+
146
+ # returns new attribute keys that are not present in the existent (loaded) attribute keys.
147
+ def new_attribute_keys
148
+ new_translations_attributes_keys - existing_translations_attributes_keys
149
+ end
150
+
151
+ # returns the number of new attribute keys
152
+ def has_new_attribute_keys
153
+ new_attribute_keys.size > 0
154
+ end
155
+
156
+ # returns new model names that are not present in the existent (loaded) model names.
157
+ def new_model_names
158
+ new_translations_model_name_keys - existing_model_names_keys
159
+ end
160
+
161
+ # returns the number of new attribute keys
162
+ def has_new_model_names
163
+ new_model_names.size > 0
164
+ end
165
+
166
+ # TODO: Add methods to merge existing and new attribs
167
+ def merged_translations_attributes_keys
168
+ (existing_translations_attributes_keys + new_translations_attributes_keys).uniq
169
+ end
170
+
171
+ def merged_translations_attributes
172
+ existing_translations_attributes.merge( new_attribute_keys.reduce({}) { |h, a| h.merge({ a => nil }) } )
173
+ end
174
+
175
+ def merged_model_names
176
+ existing_model_names.merge( new_model_names.reduce({}) { |h, a| h.merge({ a => nil }) } )
177
+ end
178
+
179
+ def merged_translations_full_hash
180
+ {
181
+ locale.to_s => {
182
+ "activerecord" => {
183
+ "attributes" => {
184
+ model_name_for_translation => merged_translations_attributes
185
+ },
186
+ "models" => {
187
+ model_name_for_translation => merged_model_names
188
+ }
189
+ }
190
+ }
191
+ }
192
+ end
193
+ end
194
+