udongo 7.0.0 → 7.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abcf2f3a3fea0a5ff7a89fa8364f083c948fe8d0
4
- data.tar.gz: a9cea4a94f6790316fae6a9843bf8e088a01f762
3
+ metadata.gz: 6ebe5d0ae0452bf3d7e74d1f177c2a6bb9573a4d
4
+ data.tar.gz: ee18f273a09e0fbf35d6e1ff632e4cb59e811db3
5
5
  SHA512:
6
- metadata.gz: 7349c0efcab0845f8358291a103043059a46ca7314fecb33fc3ed5f092b27a209187f041f2fcb4648c9bf0745fa6ae6cea27227c6f1c71d10bcb96c73b69ed55
7
- data.tar.gz: 3c4df6d375c5cac2ca2f9b2f8e48c8ba73d8756e6145b58f6f4044685d79e00b130842f801bf215a362ba8367b9ee772be6969bfb64aa4b5e460c9356d74874b
6
+ metadata.gz: 20d5a992a3ca9f53d8637140f1077e06abcc04603fc79a76719f4dc670e9554a4a47f76650331206b9a5c588bcf2e30f049e4a52f45a730e1c9e17fcbd2cedcf
7
+ data.tar.gz: c382e849537dbecc8b893c0d77def603691d843b070587035da5885d43a8e5ecfd25fb22f2552c0ceac421859aa9a0a32e7fc12045e8f87eabbd5d9c7b392c0e
@@ -0,0 +1,47 @@
1
+ class Backend::Content::DuplicateController < Backend::BaseController
2
+ before_action :find_model
3
+
4
+ def execute
5
+ duplicate
6
+ redirect_back_to_edit_translation
7
+ end
8
+
9
+ private
10
+
11
+ def find_model
12
+ begin
13
+ @model = params[:model].to_s.camelcase.constantize.find(params[:id])
14
+ rescue
15
+ redirect_to backend_path
16
+ end
17
+ end
18
+
19
+ def source_locale
20
+ if Udongo.config.i18n.app.locales.include?(params[:source_locale].to_s)
21
+ params[:source_locale].to_s
22
+ else
23
+ raise "No valid source locale provided (#{params[:source_locale]})"
24
+ end
25
+ end
26
+
27
+ def destination_locale
28
+ if Udongo.config.i18n.app.locales.include?(params[:destination_locale].to_s)
29
+ params[:destination_locale].to_s
30
+ else
31
+ raise "No valid destination locale provided (#{params[:destination_locale]})"
32
+ end
33
+ end
34
+
35
+ def duplicate
36
+ Udongo::FlexibleContent::DuplicateLocale.new(
37
+ @model,
38
+ source_locale,
39
+ destination_locale
40
+ ).execute!
41
+ end
42
+
43
+ def redirect_back_to_edit_translation
44
+ path = "edit_translation_backend_#{@model.class.name.downcase}_path"
45
+ redirect_to send(path, @model, destination_locale), notice: t('b.msg.flexible_content.duplicated')
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+ module FlexibleContentHelper
2
+ def importable_locales(model, current_locale)
3
+ Udongo.config.i18n.app.locales.select do |lo|
4
+ lo.to_s != current_locale.to_s && model.content_rows.by_locale(lo).any?
5
+ end
6
+ end
7
+ end
@@ -6,10 +6,8 @@ module Concerns
6
6
  has_many :content_rows, as: :rowable, dependent: :destroy
7
7
  end
8
8
 
9
- module ClassMethods
10
- def flexible_content?
11
- true
12
- end
9
+ def flexible_content?
10
+ true
13
11
  end
14
12
  end
15
13
  end
@@ -93,7 +93,7 @@ module Concerns
93
93
  translatable_fields_list.each { |f| result << f }
94
94
  end
95
95
 
96
- result << :flexible_content if respond_to?(:flexible_content?)
96
+ result << :flexible_content if new.respond_to?(:flexible_content?)
97
97
  result
98
98
  end
99
99
  end
@@ -13,6 +13,12 @@ module Concerns
13
13
  ).where('slug IS NOT NULL OR slug != ""').pluck(:locale).uniq
14
14
 
15
15
  update_column :seo_locales, locales
16
+
17
+ # This is a bit of a long story. For some reason when you save the
18
+ # parent object, the SEO info is -not always- saved. At the moment I'm
19
+ # unable to reproduce it consistently. Therefor I've added some extra
20
+ # code to manually loop the seo collections and save them.
21
+ @seo_collections.keys.each { |l| seo(l).save } if @seo_collections
16
22
  end
17
23
 
18
24
  scope :with_seo, ->(locale) { where('seo_locales LIKE ?', "%#{locale}%")}
@@ -1,6 +1,7 @@
1
1
  <% javascript 'backend/seo' %>
2
2
 
3
3
  <% sluggable_field ||= 'title' %>
4
+ <% slug ||= nil %>
4
5
 
5
6
  <%= content_tag :div, class: 'card', data: { seo: true, path: backend_seo_slugify_path, sluggable_input: "##{f.object_name}_#{sluggable_field}" } do %>
6
7
  <div class="card-header">
@@ -8,7 +9,12 @@
8
9
  </div>
9
10
 
10
11
  <div class="card-block">
11
- <%= f.input :seo_slug, as: :string %>
12
+ <% if slug.present? %>
13
+ <%= f.input :seo_slug, as: :string, input_html: { value: slug } %>
14
+ <% else %>
15
+ <%= f.input :seo_slug, as: :string %>
16
+ <% end %>
17
+
12
18
  <%= f.input :seo_title, as: :string %>
13
19
  <%= f.input :seo_description, as: :string %>
14
20
  <%= f.input :seo_keywords, as: :string %>
@@ -12,7 +12,23 @@
12
12
  </div>
13
13
 
14
14
  <div class="card-block">
15
- <%= t 'b.msg.flexible_content.explanation' %>
15
+ <p>
16
+ <%= t 'b.msg.flexible_content.explanation' %><br>
17
+ </p>
18
+
19
+ <% import_locales = importable_locales(model, params[:translation_locale])%>
20
+
21
+ <% if import_locales.any? %>
22
+ <p>
23
+ <%= t('b.msg.flexible_content.duplicate_from_other_locales').html_safe %>
24
+
25
+ <%=
26
+ import_locales.map do |lo|
27
+ link_to lo.upcase, backend_content_duplicate_path(model.class.name.underscore.gsub('_decorator', ''), model.id, lo, params[:translation_locale]), data: { confirm: t('b.msg.confirm') }
28
+ end.join(', ').html_safe
29
+ %>
30
+ <% end %>
31
+ </p>
16
32
  </div>
17
33
  </div>
18
34
  <% end %>
data/changelog.md CHANGED
@@ -1,3 +1,14 @@
1
+ 7.0.1 - 2017-09-21
2
+ --
3
+ * Removed some unused translations.
4
+ * The backend/seo_form partial now accepts a hard slug value so prefills are
5
+ possible on other locations.
6
+ * Cleanup the #flexible_content? check to be an instance method instead of a
7
+ class method.
8
+ * Make sure the SEO concern saves when you save its parent object.
9
+ * You can import the flexible content from another locale.
10
+
11
+
1
12
  7.0.0 - 2017-07-28
2
13
  --
3
14
  * It's now possible to use the scope .with_seo(:nl) to fetch models that actually
@@ -118,7 +118,6 @@ en:
118
118
  confirm: Are you sure?
119
119
  content_types:
120
120
  form: Form
121
- image: Image (deprecated!)
122
121
  picture: Picture
123
122
  slideshow: Slideshow
124
123
  text: Text
@@ -136,6 +135,8 @@ en:
136
135
  align_vertical_bottom: Align vertical bottom
137
136
  align_vertical_center: Align vertically
138
137
  align_vertical_top: Align vertical top
138
+ duplicate_from_other_locales: 'Would you rather copy the content from another language?<br>Click your preferred language and the content will be duplicated.'
139
+ duplicated: The flexible content has been duplicated.
139
140
  explanation: With this module you can create flexible responsive content. Click the button below to create the first row.
140
141
  full_width: Full width
141
142
  margin_explanation: Margin is the whitespace above and below this row.
@@ -120,7 +120,6 @@ nl:
120
120
  confirm: Ben je zeker?
121
121
  content_types:
122
122
  form: Formulier
123
- image: Afbeelding (niet meer gebruiken!)
124
123
  picture: Foto
125
124
  slideshow: Slideshow
126
125
  text: Tekst
@@ -138,6 +137,8 @@ nl:
138
137
  align_vertical_bottom: Vertikaal onderaan uitlijnen
139
138
  align_vertical_center: Vertikaal centreren
140
139
  align_vertical_top: Vertikaal bovenaan uitlijnen
140
+ duplicate_from_other_locales: 'Wil je de inhoud liever overnemen van een andere taal?<br>Klik op de gewenste taal en de inhoud wordt gedupliceerd:'
141
+ duplicated: De flexibele inhoud werd gedupliceerd.
141
142
  explanation: Met deze module kan je flexibele, responsive inhoud toevoegen. Klik op onderstaande knop om een eerste rij toe te voegen.
142
143
  full_width: Volledige breedte
143
144
  margin_explanation: Marge is de witruimte boven en onder je rij.
data/config/routes.rb CHANGED
@@ -90,6 +90,8 @@ Rails.application.routes.draw do
90
90
  end
91
91
 
92
92
  namespace :content do
93
+ get 'duplicate/:model/:id/:source_locale/:destination_locale' => 'duplicate#execute', as: :duplicate
94
+
93
95
  resources :rows, only: [:index, :new, :edit, :update, :destroy] do
94
96
  member do
95
97
  get :horizontal_alignment, :vertical_alignment, :toggle_full_width
@@ -0,0 +1,6 @@
1
+ class AddExternalReferenceToContentColumn < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :content_columns, :external_reference, :string, after: 'content_id'
4
+ add_index :content_columns, :external_reference
5
+ end
6
+ end
@@ -0,0 +1,86 @@
1
+ class Udongo::FlexibleContent::DuplicateLocale
2
+ def initialize(object, source_locale, destination_locale)
3
+ @object = object
4
+ @source_locale = source_locale
5
+ @destination_locale = destination_locale
6
+ end
7
+
8
+ def execute!
9
+ check_for_flexible_content!
10
+ check_for_different_locales!
11
+
12
+ ActiveRecord::Base.transaction do
13
+ clear_destination_content!
14
+
15
+ @object.content_rows.by_locale(@source_locale).each do |source_row|
16
+ new_row = duplicate_row(source_row)
17
+
18
+ source_row.columns.each do |source_column|
19
+ duplicate_column(new_row, source_column)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def check_for_flexible_content!
28
+ return if @object.respond_to?(:flexible_content?) && @object.flexible_content?
29
+ raise 'The object you provided does not have the FlexibleContent concern included.'
30
+ end
31
+
32
+ def check_for_different_locales!
33
+ if @source_locale.to_s == @destination_locale.to_s
34
+ raise "The source and destination locale are the same (#{@source_locale})"
35
+ end
36
+ end
37
+
38
+ def clear_destination_content!
39
+ @object.content_rows.by_locale(@destination_locale).destroy_all
40
+ end
41
+
42
+ def duplicate_row(source)
43
+ @object.content_rows.create!(
44
+ locale: @destination_locale,
45
+ full_width: source.full_width?,
46
+ horizontal_alignment: source.horizontal_alignment,
47
+ vertical_alignment: source.vertical_alignment,
48
+ background_color: source.background_color,
49
+ no_gutters: source.no_gutters?,
50
+ padding_top: source.padding_top,
51
+ padding_bottom: source.padding_bottom,
52
+ margin_top: source.margin_top,
53
+ margin_bottom: source.margin_bottom,
54
+ position: source.position
55
+ )
56
+ end
57
+
58
+ def duplicate_column(new_row, source_column)
59
+ widget = duplicate_widget(source_column.content)
60
+
61
+ new_row.columns.create!(
62
+ width_xs: source_column.width_xs,
63
+ width_sm: source_column.width_sm,
64
+ width_md: source_column.width_md,
65
+ width_lg: source_column.width_lg,
66
+ width_xl: source_column.width_xl,
67
+ position: source_column.position,
68
+ content: widget,
69
+ external_reference: source_column.id
70
+ )
71
+ end
72
+
73
+ def duplicate_widget(source)
74
+ source.class.create!(
75
+ widget_attributes(source)
76
+ )
77
+ end
78
+
79
+ def widget_attributes(widget)
80
+ attributes = widget.attributes
81
+ attributes.delete('id')
82
+ attributes.delete('created_at')
83
+ attributes.delete('updated_at')
84
+ attributes
85
+ end
86
+ end
@@ -1,3 +1,3 @@
1
1
  module Udongo
2
- VERSION = '7.0.0'
2
+ VERSION = '7.0.1'
3
3
  end
@@ -5,18 +5,12 @@ shared_examples_for :flexible_content do
5
5
  let(:klass) { model.to_s.underscore.to_sym }
6
6
 
7
7
  it '.flexible_content?' do
8
- expect(model.flexible_content?).to be true
9
- end
10
-
11
- it '.respond_to?' do
12
- expect(model).to respond_to(
13
- :flexible_content?
14
- )
8
+ expect(model.new).to be_flexible_content
15
9
  end
16
10
 
17
11
  it '#respond_to?' do
18
12
  expect(model.new).to respond_to(
19
- :content_rows
13
+ :content_rows, :flexible_content?
20
14
  )
21
15
  end
22
16
  end
@@ -91,6 +91,13 @@ shared_examples_for :seo do
91
91
  end
92
92
  end
93
93
 
94
+ it 'autosave when the parent is saved' do
95
+ instance.seo(:en).title = 'some foo'
96
+ instance.save
97
+
98
+ expect(model.find(instance.id).seo(:en).title).to eq 'some foo'
99
+ end
100
+
94
101
  it '#respond_to?' do
95
102
  expect(build(klass)).to respond_to(:meta, :seo)
96
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: udongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davy Hellemans
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-28 00:00:00.000000000 Z
12
+ date: 2017-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -462,6 +462,7 @@ files:
462
462
  - app/controllers/backend/articles_controller.rb
463
463
  - app/controllers/backend/assets_controller.rb
464
464
  - app/controllers/backend/base_controller.rb
465
+ - app/controllers/backend/content/duplicate_controller.rb
465
466
  - app/controllers/backend/content/rows/columns_controller.rb
466
467
  - app/controllers/backend/content/rows/forms_controller.rb
467
468
  - app/controllers/backend/content/rows/pictures_controller.rb
@@ -528,6 +529,7 @@ files:
528
529
  - app/helpers/backend/form_helper.rb
529
530
  - app/helpers/backend/pagination_helper.rb
530
531
  - app/helpers/collection_helper.rb
532
+ - app/helpers/flexible_content_helper.rb
531
533
  - app/helpers/icon_helper.rb
532
534
  - app/helpers/link_helper.rb
533
535
  - app/helpers/navigation_helper.rb
@@ -854,6 +856,7 @@ files:
854
856
  - db/migrate/20170623124218_add_caption_to_content_video.rb
855
857
  - db/migrate/20170728094909_add_seo_locales_to_models_with_seo.rb
856
858
  - db/migrate/20170728125838_remove_content_images.rb
859
+ - db/migrate/20170919135942_add_external_reference_to_content_column.rb
857
860
  - lib/tasks/task_extras.rb
858
861
  - lib/tasks/udongo_tasks.rake
859
862
  - lib/udongo.rb
@@ -880,6 +883,7 @@ files:
880
883
  - lib/udongo/email_vars_parser.rb
881
884
  - lib/udongo/engine.rb
882
885
  - lib/udongo/flexible_content/column_width_calculator.rb
886
+ - lib/udongo/flexible_content/duplicate_locale.rb
883
887
  - lib/udongo/form.rb
884
888
  - lib/udongo/image_manipulation/base.rb
885
889
  - lib/udongo/image_manipulation/resize_and_pad.rb