weeler 1.5.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +3 -14
  4. data/CHANGELOG.md +43 -0
  5. data/Gemfile +3 -0
  6. data/README.md +30 -37
  7. data/Rakefile +4 -4
  8. data/app/assets/javascripts/weeler/init.js +32 -0
  9. data/app/assets/stylesheets/weeler/style.css.scss +7 -1
  10. data/app/controllers/concerns/weeler/section_seo.rb +1 -1
  11. data/app/controllers/weeler/base_controller.rb +2 -2
  12. data/app/controllers/weeler/seo_items_controller.rb +3 -2
  13. data/app/controllers/weeler/settings_controller.rb +27 -9
  14. data/app/controllers/weeler/static_sections_controller.rb +2 -2
  15. data/app/controllers/weeler/translations_controller.rb +5 -19
  16. data/app/models/setting.rb +7 -0
  17. data/app/views/kaminari/weeler/_first_page.html.haml +3 -0
  18. data/app/views/kaminari/weeler/_gap.html.haml +2 -0
  19. data/app/views/kaminari/weeler/_last_page.html.haml +3 -0
  20. data/app/views/kaminari/weeler/_next_page.html.haml +3 -0
  21. data/app/views/kaminari/weeler/_page.html.haml +2 -0
  22. data/app/views/kaminari/weeler/_paginator.html.haml +11 -0
  23. data/app/views/kaminari/weeler/_prev_page.html.haml +3 -0
  24. data/app/views/weeler/base/_footer.html.haml +1 -1
  25. data/app/views/weeler/settings/_form.html.haml +16 -0
  26. data/app/views/weeler/settings/index.html.haml +5 -8
  27. data/app/views/weeler/static_sections/show.html.haml +5 -1
  28. data/app/views/weeler/translations/_form.html.haml +5 -2
  29. data/app/views/weeler/translations/index.html.haml +0 -10
  30. data/lib/generators/weeler/templates/assets/javascripts/weeler/app/index.js +3 -1
  31. data/lib/generators/weeler/templates/assets/stylesheets/weeler/app/index.css +1 -1
  32. data/lib/generators/weeler/templates/controllers/weeler/application_controller.rb +1 -1
  33. data/lib/i18n/backend/weeler/exporter.rb +32 -14
  34. data/lib/i18n/backend/weeler/importer.rb +57 -54
  35. data/lib/i18n/backend/weeler.rb +15 -26
  36. data/lib/weeler/action_controller/acts/restful.rb +4 -4
  37. data/lib/weeler/action_dispatch/routing/mapper.rb +1 -2
  38. data/lib/weeler/action_view/helpers/translation_helper.rb +2 -2
  39. data/lib/weeler/engine.rb +0 -3
  40. data/lib/weeler/version.rb +3 -3
  41. data/lib/weeler.rb +8 -3
  42. data/spec/.DS_Store +0 -0
  43. data/spec/controllers/translations_controller_spec.rb +16 -16
  44. data/spec/dummy/.ruby-version +1 -0
  45. data/spec/dummy/Rakefile +2 -2
  46. data/spec/dummy/app/assets/config/manifest.js +3 -0
  47. data/spec/dummy/app/assets/stylesheets/application.css +6 -4
  48. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  49. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  50. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  51. data/spec/dummy/app/{assets/javascripts → javascript/packs}/application.js +5 -3
  52. data/spec/dummy/app/jobs/application_job.rb +7 -0
  53. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  54. data/spec/dummy/app/models/application_record.rb +3 -0
  55. data/spec/dummy/app/models/post.rb +1 -1
  56. data/spec/dummy/app/views/layouts/application.html.erb +9 -9
  57. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  58. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  59. data/spec/dummy/bin/rails +1 -1
  60. data/spec/dummy/bin/setup +33 -0
  61. data/spec/dummy/config/application.rb +19 -13
  62. data/spec/dummy/config/boot.rb +3 -3
  63. data/spec/dummy/config/cable.yml +10 -0
  64. data/spec/dummy/config/database.yml +1 -0
  65. data/spec/dummy/config/environment.rb +2 -2
  66. data/spec/dummy/config/environments/development.rb +38 -5
  67. data/spec/dummy/config/environments/production.rb +64 -32
  68. data/spec/dummy/config/environments/test.rb +21 -9
  69. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  70. data/spec/dummy/config/initializers/assets.rb +12 -0
  71. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  72. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  73. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  74. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  75. data/spec/dummy/config/puma.rb +38 -0
  76. data/spec/dummy/config/spring.rb +6 -0
  77. data/spec/dummy/config/storage.yml +34 -0
  78. data/spec/dummy/config.ru +2 -1
  79. data/spec/dummy/db/migrate/20140123083704_create_weeler_seos.rb +1 -1
  80. data/spec/dummy/db/migrate/20140123083705_create_weeler_settings.rb +1 -1
  81. data/spec/dummy/db/migrate/20140123083706_create_weeler_translations.rb +1 -1
  82. data/spec/dummy/db/migrate/20140123083707_translate_weeler_seos.rb +1 -1
  83. data/spec/dummy/db/migrate/20140718103237_create_posts.rb +1 -1
  84. data/spec/dummy/db/migrate/20140726151210_create_translations.rb +1 -1
  85. data/spec/dummy/db/migrate/20160330161101_create_weeler_locks.rb +1 -1
  86. data/spec/dummy/db/migrate/20160330192005_create_weeler_translation_stats.rb +1 -1
  87. data/spec/dummy/db/schema.rb +56 -64
  88. data/spec/dummy/{app/mailers/.keep → db/test.sqlite3} +0 -0
  89. data/spec/dummy/log/development.log +0 -1020
  90. data/spec/dummy/public/404.html +24 -15
  91. data/spec/dummy/public/422.html +24 -15
  92. data/spec/dummy/public/500.html +23 -14
  93. data/spec/dummy/{app/models/.keep → public/apple-touch-icon-precomposed.png} +0 -0
  94. data/spec/dummy/public/apple-touch-icon.png +0 -0
  95. data/spec/dummy/storage/.keep +0 -0
  96. data/spec/factories/dummy_posts.rb +3 -3
  97. data/spec/factories/translations.rb +4 -4
  98. data/spec/fixtures/test_2020_format.xlsx +0 -0
  99. data/spec/spec_helper.rb +7 -5
  100. data/spec/weeler/action_controller/acts/restful_spec.rb +15 -16
  101. data/spec/weeler/i18n/backend/weeler/exporter_spec.rb +6 -0
  102. data/spec/weeler/i18n/backend/weeler/importer_spec.rb +17 -6
  103. data/spec/weeler/i18n/backend/weeler_spec.rb +55 -70
  104. data/spec/weeler/i18n/humanize_missing_translations_spec.rb +14 -11
  105. data/weeler.gemspec +18 -13
  106. metadata +103 -65
  107. data/app/assets/javascripts/weeler/init.js.coffee +0 -26
  108. data/app/models/settings.rb +0 -2
  109. data/app/views/kaminari/weeler/_first_page.html.erb +0 -13
  110. data/app/views/kaminari/weeler/_gap.html.erb +0 -8
  111. data/app/views/kaminari/weeler/_last_page.html.erb +0 -13
  112. data/app/views/kaminari/weeler/_next_page.html.erb +0 -14
  113. data/app/views/kaminari/weeler/_page.html.erb +0 -12
  114. data/app/views/kaminari/weeler/_paginator.html.erb +0 -23
  115. data/app/views/kaminari/weeler/_prev_page.html.erb +0 -13
  116. data/app/views/weeler/translations/usage_stats.html.haml +0 -34
  117. data/lib/generators/weeler/templates/migrations/create_weeler_translation_stats.rb +0 -11
  118. data/lib/i18n/backend/weeler/usage_logger.rb +0 -35
  119. data/lib/weeler/action_view/helpers/form_helper.rb +0 -13
  120. data/lib/weeler/action_view/helpers/image_form_helper.rb +0 -83
  121. data/spec/dummy/README.rdoc +0 -28
  122. data/spec/dummy/bin/bundle +0 -3
  123. data/spec/dummy/config/initializers/secret_token.rb +0 -12
  124. data/spec/dummy/config/initializers/session_store.rb +0 -3
  125. data/spec/dummy/log/production.log +0 -4
  126. data/spec/weeler/action_view/helpers/form_helper_spec.rb +0 -35
  127. data/spec/weeler/i18n/backend/weeler/usage_logger_spec.rb +0 -34
@@ -25,7 +25,6 @@ module I18n
25
25
  extend ActiveSupport::Concern
26
26
 
27
27
  module ClassMethods
28
-
29
28
  # Prepare xlsx package from current scope
30
29
  # Stores all translations in translations worksheet.
31
30
  def as_xlsx_package
@@ -42,33 +41,52 @@ module I18n
42
41
 
43
42
  included_keys = []
44
43
 
45
- self.current_scope.each do |translation|
46
- unless included_keys.include? translation.key
47
- sheet.add_row(Translation.translation_row_by_key_and_locales(translation.key, locales), types: types)
48
- included_keys << translation.key
49
- end
44
+ tranlsations_by_locales = Translation.where(locale: locales).group_by(&:locale)
45
+
46
+ current_scope.each do |translation|
47
+ next if included_keys.include?(translation.key)
48
+
49
+ row = Translation.translation_row_by_key_and_locales(tranlsations_by_locales, translation.key, locales)
50
+ sheet.add_row(row, types: types)
51
+ included_keys << translation.key
50
52
  end
51
- return package
53
+
54
+ package
52
55
  end
53
56
 
54
- def title_row locales
57
+ def title_row(locales)
55
58
  row = [ 'Key' ]
56
59
  locales.each do |locale|
57
60
  row.push(locale.capitalize)
58
61
  end
62
+
63
+ row.push('Created at')
64
+ row.push('Updated at')
65
+
59
66
  row
60
67
  end
61
68
 
62
- def translation_row_by_key_and_locales key, locales
63
- row = [ key ]
69
+ def translation_row_by_key_and_locales(tranlsations_by_locales, key, locales)
70
+ row = [key]
71
+ created_ats = []
72
+ updated_ats = []
73
+
64
74
  locales.each do |locale|
65
- result = Translation.locale(locale).lookup(key).load
66
- if result.first.present?
67
- row.push(result.first.value)
75
+ translation = tranlsations_by_locales[locale.to_s]&.find { |t| t.key == key }
76
+
77
+ if translation.present?
78
+ created_ats.push(translation.created_at)
79
+ updated_ats.push(translation.updated_at)
80
+
81
+ row.push(translation.value)
68
82
  else
69
- row.push("")
83
+ row.push('')
70
84
  end
71
85
  end
86
+
87
+ row.push(created_ats.min)
88
+ row.push(updated_ats.max)
89
+
72
90
  row
73
91
  end
74
92
  end
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # if params[:file].present?
7
7
  # I18n::Backend::Weeler::Translation.import params[:file]
8
- # Settings.i18n_updated_at = Time.now
8
+ # Setting.i18n_updated_at = Time.now
9
9
  # end
10
10
 
11
11
  begin
@@ -17,82 +17,85 @@ end
17
17
  module I18n
18
18
  module Backend
19
19
  class Weeler
20
-
21
20
  module Importer
22
21
  extend ActiveSupport::Concern
23
22
 
24
23
  module ClassMethods
25
-
26
24
  # Loads file and iterates each sheet and row.
27
- def import file
28
- xls = open_spreadsheet file
29
- xls.each_with_pagename do |name, sheet|
25
+ def import(file)
26
+ xls = open_spreadsheet(file)
30
27
 
28
+ xls.each_with_pagename do |_, sheet|
31
29
  # Lookup locales
32
30
  locales = locales_from_xlsx_sheet_row(sheet.row(1))
31
+ tranlsations_by_locales = Translation.where(locale: locales).group_by(&:locale)
33
32
 
34
33
  # Lookup values
35
34
  (2..sheet.last_row).each do |row_no|
36
- store_translations_from_xlsx_row(sheet.row(row_no), locales)
37
- end # rows
38
-
39
- end # sheets
40
-
41
- end # import
35
+ store_translations_from_xlsx_row(tranlsations_by_locales, sheet.row(row_no), locales)
36
+ end
37
+ end
38
+ end
42
39
 
43
40
  private
44
41
 
45
- # Open csv, xls, xlsx or ods file and read content
46
- def open_spreadsheet(file)
47
- case File.extname(file.original_filename)
48
- when ".csv" then Roo::Csv.new(file.path, file_warning: :ignore)
49
- when ".xls" then Roo::Excel.new(file.path, file_warning: :ignore)
50
- when ".xlsx" then Roo::Excelx.new(file.path, file_warning: :ignore)
51
- when ".ods" then Roo::OpenOffice.new(file.path, file_warning: :ignore)
52
- else raise "Unknown file type: #{file.original_filename}"
53
- end
42
+ # Open csv, xls, xlsx or ods file and read content
43
+ def open_spreadsheet(file)
44
+ case File.extname(file.original_filename)
45
+ when ".csv" then Roo::Csv.new(file.path, file_warning: :ignore)
46
+ when ".xls" then Roo::Excel.new(file.path, file_warning: :ignore)
47
+ when ".xlsx" then Roo::Excelx.new(file.path, file_warning: :ignore)
48
+ when ".ods" then Roo::OpenOffice.new(file.path, file_warning: :ignore)
49
+ else raise "Unknown file type: #{file.original_filename}"
54
50
  end
51
+ end
55
52
 
56
- # Lookup locales and sequence for loading
57
- def locales_from_xlsx_sheet_row row
58
- locales = []
59
- row.each_with_index do |cell, i|
60
- if i > 0
61
- locales.push(cell.downcase)
62
- end
63
- end
64
- locales
65
- end
53
+ # Lookup locales and sequence for loading
54
+ def locales_from_xlsx_sheet_row(row)
55
+ locales = []
56
+ row.each_with_index do |cell, i|
57
+ next unless i.positive?
66
58
 
67
- # Iterate each cell in row and store translation by locale
68
- def store_translations_from_xlsx_row row, locales
69
- locale = nil
70
- key = nil
71
- value = nil
72
-
73
- row.each_with_index do |cell, i|
74
- if i == 0
75
- key = cell
76
- else
77
- locale = locales[ i - 1 ]
78
- store_translation_from_xlsx_cell locale, key, cell
79
- end
80
- end
59
+ locale = cell.downcase
60
+
61
+ # check if legal local
62
+ next if locale.size != 2
63
+
64
+ locales.push(cell.downcase)
81
65
  end
66
+ locales
67
+ end
68
+
69
+ # Iterate each cell in row and store translation by locale
70
+ def store_translations_from_xlsx_row(tranlsations_by_locales, row, locales)
71
+ locale = nil
72
+ key = nil
82
73
 
83
- # Store locale if locale and key present
84
- def store_translation_from_xlsx_cell locale, key, cell
85
- value = cell.nil? ? '' : cell
74
+ row.each_with_index do |cell, i|
75
+ if i.zero?
76
+ key = cell
77
+ else
78
+ locale = locales[i - 1]
86
79
 
87
- if locale.present? && key.present?
88
- translation = Translation.find_or_initialize_by locale: locale, key: key
89
- if translation.value != value
90
- translation.value = value
91
- translation.save
92
- end
80
+ store_translation_from_xlsx_cell(tranlsations_by_locales[locale.to_s], locale, key, cell) if locale.present?
93
81
  end
94
82
  end
83
+ end
84
+
85
+ # Store locale if locale and key present
86
+ def store_translation_from_xlsx_cell(locale_translations, locale, key, cell)
87
+ value = cell.nil? ? '' : cell
88
+
89
+ return if locale.blank? || key.blank?
90
+
91
+ translation = locale_translations&.find { |t| t.key == key }
92
+
93
+ return if translation.present? && translation.value == value
95
94
 
95
+ translation ||= Translation.new(locale: locale, key: key)
96
+ translation.value = value
97
+ translation.save
98
+ end
96
99
  end
97
100
  end
98
101
 
@@ -4,8 +4,6 @@ require 'i18n/backend/weeler/dedupe'
4
4
  require 'i18n/backend/weeler/html_checker'
5
5
  require 'i18n/backend/weeler/exporter'
6
6
  require 'i18n/backend/weeler/importer'
7
- require 'i18n/backend/weeler/usage_logger'
8
- require 'i18n/backend/weeler/translation_stat'
9
7
  require 'i18n/backend/weeler/lock'
10
8
 
11
9
  module I18n
@@ -31,8 +29,6 @@ module I18n
31
29
  autoload :Translation, 'i18n/backend/weeler/translation'
32
30
  autoload :Exporter, 'i18n/backend/weeler/exporter'
33
31
  autoload :Importer, 'i18n/backend/weeler/importer'
34
- autoload :UsageLogger, 'i18n/backend/weeler/usage_logger'
35
- autoload :TranslationStat, 'i18n/backend/weeler/translation_stat'
36
32
  autoload :Lock, 'i18n/backend/weeler/lock'
37
33
 
38
34
  module Implementation
@@ -52,12 +48,16 @@ module I18n
52
48
  Translation.all.each do |translation|
53
49
  # Load in cache unless value is nil or it is blank and empty
54
50
  # translation acts like missing
55
- if !(translation.value.nil? || (::Weeler.empty_translation_acts_like_missing && translation.value.blank?))
56
- i18n_cache.write [translation.locale, translation.key], translation
57
- end
51
+ next if translation.value.nil? || (::Weeler.empty_translation_acts_like_missing && translation.value.blank?)
52
+
53
+ i18n_cache.write [translation.locale, translation.key], translation
58
54
  end
59
55
 
60
- i18n_cache.write('UPDATED_AT', Settings.i18n_updated_at) if ActiveRecord::Base.connection.table_exists?('settings')
56
+ i18n_cache.write('UPDATED_AT', Setting.i18n_updated_at) if ActiveRecord::Base.connection.data_source_exists?('settings')
57
+ end
58
+
59
+ def available_locales
60
+ I18n::Backend::Weeler::Translation.distinct.pluck(:locale).compact.map(&:to_sym)
61
61
  end
62
62
 
63
63
  protected
@@ -70,26 +70,15 @@ module I18n
70
70
 
71
71
  private
72
72
 
73
- def lookup_in_cache locale, key, scope = [], options = {}
73
+ def lookup_in_cache(locale, key, scope = [], options = {})
74
74
  # reload cache if cache timestamp differs from last translations update
75
- reload_cache if ((!ActiveRecord::Base.connection.table_exists?('settings')) || i18n_cache.read('UPDATED_AT') != Settings.i18n_updated_at)
76
-
77
- # log locale/key usage for statistics
78
- if Settings.log_key_usage == 'true'
79
- i18n_cache.delete([:dump_usage_stats, Process.pid])
80
- log_key_usage(locale, key)
81
- end
82
-
83
- if Settings.log_key_usage == 'dump'
84
- dump_key_usage
85
- end
75
+ reload_cache if ((!ActiveRecord::Base.connection.data_source_exists?('settings')) || i18n_cache.read('UPDATED_AT') != Setting.i18n_updated_at)
86
76
 
87
77
  return nil if i18n_cache.read([:missing, [locale, key]])
88
78
 
89
79
  keys = expand_keys key
90
80
 
91
81
  keys.reverse.each do |check_key|
92
-
93
82
  result = i18n_cache.read([locale, check_key])
94
83
 
95
84
  return result.value unless result.blank?
@@ -118,7 +107,7 @@ module I18n
118
107
  translation = result.first
119
108
  if translation.value.blank?
120
109
  fallback_value = fallback_backend_translation locale, key
121
- translation.update_attributes value: fallback_value if fallback_value.present?
110
+ translation.update value: fallback_value if fallback_value.present?
122
111
  end
123
112
  return translation.value
124
113
  else
@@ -145,10 +134,12 @@ module I18n
145
134
 
146
135
  keys = options[:count] ? PLURAL_KEYS.map { |k| [singular_key, k].join(FLATTEN_SEPARATOR) } : [singular_key]
147
136
 
148
-
149
137
  keys.each do |key|
150
- translation = Weeler::Translation.find_or_initialize_by locale: locale.to_s, key: key
138
+ translation = Weeler::Translation.find_or_initialize_by(locale: locale.to_s, key: key)
151
139
  translation.interpolations = interpolations
140
+
141
+
142
+
152
143
  fallback_value = fallback_backend_translation locale, key
153
144
  if fallback_value.present?
154
145
  translation.value = fallback_value
@@ -162,7 +153,6 @@ module I18n
162
153
  return_value
163
154
  end
164
155
 
165
-
166
156
  def fallback_backend_translation locale, key
167
157
  if I18n.backend.backends.size > 1
168
158
  alternative_backend = I18n.backend.backends[1]
@@ -171,7 +161,6 @@ module I18n
171
161
  nil
172
162
  end
173
163
  end
174
-
175
164
  end
176
165
 
177
166
  include Implementation
@@ -30,7 +30,7 @@ module Weeler
30
30
  # <tt>_filter.html.haml</tt>
31
31
  #
32
32
  def acts_as_restful(active_record_model, options = {})
33
- before_filter(:load_record, only: [:show, :edit, :update, :destroy, :remove_image])
33
+ before_action(:load_record, only: [:show, :edit, :update, :destroy, :remove_image])
34
34
 
35
35
  include InstanceMethodsOnActivation
36
36
  helper_method :item_humanized_name
@@ -90,7 +90,7 @@ module Weeler
90
90
  end
91
91
 
92
92
  def update
93
- if @item.update_attributes(items_params)
93
+ if @item.update(items_params)
94
94
  after_update_action
95
95
  else
96
96
  render :action => 'edit'
@@ -118,7 +118,7 @@ module Weeler
118
118
  permited_params.call(params)
119
119
  elsif permited_params.blank?
120
120
  warning_suggestion = params[parameterized_name.to_sym].is_a?(Hash) ? params[parameterized_name.to_sym].keys.map{ |k| k.to_sym } : "permit_params:"
121
- warn "[UNPERMITED PARAMS] To permit #{params[parameterized_name.to_sym].inspect} params, add 'permit_params: #{warning_suggestion}' option to 'acts_as_restful'"
121
+ warn "[UNPERMITED PARAMS] To permit #{params[parameterized_name.to_sym].to_unsafe_h.inspect} params, add 'permit_params: #{warning_suggestion}' option to 'acts_as_restful'"
122
122
  else
123
123
  params.require(parameterized_name.to_sym).permit(permited_params)
124
124
  end
@@ -199,7 +199,7 @@ module Weeler
199
199
  item.sequence = index
200
200
  item.save!
201
201
  end
202
- render :text => 'all ok'
202
+ render plain: 'all ok'
203
203
  end
204
204
 
205
205
  end # Instance methods
@@ -54,11 +54,10 @@ module Weeler
54
54
  collection do
55
55
  get :export
56
56
  post :import
57
- get :usage_stats
58
57
  end
59
58
  end
60
59
  resources :seo_items
61
- resources :settings, :only => [:index, :edit, :update]
60
+ resources :settings, :only => [:index, :update, :create]
62
61
  end
63
62
 
64
63
  # Ordable route concern for dynamic sorting and removing image
@@ -4,8 +4,8 @@ module Weeler
4
4
  module TranslationHelper
5
5
  extend ActiveSupport::Concern
6
6
 
7
- def translate(key, options = {})
8
- request.present? && request.params[:show_translation_keys] == "true" ? key : super(key, options)
7
+ def translate(key, **options)
8
+ request.present? && request.params[:show_translation_keys] == "true" ? key : super(key, **options)
9
9
  end
10
10
  alias :t :translate
11
11
 
data/lib/weeler/engine.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "weeler/action_controller/acts/restful"
2
2
  require "weeler/action_dispatch/routing/mapper"
3
- require "weeler/action_view/helpers/form_helper"
4
3
  require "weeler/action_view/helpers/translation_helper"
5
4
 
6
5
  module Weeler
@@ -10,14 +9,12 @@ module Weeler
10
9
  config.weeler = Weeler
11
10
 
12
11
  config.i18n.available_locales = [:en] unless config.i18n.available_locales.present?
13
- config.active_record.raise_in_transactional_callbacks = true
14
12
  config.assets.precompile += ["weeler/init.js", "weeler/init.css"]
15
13
 
16
14
  # Load extend Rails classes
17
15
  ::ActionDispatch::Routing::Mapper.send(:include, Weeler::ActionDispatch::Routing::Mapper)
18
16
  ::ActionController::Base.send(:include, Weeler::ActionController::Acts::Restful)
19
17
 
20
- ::ActionView::Helpers::FormBuilder.send(:include, Weeler::ActionView::Helpers::FormHelper)
21
18
  ::ActionView::Base.send(:include, Weeler::ActionView::Helpers::TranslationHelper)
22
19
  end
23
20
 
@@ -1,8 +1,8 @@
1
1
  module Weeler
2
2
  module VERSION
3
- MAJOR = 1
4
- MINOR = 5
5
- TINY = 2
3
+ MAJOR = 2
4
+ MINOR = 0
5
+ TINY = 1
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
8
8
  end
data/lib/weeler.rb CHANGED
@@ -11,7 +11,6 @@ require "haml"
11
11
  require "kaminari"
12
12
  require "globalize"
13
13
  require "jquery-ui-rails"
14
- require "jquery-turbolinks"
15
14
  require "rails-settings-cached"
16
15
 
17
16
  module Weeler
@@ -27,7 +26,7 @@ module Weeler
27
26
 
28
27
  mattr_accessor :use_weeler_i18n
29
28
  @@use_weeler_i18n = true
30
-
29
+
31
30
  mattr_accessor :empty_translation_acts_like_missing
32
31
  @@empty_translation_acts_like_missing = true
33
32
 
@@ -66,9 +65,15 @@ module Weeler
66
65
  mattr_accessor :mount_location_namespace
67
66
  @@mount_location_namespace = "weeler"
68
67
 
68
+ mattr_accessor :use_rails_rich_text_editor
69
+ @@use_rails_rich_text_editor = true
70
+
71
+ mattr_accessor :settings_fields
72
+ @@settings_fields = []
73
+
69
74
  def self.setup
70
75
  yield self
71
- if Weeler.use_weeler_i18n == true && ActiveRecord::Base.connection.table_exists?('weeler_translations')
76
+ if Weeler.use_weeler_i18n == true && ActiveRecord::Base.connection.data_source_exists?('weeler_translations')
72
77
  require "i18n/weeler"
73
78
  Weeler.static_sections.each do |key, section|
74
79
  Weeler.static_menu_items << {name: key.to_s.capitalize, weeler_path: "static_sections/#{key}"}
data/spec/.DS_Store CHANGED
Binary file
@@ -10,8 +10,8 @@ describe Weeler::TranslationsController, type: :controller do
10
10
 
11
11
  describe "GET #index" do
12
12
  before do
13
- FactoryGirl.create(:translation, key: 'foo.bar')
14
- FactoryGirl.create(:translation, key: 'bar.foo')
13
+ FactoryBot.create(:translation, key: 'foo.bar')
14
+ FactoryBot.create(:translation, key: 'bar.foo')
15
15
  end
16
16
 
17
17
  it "list translations" do
@@ -25,7 +25,7 @@ describe Weeler::TranslationsController, type: :controller do
25
25
  expect(I18n.t("title", locale: :en)).to eq("Title")
26
26
  I18n::Backend::Weeler::Translation.delete_all
27
27
 
28
- post :create, i18n_backend_weeler_translation: FactoryGirl.attributes_for(:translation)
28
+ post :create, params: { i18n_backend_weeler_translation: FactoryBot.attributes_for(:translation) }
29
29
 
30
30
  expect(I18n.t("title", locale: :en)).to eq("This is weeler")
31
31
  end
@@ -33,10 +33,10 @@ describe Weeler::TranslationsController, type: :controller do
33
33
  it "doesnt create a duplicate key" do
34
34
  I18n::Backend::Weeler::Translation.delete_all
35
35
 
36
- post :create, i18n_backend_weeler_translation: {locale: "en", key: "no.dup.title", value: "This is weeler"}
36
+ post :create, params: { i18n_backend_weeler_translation: {locale: "en", key: "no.dup.title", value: "This is weeler"} }
37
37
  expect(I18n.t("no.dup.title", locale: :en)).to eq("This is weeler")
38
38
 
39
- post :create, i18n_backend_weeler_translation: {locale: "en", key: "no.dup.title", value: "This is weeler"}
39
+ post :create, params: { i18n_backend_weeler_translation: {locale: "en", key: "no.dup.title", value: "This is weeler"} }
40
40
  expect(response).to render_template(:edit)
41
41
  end
42
42
  end
@@ -44,17 +44,17 @@ describe Weeler::TranslationsController, type: :controller do
44
44
  describe "PUT #update" do
45
45
  it "update translation in DB" do
46
46
  I18n::Backend::Weeler::Translation.delete_all
47
- translation = FactoryGirl.create(:translation, key: 'foo.updated', value: nil)
47
+ translation = FactoryBot.create(:translation, key: 'foo.updated', value: nil)
48
48
 
49
- put "update", id: translation.id, i18n_backend_weeler_translation: {value: "Updated weeler!"}
49
+ put "update", params: { id: translation.id, i18n_backend_weeler_translation: {value: "Updated weeler!"} }
50
50
  expect(I18n.t("foo.updated", locale: :en)).to eq("Updated weeler!")
51
51
  end
52
52
 
53
53
  it "dont updates if key is empty" do
54
54
  I18n::Backend::Weeler::Translation.delete_all
55
- translation = FactoryGirl.create(:translation, key: 'foo.updated', value: nil)
55
+ translation = FactoryBot.create(:translation, key: 'foo.updated', value: nil)
56
56
 
57
- put "update", id: translation.id, i18n_backend_weeler_translation: {value: "Updated weeler!", key: nil}
57
+ put "update", params: { id: translation.id, i18n_backend_weeler_translation: {value: "Updated weeler!", key: nil} }
58
58
  expect(response).to render_template(:edit)
59
59
  end
60
60
  end
@@ -68,16 +68,16 @@ describe Weeler::TranslationsController, type: :controller do
68
68
 
69
69
  describe "GET #edit" do
70
70
  it "retern edit translation form" do
71
- translation = FactoryGirl.create(:translation, key: 'foo.updated', value: nil)
72
- get "edit", id: translation.id
71
+ translation = FactoryBot.create(:translation, key: 'foo.updated', value: nil)
72
+ get "edit", params: { id: translation.id }
73
73
  expect(response).to render_template(:edit)
74
74
  end
75
75
  end
76
76
 
77
77
  describe "DELETE #destroy" do
78
78
  it "destroys translation" do
79
- translation = FactoryGirl.create(:translation, key: 'foo.removing', value: "Bla bla")
80
- delete "destroy", id: translation.id
79
+ translation = FactoryBot.create(:translation, key: 'foo.removing', value: "Bla bla")
80
+ delete "destroy", params: { id: translation.id }
81
81
 
82
82
  expect(I18n.t("foo.removing", locale: :en)).to eq("Removing") # Returns empty key
83
83
  end
@@ -87,10 +87,10 @@ describe Weeler::TranslationsController, type: :controller do
87
87
  context "submiting a file" do
88
88
  it "adds translation from files" do
89
89
  I18n::Backend::Weeler::Translation.delete_all
90
- Settings.i18n_updated_at = Time.now
90
+ Setting.i18n_updated_at = Time.current
91
91
 
92
92
  expect(I18n.t("welcome.title", locale: :en)).to eq("Title") # Missing translation
93
- post "import", file: fixture_file_upload(File.dirname(__FILE__) + '/../fixtures/test.xlsx', 'application/xlsx')
93
+ post "import", params: { file: fixture_file_upload(File.dirname(__FILE__) + '/../fixtures/test.xlsx', 'application/xlsx') }
94
94
  expect(I18n.t("welcome.title", locale: :en)).to eq("EN welcome")
95
95
  end
96
96
  end
@@ -110,7 +110,7 @@ describe Weeler::TranslationsController, type: :controller do
110
110
  it "retursns translation file" do
111
111
  get "export", format: :xlsx
112
112
  expect(response.headers["Content-Type"]).to eq("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
113
- expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"translations.xlsx\"")
113
+ expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"translations.xlsx\"; filename*=UTF-8''translations.xlsx")
114
114
  end
115
115
  end
116
116
 
@@ -0,0 +1 @@
1
+ ruby-2.7.2
data/spec/dummy/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
4
+ require_relative 'config/application'
5
5
 
6
- Dummy::Application.load_tasks
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
3
+ //= link faker_manifest.js
@@ -3,11 +3,13 @@
3
3
  * listed below.
4
4
  *
5
5
  * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
7
  *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
10
12
  *
11
- *= require_self
12
13
  *= require_tree .
14
+ *= require_self
13
15
  */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -1,5 +1,2 @@
1
1
  class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
5
2
  end
@@ -2,12 +2,14 @@
2
2
  // listed below.
3
3
  //
4
4
  // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
6
  //
7
7
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
9
  //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
+ //= require rails-ujs
14
+ //= require activestorage
13
15
  //= require_tree .
@@ -0,0 +1,7 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ # Automatically retry jobs that encountered a deadlock
3
+ # retry_on ActiveRecord::Deadlocked
4
+
5
+ # Most jobs are safe to ignore if the underlying records are no longer available
6
+ # discard_on ActiveJob::DeserializationError
7
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end