udongo 7.0.1 → 7.0.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.
- checksums.yaml +4 -4
- data/changelog.md +5 -0
- data/lib/udongo/flexible_content/duplicate_locale.rb +73 -69
- data/lib/udongo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e840d9bb18fba2da849e3c6ec733ab2c6f8fd88
|
4
|
+
data.tar.gz: a354bc901b32d59bec7010afbfed60ce5eef60ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e93e8f31f091510d4cf03d597727db9342cc57ba31e6e9e79d8fee47f8b896756625a3b1f12269fdc5500e0e10639ab959bfa3f5e9d211d347d1b00705f020b
|
7
|
+
data.tar.gz: c72873d2fda0032e8139ccbe587d09900e21e0fe76f8067299f891add9570ba3a7da60a2b2603ba5d672778b6076552196ea7c92d8150c63c102760e33b0ecbc
|
data/changelog.md
CHANGED
@@ -1,86 +1,90 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Udongo
|
2
|
+
module FlexibleContent
|
3
|
+
class DuplicateLocale
|
4
|
+
def initialize(object, source_locale, destination_locale)
|
5
|
+
@object = object
|
6
|
+
@source_locale = source_locale
|
7
|
+
@destination_locale = destination_locale
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
def execute!
|
11
|
+
check_for_flexible_content!
|
12
|
+
check_for_different_locales!
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
ActiveRecord::Base.transaction do
|
15
|
+
clear_destination_content!
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
@object.content_rows.by_locale(@source_locale).each do |source_row|
|
18
|
+
new_row = duplicate_row(source_row)
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
source_row.columns.each do |source_column|
|
21
|
+
duplicate_column(new_row, source_column)
|
22
|
+
end
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
22
|
-
end
|
23
|
-
end
|
24
26
|
|
25
|
-
|
27
|
+
private
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def check_for_flexible_content!
|
30
|
+
return if @object.respond_to?(:flexible_content?) && @object.flexible_content?
|
31
|
+
raise 'The object you provided does not have the FlexibleContent concern included.'
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def check_for_different_locales!
|
35
|
+
if @source_locale.to_s == @destination_locale.to_s
|
36
|
+
raise "The source and destination locale are the same (#{@source_locale})"
|
37
|
+
end
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
def clear_destination_content!
|
41
|
+
@object.content_rows.by_locale(@destination_locale).destroy_all
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
44
|
+
def duplicate_row(source)
|
45
|
+
@object.content_rows.create!(
|
46
|
+
locale: @destination_locale,
|
47
|
+
full_width: source.full_width?,
|
48
|
+
horizontal_alignment: source.horizontal_alignment,
|
49
|
+
vertical_alignment: source.vertical_alignment,
|
50
|
+
background_color: source.background_color,
|
51
|
+
no_gutters: source.no_gutters?,
|
52
|
+
padding_top: source.padding_top,
|
53
|
+
padding_bottom: source.padding_bottom,
|
54
|
+
margin_top: source.margin_top,
|
55
|
+
margin_bottom: source.margin_bottom,
|
56
|
+
position: source.position
|
57
|
+
)
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
+
def duplicate_column(new_row, source_column)
|
61
|
+
widget = duplicate_widget(source_column.content)
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
new_row.columns.create!(
|
64
|
+
width_xs: source_column.width_xs,
|
65
|
+
width_sm: source_column.width_sm,
|
66
|
+
width_md: source_column.width_md,
|
67
|
+
width_lg: source_column.width_lg,
|
68
|
+
width_xl: source_column.width_xl,
|
69
|
+
position: source_column.position,
|
70
|
+
content: widget,
|
71
|
+
external_reference: source_column.id
|
72
|
+
)
|
73
|
+
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
def duplicate_widget(source)
|
76
|
+
source.class.create!(
|
77
|
+
widget_attributes(source)
|
78
|
+
)
|
79
|
+
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
def widget_attributes(widget)
|
82
|
+
attributes = widget.attributes
|
83
|
+
attributes.delete('id')
|
84
|
+
attributes.delete('created_at')
|
85
|
+
attributes.delete('updated_at')
|
86
|
+
attributes
|
87
|
+
end
|
88
|
+
end
|
85
89
|
end
|
86
90
|
end
|
data/lib/udongo/version.rb
CHANGED