jekyll-contentful-data-import 1.4.1 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a023acf8f4a522069e34d5a64bb70bc4be81cf01
4
- data.tar.gz: f8eceedfbc009522bb3e8142a7ab0f9b66367bb2
3
+ metadata.gz: 1cf5c41ca9aca767ca77b9d1442959f64ced7e01
4
+ data.tar.gz: 4bc77e0deb86dec284616db98a4f7f6cf203767d
5
5
  SHA512:
6
- metadata.gz: 7cd71f3134d5c1ca3987b009c4b239ea0b49ab9e73d327ffeb86cf7e3734e921f13acc2b1271ca399bbf3b6b9e382f89c4dbe0f363dd8f69b4125079b5ff5c05
7
- data.tar.gz: b31cf5afb8989d8ffb313352328deb6b6894ea30075693083aae7cc8c359857dbe860f7b86adcc05fa2e8626a4933d52c4a4cd24f71cbcd561c415cdbbcb697e
6
+ metadata.gz: 4334226a3e39567e23bfd2954312adc08f6178f777fedb0ad822d9f7e8c8e85754fcaf33381fb08aeb9b8bc4a25895cc19cd2e24d5a2b90f1c8b8c155f25af10
7
+ data.tar.gz: 07bcd6073b737c35f42e4bef68e8fb37df92e029b1d8cf85a31ed41fa44f3db7d99371b3a01e17a264ac4bd1774bfe07dec1853be6acdb3e555d52b217398e29
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## v1.4.2
6
+ ### Fixed
7
+ * Fixed localization issues for included assets [#29](https://github.com/contentful/jekyll-contentful-data-import/issues/29)
8
+
5
9
  ## v1.4.1
6
10
  ### Changed
7
11
  * Changed `Location` fields to use strings as keys instead of symbols to make it consistent with the rest of the serialization
@@ -29,7 +29,7 @@ module Jekyll
29
29
  fields = has_multiple_locales? ? entry.fields_with_locales : entry.fields
30
30
 
31
31
  fields.each do |k, v|
32
- name, value = map_field k, v
32
+ name, value = map_field(k, v)
33
33
  result[name] = value
34
34
  end
35
35
 
@@ -41,14 +41,24 @@ module Jekyll
41
41
  end
42
42
 
43
43
  def map_field(field_name, field_value)
44
- value_mapping = map_value(field_value)
44
+ value_mapping = nil
45
+
46
+ if has_multiple_locales?
47
+ value_mapping = {}
48
+ field_value.each do |locale, value|
49
+ value_mapping[locale.to_s] = map_value(value, locale.to_s)
50
+ end
51
+ else
52
+ value_mapping = map_value(field_value)
53
+ end
54
+
45
55
  return field_name.to_s, value_mapping
46
56
  end
47
57
 
48
- def map_value(value)
58
+ def map_value(value, locale = nil)
49
59
  case value
50
60
  when ::Contentful::Asset
51
- map_asset(value)
61
+ map_asset(value, locale)
52
62
  when ::Contentful::Location
53
63
  map_location(value)
54
64
  when ::Contentful::Link
@@ -56,13 +66,13 @@ module Jekyll
56
66
  when ::Contentful::DynamicEntry
57
67
  map_entry(value)
58
68
  when ::Array
59
- map_array(value)
69
+ map_array(value, locale)
60
70
  when ::Symbol
61
71
  value.to_s
62
72
  when ::Hash
63
73
  result = {}
64
74
  value.each do |k, v|
65
- result[k.to_s] = map_value(v)
75
+ result[k.to_s] = map_value(v, locale)
66
76
  end
67
77
  result
68
78
  else
@@ -70,8 +80,26 @@ module Jekyll
70
80
  end
71
81
  end
72
82
 
73
- def map_asset(asset)
74
- {'title' => asset.title, 'url' => asset.file.url}
83
+ def map_asset(asset, locale = nil)
84
+ if locale
85
+ file = asset.fields(locale)[:file]
86
+ file_url = file.nil? ? '' : file.url
87
+
88
+ return {
89
+ 'title' => asset.fields(locale)[:title],
90
+ 'description' => asset.fields(locale)[:description],
91
+ 'url' => file_url
92
+ }
93
+ end
94
+
95
+ file = asset.file
96
+ file_url = file.nil? ? '' : file.url
97
+
98
+ {
99
+ 'title' => asset.title,
100
+ 'description' => asset.description,
101
+ 'url' => file_url
102
+ }
75
103
  end
76
104
 
77
105
  def map_entry(child)
@@ -90,8 +118,8 @@ module Jekyll
90
118
  {'sys' => {'id' => link.id}}
91
119
  end
92
120
 
93
- def map_array(array)
94
- array.map {|element| map_value(element)}
121
+ def map_array(array, locale)
122
+ array.map {|element| map_value(element, locale)}
95
123
  end
96
124
  end
97
125
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Contentful
3
- VERSION = "1.4.1"
3
+ VERSION = "1.4.2"
4
4
  end
5
5
  end
@@ -33,10 +33,25 @@ describe Jekyll::Contentful::Mappers::Base do
33
33
  end
34
34
 
35
35
  class AssetDouble < Contentful::Asset
36
- attr_reader :title, :file
37
- def initialize(title, url)
36
+ attr_reader :title, :description, :file
37
+ def initialize(title, description, url, fields = nil)
38
38
  @title = title
39
+ @description = description
39
40
  @file = FileDouble.new(url)
41
+ @fields = {
42
+ 'en-US' => {
43
+ title: title,
44
+ description: description,
45
+ file: file
46
+ }
47
+ } if fields.nil?
48
+
49
+ @fields ||= fields
50
+ end
51
+
52
+ def fields(locale = nil)
53
+ return { title: title, description: description, file: file } if locale.nil?
54
+ @fields[locale]
40
55
  end
41
56
  end
42
57
 
@@ -66,7 +81,7 @@ describe Jekyll::Contentful::Mappers::Base do
66
81
 
67
82
  it 'maps a complete entry' do
68
83
  entry = EntryDouble.new('foo', ContentTypeDouble.new, {
69
- 'asset' => AssetDouble.new('some_title', 'some_url'),
84
+ 'asset' => AssetDouble.new('some_title', 'foo', 'some_url'),
70
85
  'location' => LocationDouble.new(12.32, 43.34),
71
86
  'link' => LinkDouble.new('bar'),
72
87
  'entry' => EntryDouble.new('baz'),
@@ -83,6 +98,7 @@ describe Jekyll::Contentful::Mappers::Base do
83
98
  'sys' => { 'id' => 'foo' },
84
99
  'asset' => {
85
100
  'title' => 'some_title',
101
+ 'description' => 'foo',
86
102
  'url' => 'some_url'
87
103
  },
88
104
  'location' => {
@@ -129,5 +145,45 @@ describe Jekyll::Contentful::Mappers::Base do
129
145
  expect(mapper.map).to match expected
130
146
  end
131
147
  end
148
+
149
+ describe '#29 - Assets should pull the correct locale if the field is localized' do
150
+ it 'should fetch the correct locale for the asset' do
151
+ config = {'cda_query' => { 'locale' => '*' } }
152
+ fields = {
153
+ 'en-US' => {
154
+ 'asset' => AssetDouble.new('some_title', 'foo', 'some_url')
155
+ },
156
+ 'de-DE' => {
157
+ 'asset' => AssetDouble.new('some_title', 'foo', 'some_url', {
158
+ 'de-DE' => {
159
+ title: 'other_title',
160
+ description: 'other description',
161
+ file: FileDouble.new('other_url')
162
+ }
163
+ })
164
+ }
165
+ }
166
+ entry = EntryDouble.new('foo', ContentTypeDouble.new, fields, true)
167
+ mapper = described_class.new(entry, config)
168
+
169
+ expected = {
170
+ 'sys' => { 'id' => 'foo' },
171
+ 'asset' => {
172
+ "en-US" => {
173
+ "title" => "some_title",
174
+ "description" => "foo",
175
+ "url" => 'some_url'
176
+ },
177
+ "de-DE" => {
178
+ "title" => "other_title",
179
+ "description" => "other description",
180
+ "url" => 'other_url'
181
+ }
182
+ }
183
+ }
184
+
185
+ expect(mapper.map).to match expected
186
+ end
187
+ end
132
188
  end
133
189
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-contentful-data-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll