contentful_middleman 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68a030c2034591f7185811846ef7291c2d4737f5
4
- data.tar.gz: f7a6f9ac89751ed18e9eceea27685a2afc96afa2
3
+ metadata.gz: 2dac67d35714c539c1f8049c06e3e040521d27b8
4
+ data.tar.gz: 98de1a200a81d2404ceb89ee8857317c810b0c75
5
5
  SHA512:
6
- metadata.gz: 3bc49305a332c10297de0d15b0b55ef5c9ef398c7f1ecb94fcc9772656dbe004b8063e6186d652a26272d370ed47bfc16b8648342386b1001c4b31f01363362d
7
- data.tar.gz: 988f0484835b53d7373df49c55e69301f3f7aea24908e875a7117cdcf9fb78a7cf7345bbb8b037eb0c989885e9351cdb5660caa29bcfd72c6b6a09d9922052c7
6
+ metadata.gz: a8f4d774ab03dfad0faea07cd98591bc00873c1647ca498dc3ae1b26e60198ff934059a92d3835db60fc4271105d15583e6a6ccee64cfc37756c5d12ce03d241
7
+ data.tar.gz: 852d4db734b37f6613ce305e6c7fd146ab32f09ee379700254209b0e2ceb6c0d11d4899b7521aeb4973e3da1f65954d5f9b2ea1b2dd39132bf6aae89c5e199bf
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Change Log
2
2
  ## Unreleased
3
3
 
4
+ ## 1.4.1
5
+ ### Fixed
6
+ * Fix localized resource serialization[#95](https://github.com/contentful/contentful_middleman/issues/95)
7
+
4
8
  ## 1.4.0
5
9
 
6
10
  ### Added
@@ -44,10 +44,15 @@ module ContentfulMiddleman
44
44
  value.hashize
45
45
  when ::Array
46
46
  value.map {|element| ensure_primitive_data_types(element)}
47
+ when ::Hash
48
+ res = {}
49
+ value.each do |k, v|
50
+ res[ensure_primitive_data_types(k)] = ensure_primitive_data_types(v)
51
+ end
52
+ res
47
53
  else
48
54
  value
49
55
  end
50
56
  end
51
-
52
57
  end
53
58
  end
@@ -30,8 +30,16 @@ module ContentfulMiddleman
30
30
  end
31
31
 
32
32
  def map_field(context, field_name, field_value)
33
- value_mapping = map_value(field_value)
34
- context.set(field_name, value_mapping)
33
+ if has_multiple_locales?
34
+ processed_locales = {}
35
+ field_value.each do |locale, value|
36
+ processed_locales[locale] = map_value(value)
37
+ end
38
+ context.set(field_name, processed_locales)
39
+ else
40
+ value_mapping = map_value(field_value)
41
+ context.set(field_name, value_mapping)
42
+ end
35
43
  end
36
44
 
37
45
  def map_value(value)
@@ -66,7 +74,7 @@ module ContentfulMiddleman
66
74
  fields = has_multiple_locales? ? entry.fields_with_locales : entry.fields
67
75
 
68
76
  # Prevent entries with no values from breaking the import
69
- fields ||= []
77
+ fields ||= {}
70
78
 
71
79
  fields.each {|k, v| map_field context, k, v}
72
80
  end
@@ -1,3 +1,3 @@
1
1
  module ContentfulMiddleman
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -62,11 +62,9 @@ describe ContentfulMiddleman::Mapper::Base do
62
62
  },
63
63
  :image=>{
64
64
  :'en-US'=>{
65
- "sys"=>{
66
- "type"=>"Link",
67
- "linkType"=>"Asset",
68
- "id"=>"1x0xpXu4pSGS4OukSyWGUK"
69
- }
65
+ :title=>"Doge",
66
+ :description=>"nice picture",
67
+ :url=>"//images.contentful.com/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg"
70
68
  }
71
69
  },
72
70
  :description=>{
@@ -78,6 +76,46 @@ describe ContentfulMiddleman::Mapper::Base do
78
76
 
79
77
  expect(context.hashize).to eq(expected)
80
78
  end
79
+
80
+ it 'maps entries with multiple locales with nested resources' do
81
+ vcr('entries/localized_references') {
82
+ subject = described_class.new entries, OptionsDouble.new(cda_query: {locale: '*'})
83
+ expect(context.hashize).to eq({})
84
+
85
+ expected = {
86
+ :id=>"42kEjzNj9mIci2eyGOISiQ",
87
+ :image=>{
88
+ :'en-US'=>{
89
+ title: "image-view-1139205 960 720",
90
+ description: nil,
91
+ url: "//images.contentful.com/1sjfpsn7l90g/6Rloj9MIxOwg0w2kqCaWS2/464b740a98d711905545f77d56fa3b2b/image-view-1139205_960_720.jpg"
92
+ },
93
+ :es=>{
94
+ title: "background-image-967820 960 720",
95
+ description: nil,
96
+ url: "//images.contentful.com/1sjfpsn7l90g/2WGPppy4laAWWgUiWG02SA/3951271109e19ae45b21bb044b24b3ec/background-image-967820_960_720.jpg"
97
+ },
98
+ :zh=>{
99
+ title: "image-view-1139204 960 720",
100
+ description: nil,
101
+ url: "//images.contentful.com/1sjfpsn7l90g/6zkhmrCizKuQUG0UmYKe4W/a8f90059b5bfd620791814f2c3edfaa4/image-view-1139204_960_720.jpg"
102
+ }
103
+ }
104
+ }
105
+
106
+ client = Contentful::Client.new(
107
+ space: '1sjfpsn7l90g',
108
+ access_token: 'e451a3cdfced9000220be41ed9c899866e8d52aa430eaf7c35b09df8fc6326f9',
109
+ dynamic_entries: :auto
110
+ )
111
+
112
+ entries = client.entries(locale: '*')
113
+
114
+ subject.map(context, entries.first)
115
+
116
+ expect(context.hashize).to eq(expected)
117
+ }
118
+ end
81
119
  end
82
120
  end
83
121
 
@@ -0,0 +1,214 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cdn.contentful.com/spaces/1sjfpsn7l90g/content_types?limit=1000
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulGem/1.0.0
12
+ Authorization:
13
+ - Bearer e451a3cdfced9000220be41ed9c899866e8d52aa430eaf7c35b09df8fc6326f9
14
+ Content-Type:
15
+ - application/vnd.contentful.delivery.v1+json
16
+ Accept-Encoding:
17
+ - gzip
18
+ Connection:
19
+ - close
20
+ Host:
21
+ - cdn.contentful.com
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Access-Control-Allow-Headers:
28
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation,X-Contentful-User-Agent
29
+ Access-Control-Allow-Methods:
30
+ - GET,HEAD,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Expose-Headers:
34
+ - Etag
35
+ Access-Control-Max-Age:
36
+ - '86400'
37
+ Cache-Control:
38
+ - max-age=0
39
+ Content-Type:
40
+ - application/vnd.contentful.delivery.v1+json
41
+ Etag:
42
+ - '"a684f9ee6d6e80804ecfc6ad741f3b28"'
43
+ Server:
44
+ - Contentful
45
+ X-Content-Type-Options:
46
+ - nosniff
47
+ - nosniff
48
+ X-Contentful-Request-Id:
49
+ - eaef9f65adddf842356893d4ff94a061
50
+ Content-Length:
51
+ - '809'
52
+ Accept-Ranges:
53
+ - bytes
54
+ Date:
55
+ - Thu, 29 Sep 2016 22:30:25 GMT
56
+ Via:
57
+ - 1.1 varnish
58
+ Age:
59
+ - '4828'
60
+ Connection:
61
+ - close
62
+ X-Served-By:
63
+ - cache-gru7124-GRU
64
+ X-Cache:
65
+ - HIT
66
+ X-Cache-Hits:
67
+ - '1'
68
+ X-Timer:
69
+ - S1475188225.132636,VS0,VE0
70
+ Vary:
71
+ - Accept-Encoding
72
+ body:
73
+ encoding: ASCII-8BIT
74
+ string: |
75
+ {
76
+ "sys": {
77
+ "type": "Array"
78
+ },
79
+ "total": 1,
80
+ "skip": 0,
81
+ "limit": 1000,
82
+ "items": [
83
+ {
84
+ "sys": {
85
+ "space": {
86
+ "sys": {
87
+ "type": "Link",
88
+ "linkType": "Space",
89
+ "id": "1sjfpsn7l90g"
90
+ }
91
+ },
92
+ "id": "test",
93
+ "type": "ContentType",
94
+ "createdAt": "2016-09-29T14:46:41.071Z",
95
+ "updatedAt": "2016-09-29T14:46:41.071Z",
96
+ "revision": 1
97
+ },
98
+ "displayField": null,
99
+ "name": "Test",
100
+ "description": "",
101
+ "fields": [
102
+ {
103
+ "id": "image",
104
+ "name": "Image",
105
+ "type": "Link",
106
+ "localized": true,
107
+ "required": false,
108
+ "disabled": false,
109
+ "omitted": false,
110
+ "linkType": "Asset"
111
+ }
112
+ ]
113
+ }
114
+ ]
115
+ }
116
+ http_version:
117
+ recorded_at: Thu, 29 Sep 2016 22:30:25 GMT
118
+ - request:
119
+ method: get
120
+ uri: https://cdn.contentful.com/spaces/1sjfpsn7l90g/entries?locale=*
121
+ body:
122
+ encoding: US-ASCII
123
+ string: ''
124
+ headers:
125
+ User-Agent:
126
+ - RubyContentfulGem/1.0.0
127
+ Authorization:
128
+ - Bearer e451a3cdfced9000220be41ed9c899866e8d52aa430eaf7c35b09df8fc6326f9
129
+ Content-Type:
130
+ - application/vnd.contentful.delivery.v1+json
131
+ Accept-Encoding:
132
+ - gzip
133
+ Connection:
134
+ - close
135
+ Host:
136
+ - cdn.contentful.com
137
+ response:
138
+ status:
139
+ code: 200
140
+ message: OK
141
+ headers:
142
+ Access-Control-Allow-Headers:
143
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation,X-Contentful-User-Agent
144
+ Access-Control-Allow-Methods:
145
+ - GET,HEAD,OPTIONS
146
+ Access-Control-Allow-Origin:
147
+ - "*"
148
+ Access-Control-Expose-Headers:
149
+ - Etag
150
+ Access-Control-Max-Age:
151
+ - '86400'
152
+ Cache-Control:
153
+ - max-age=0
154
+ Content-Encoding:
155
+ - gzip
156
+ Content-Type:
157
+ - application/vnd.contentful.delivery.v1+json
158
+ Etag:
159
+ - W/"d74db949e37697354c70ebc8d3ac5301"
160
+ Server:
161
+ - Contentful
162
+ X-Content-Type-Options:
163
+ - nosniff
164
+ - nosniff
165
+ X-Contentful-Request-Id:
166
+ - 5a58a9b54ff533c49bab5b96f4654c08
167
+ Content-Length:
168
+ - '880'
169
+ Accept-Ranges:
170
+ - bytes
171
+ Date:
172
+ - Thu, 29 Sep 2016 22:30:25 GMT
173
+ Via:
174
+ - 1.1 varnish
175
+ Age:
176
+ - '4828'
177
+ Connection:
178
+ - close
179
+ X-Served-By:
180
+ - cache-gru7120-GRU
181
+ X-Cache:
182
+ - HIT
183
+ X-Cache-Hits:
184
+ - '21'
185
+ X-Timer:
186
+ - S1475188225.757896,VS0,VE0
187
+ Vary:
188
+ - Accept-Encoding
189
+ body:
190
+ encoding: ASCII-8BIT
191
+ string: !binary |-
192
+ H4sIAAAAAAAAA+2WXW/aMBSG7/srUK4HsR0nwb1DVYWqbu06itA2VVVCHDAk
193
+ ISOhDCr++2yHgCEhoxtrVWm5gPjj2Ofj9eM8n9VqWrJItPPaM3/ljXQRU97S
194
+ WtOps9B43+qDmJNOUifg/VC2kjGLeQPIRsBCloohkLVZSkOx4He5YLbs3i5y
195
+ pyR2+mKrfEbWqfgiOmRn7tNHFo01sef24btH4/u1zx254t4E5olwYDLy4ySy
196
+ AwIGIqr8WW3eZZzZo2U2GI0vR8ubEQmv+gzRRfv2qsPulPU3jl1G6XShDvSn
197
+ 1Emp1xJ50RCAVh2QOiL3EJ+bxrmJGwayv6kGs9h7mcGUPrGETaK8JmvP+5Mo
198
+ pVG6zsjpUnuhrFua4JQm6YHErvO6SbDmMxp4W80J1zUWOoOCGmhU73b2JFIi
199
+ pXXsFTKRMt0KpZUkNN0TivBBSsX6EkxG5NPVz9v5AMzR+MeF0+sgNTZ+KFQJ
200
+ qfnQ6G5cMjb1gK0lJrpP5C/qtT/H8QIHTqvXG3RZrw1Qp3Wsv8vhq+d3OR6G
201
+ 0wu2vJ7dddugG369prhX4e/2iOZKkv+iBg+SQCzqBzNPybyWFThn0JZCpcUo
202
+ JVHpTFnN48tWxqONzA4RqUpcmUAPFHxHhhuMF5SuVbMJWQ1sQZVN3ONqOpWa
203
+ qHzaFlBhbAkERHJZGuxjgHfnINBcpz8eTCezyKtLYtSJZTcRqBEL1GwEdgi0
204
+ kxCfVa2rglIWeTYVt52m63KXpLHmqj8L+Guoq8XTy+uhG8SEyIYQEAqJQ7Hp
205
+ Iui6AGMXYdegff1ALI88lkceS2MUD4qM8mjqsKAIGel1wpYiecjEBjF2MS3H
206
+ yyArBuTgnHmpgAHfumjKx4eUDYbiQuMTFPxl1ioQRY9ym66XFwW4cUL5cfFH
207
+ ke9ebVks+iimO/f53ukpoiMPbVvxEjy/NyIcuLJORgQTk5cSoWjyj4iQYeCJ
208
+ 0XkdQoMgYL4pDMpLoWMLuzYGDml6HAkEmCY2fdv2TMt3DBe5GWfqahin4AA0
209
+ kFk8zMdxgGOoaKpywMJ/y4Fi7aqD/o8ACdMduOZfreVfVSdDALatlyKgaPJa
210
+ CMBvi4DSUuhO0ycAmMQ1Xd+zELAJbELso75BPd9xcBEBuPo0HPMpAA3YtN4V
211
+ An4T9GkQIL8LHvjv6mx19gvB1oxYBREAAA==
212
+ http_version:
213
+ recorded_at: Thu, 29 Sep 2016 22:30:25 GMT
214
+ recorded_with: VCR 3.0.3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_middleman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sascha Konietzke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-26 00:00:00.000000000 Z
12
+ date: 2016-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
@@ -239,6 +239,7 @@ files:
239
239
  - spec/fixtures/space_hash_fixtures/.foo-space-hash
240
240
  - spec/fixtures/space_hash_fixtures/.foobar-space-hash
241
241
  - spec/fixtures/space_hash_fixtures/.my_space-space-hash
242
+ - spec/fixtures/vcr_fixtures/entries/localized_references.yml
242
243
  - spec/fixtures/vcr_fixtures/entries/nil_file.yml
243
244
  - spec/fixtures/vcr_fixtures/helpers/preview.yml
244
245
  - spec/fixtures/vcr_fixtures/instance/entries_1.yml
@@ -300,6 +301,7 @@ test_files:
300
301
  - spec/fixtures/space_hash_fixtures/.foo-space-hash
301
302
  - spec/fixtures/space_hash_fixtures/.foobar-space-hash
302
303
  - spec/fixtures/space_hash_fixtures/.my_space-space-hash
304
+ - spec/fixtures/vcr_fixtures/entries/localized_references.yml
303
305
  - spec/fixtures/vcr_fixtures/entries/nil_file.yml
304
306
  - spec/fixtures/vcr_fixtures/helpers/preview.yml
305
307
  - spec/fixtures/vcr_fixtures/instance/entries_1.yml