contentful_middleman 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/contentful_middleman/commands/context.rb +4 -0
- data/lib/contentful_middleman/mappers/base.rb +16 -10
- data/lib/contentful_middleman/version.rb +1 -1
- data/spec/contentful_middleman/mappers/base_spec.rb +36 -0
- data/spec/fixtures/vcr_fixtures/entries/localized_references_localized_assets.yml +214 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4803cd6c6ea14906e4ed4d4a533d9ddb11d262b3
|
4
|
+
data.tar.gz: f3706b7c56d6f84723efb1a56cd42d757a07c8e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df23abc8d6ced3f47311cc19f0b8cb929c37854fdf628813dff8652215ee2ceda1febc7e06d53a42e86686018652835741f02b79ce5fa92cd32e8cc86f0cfd09
|
7
|
+
data.tar.gz: 60fb4dc515c2d4d9a034752f8f6138f95b911b5baa6cea976a080c01e23c9b7003ca960eadb0a869da21380bf4a01e9b935830dbc12c68ef3fd3d1bb2623216f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Change Log
|
2
2
|
## Unreleased
|
3
3
|
|
4
|
+
## 1.4.2
|
5
|
+
### Fixed
|
6
|
+
* Fix localized resource serialization for localized Assets[#95](https://github.com/contentful/contentful_middleman/issues/95)
|
7
|
+
|
4
8
|
## 1.4.1
|
5
9
|
### Fixed
|
6
10
|
* Fix localized resource serialization[#95](https://github.com/contentful/contentful_middleman/issues/95)
|
@@ -33,7 +33,7 @@ module ContentfulMiddleman
|
|
33
33
|
if has_multiple_locales?
|
34
34
|
processed_locales = {}
|
35
35
|
field_value.each do |locale, value|
|
36
|
-
processed_locales[locale] = map_value(value)
|
36
|
+
processed_locales[locale] = map_value(value, locale.to_s)
|
37
37
|
end
|
38
38
|
context.set(field_name, processed_locales)
|
39
39
|
else
|
@@ -42,10 +42,10 @@ module ContentfulMiddleman
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def map_value(value)
|
45
|
+
def map_value(value, locale = nil)
|
46
46
|
case value
|
47
47
|
when Contentful::Asset
|
48
|
-
map_asset(value)
|
48
|
+
map_asset(value, locale)
|
49
49
|
when Contentful::Location
|
50
50
|
map_location(value)
|
51
51
|
when Contentful::Link
|
@@ -53,17 +53,23 @@ module ContentfulMiddleman
|
|
53
53
|
when Contentful::DynamicEntry
|
54
54
|
map_entry(value)
|
55
55
|
when Array
|
56
|
-
map_array(value)
|
56
|
+
map_array(value, locale)
|
57
57
|
else
|
58
58
|
value
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def map_asset(asset)
|
62
|
+
def map_asset(asset, locale = nil)
|
63
63
|
context = Context.new
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
if locale
|
65
|
+
context.title = asset.fields(locale)[:title]
|
66
|
+
context.description = asset.fields(locale)[:description]
|
67
|
+
context.url = asset.fields(locale)[:file].url unless asset.fields(locale)[:file].nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
context.title = asset.title unless context.has?(:title) && !context.title.nil?
|
71
|
+
context.description = asset.description unless context.has?(:description) && !context.description.nil?
|
72
|
+
context.url = asset.file.url unless asset.file.nil? || (context.has?(:url) && !context.url.nil?)
|
67
73
|
|
68
74
|
context
|
69
75
|
end
|
@@ -100,8 +106,8 @@ module ContentfulMiddleman
|
|
100
106
|
context
|
101
107
|
end
|
102
108
|
|
103
|
-
def map_array(array)
|
104
|
-
array.map {|element| map_value(element)}
|
109
|
+
def map_array(array, locale = nil)
|
110
|
+
array.map {|element| map_value(element, locale)}
|
105
111
|
end
|
106
112
|
end
|
107
113
|
end
|
@@ -116,6 +116,42 @@ describe ContentfulMiddleman::Mapper::Base do
|
|
116
116
|
expect(context.hashize).to eq(expected)
|
117
117
|
}
|
118
118
|
end
|
119
|
+
|
120
|
+
it 'maps entries with multiple locales with nested resources that are also localized' do
|
121
|
+
vcr('entries/localized_references_localized_assets') {
|
122
|
+
subject = described_class.new entries, OptionsDouble.new(cda_query: {locale: '*'})
|
123
|
+
expect(context.hashize).to eq({})
|
124
|
+
|
125
|
+
expected = {
|
126
|
+
id: "2HjFERK39eeCYegCayUkMK",
|
127
|
+
image: {
|
128
|
+
:"en-US" => {
|
129
|
+
title: "EN Title",
|
130
|
+
description: "EN Description",
|
131
|
+
url: "//assets.contentful.com/bht13amj0fva/14bZJKTr6AoaGyeg4kYiWq/13f00bdf75c1320061ce471a3881e831/Flag_of_the_United_States.svg"
|
132
|
+
},
|
133
|
+
es: {
|
134
|
+
title: "ES Title",
|
135
|
+
description: "ES Description",
|
136
|
+
url: "//assets.contentful.com/bht13amj0fva/14bZJKTr6AoaGyeg4kYiWq/5501c98c296af77b9acba1146ea3e211/Flag_of_Spain.svg"
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
client = Contentful::Client.new(
|
142
|
+
space: 'bht13amj0fva',
|
143
|
+
access_token: 'bb703a05e107148bed6ee246a9f6b3678c63fed7335632eb68fe1b689c801534',
|
144
|
+
dynamic_entries: :auto
|
145
|
+
)
|
146
|
+
|
147
|
+
entry = client.entries(locale: '*').first
|
148
|
+
|
149
|
+
subject.map(context, entry)
|
150
|
+
|
151
|
+
expect(entry.image.id).to eq(entry.fields('es')[:image].id)
|
152
|
+
expect(context.hashize).to eq(expected)
|
153
|
+
}
|
154
|
+
end
|
119
155
|
end
|
120
156
|
end
|
121
157
|
|
@@ -0,0 +1,214 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://cdn.contentful.com/spaces/bht13amj0fva/content_types?limit=1000
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- RubyContentfulGem/1.0.1
|
12
|
+
Authorization:
|
13
|
+
- Bearer bb703a05e107148bed6ee246a9f6b3678c63fed7335632eb68fe1b689c801534
|
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
|
+
- '"79ff2349ce217bd8393ccf0929f39692"'
|
43
|
+
Server:
|
44
|
+
- Contentful
|
45
|
+
Strict-Transport-Security:
|
46
|
+
- max-age=0
|
47
|
+
X-Content-Type-Options:
|
48
|
+
- nosniff
|
49
|
+
- nosniff
|
50
|
+
X-Contentful-Request-Id:
|
51
|
+
- a946bc1a0976f80a014f06d1a9ee246b
|
52
|
+
Content-Length:
|
53
|
+
- '809'
|
54
|
+
Accept-Ranges:
|
55
|
+
- bytes
|
56
|
+
Date:
|
57
|
+
- Wed, 05 Oct 2016 14:33:01 GMT
|
58
|
+
Via:
|
59
|
+
- 1.1 varnish
|
60
|
+
Age:
|
61
|
+
- '0'
|
62
|
+
Connection:
|
63
|
+
- close
|
64
|
+
X-Served-By:
|
65
|
+
- cache-gru7120-GRU
|
66
|
+
X-Cache:
|
67
|
+
- MISS
|
68
|
+
X-Cache-Hits:
|
69
|
+
- '0'
|
70
|
+
X-Timer:
|
71
|
+
- S1475677981.403335,VS0,VE335
|
72
|
+
Vary:
|
73
|
+
- Accept-Encoding
|
74
|
+
body:
|
75
|
+
encoding: ASCII-8BIT
|
76
|
+
string: |
|
77
|
+
{
|
78
|
+
"sys": {
|
79
|
+
"type": "Array"
|
80
|
+
},
|
81
|
+
"total": 1,
|
82
|
+
"skip": 0,
|
83
|
+
"limit": 1000,
|
84
|
+
"items": [
|
85
|
+
{
|
86
|
+
"sys": {
|
87
|
+
"space": {
|
88
|
+
"sys": {
|
89
|
+
"type": "Link",
|
90
|
+
"linkType": "Space",
|
91
|
+
"id": "bht13amj0fva"
|
92
|
+
}
|
93
|
+
},
|
94
|
+
"id": "test",
|
95
|
+
"type": "ContentType",
|
96
|
+
"createdAt": "2016-10-05T14:29:07.531Z",
|
97
|
+
"updatedAt": "2016-10-05T14:31:56.190Z",
|
98
|
+
"revision": 2
|
99
|
+
},
|
100
|
+
"displayField": null,
|
101
|
+
"name": "Test",
|
102
|
+
"description": "",
|
103
|
+
"fields": [
|
104
|
+
{
|
105
|
+
"id": "image",
|
106
|
+
"name": "image",
|
107
|
+
"type": "Link",
|
108
|
+
"localized": true,
|
109
|
+
"required": false,
|
110
|
+
"disabled": false,
|
111
|
+
"omitted": false,
|
112
|
+
"linkType": "Asset"
|
113
|
+
}
|
114
|
+
]
|
115
|
+
}
|
116
|
+
]
|
117
|
+
}
|
118
|
+
http_version:
|
119
|
+
recorded_at: Wed, 05 Oct 2016 14:33:01 GMT
|
120
|
+
- request:
|
121
|
+
method: get
|
122
|
+
uri: https://cdn.contentful.com/spaces/bht13amj0fva/entries?locale=*
|
123
|
+
body:
|
124
|
+
encoding: US-ASCII
|
125
|
+
string: ''
|
126
|
+
headers:
|
127
|
+
User-Agent:
|
128
|
+
- RubyContentfulGem/1.0.1
|
129
|
+
Authorization:
|
130
|
+
- Bearer bb703a05e107148bed6ee246a9f6b3678c63fed7335632eb68fe1b689c801534
|
131
|
+
Content-Type:
|
132
|
+
- application/vnd.contentful.delivery.v1+json
|
133
|
+
Accept-Encoding:
|
134
|
+
- gzip
|
135
|
+
Connection:
|
136
|
+
- close
|
137
|
+
Host:
|
138
|
+
- cdn.contentful.com
|
139
|
+
response:
|
140
|
+
status:
|
141
|
+
code: 200
|
142
|
+
message: OK
|
143
|
+
headers:
|
144
|
+
Access-Control-Allow-Headers:
|
145
|
+
- 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
|
146
|
+
Access-Control-Allow-Methods:
|
147
|
+
- GET,HEAD,OPTIONS
|
148
|
+
Access-Control-Allow-Origin:
|
149
|
+
- "*"
|
150
|
+
Access-Control-Expose-Headers:
|
151
|
+
- Etag
|
152
|
+
Access-Control-Max-Age:
|
153
|
+
- '86400'
|
154
|
+
Cache-Control:
|
155
|
+
- max-age=0
|
156
|
+
Content-Encoding:
|
157
|
+
- gzip
|
158
|
+
Content-Type:
|
159
|
+
- application/vnd.contentful.delivery.v1+json
|
160
|
+
Etag:
|
161
|
+
- W/"9eb6afcb4d25e10d50af4c9240520a51"
|
162
|
+
Server:
|
163
|
+
- Contentful
|
164
|
+
Strict-Transport-Security:
|
165
|
+
- max-age=0
|
166
|
+
X-Content-Type-Options:
|
167
|
+
- nosniff
|
168
|
+
- nosniff
|
169
|
+
X-Contentful-Request-Id:
|
170
|
+
- d623eaae9eb80e5eaaec79eecc075d97
|
171
|
+
Content-Length:
|
172
|
+
- '695'
|
173
|
+
Accept-Ranges:
|
174
|
+
- bytes
|
175
|
+
Date:
|
176
|
+
- Wed, 05 Oct 2016 14:33:02 GMT
|
177
|
+
Via:
|
178
|
+
- 1.1 varnish
|
179
|
+
Age:
|
180
|
+
- '0'
|
181
|
+
Connection:
|
182
|
+
- close
|
183
|
+
X-Served-By:
|
184
|
+
- cache-gru7124-GRU
|
185
|
+
X-Cache:
|
186
|
+
- MISS
|
187
|
+
X-Cache-Hits:
|
188
|
+
- '0'
|
189
|
+
X-Timer:
|
190
|
+
- S1475677981.908967,VS0,VE168
|
191
|
+
Vary:
|
192
|
+
- Accept-Encoding
|
193
|
+
body:
|
194
|
+
encoding: ASCII-8BIT
|
195
|
+
string: !binary |-
|
196
|
+
H4sIAAAAAAAAA8VVTY/aMBC98yuQry3ETiAf3BBlW5V2DwVU7VYrZBKH9ZIE
|
197
|
+
mpjVpiv+e20nISYkUVm1qi/xOLZn5s1749dOtwuSNAGj7iufcoOle8ItMI5j
|
198
|
+
nAK+dnwv9rAdwwFfR9JKtnTPDSiNgIaUiV8wsykjobjwh7wwu7biRXpK9tgV
|
199
|
+
rood2aISi1iQi0VMX2i0BcJnObj3aLvIY57LGysbqCfSWT8yZODwCfrPWGRV
|
200
|
+
jONpLvPMBsjO6J+ebqbfZoZDyOSObCY4XW6/zpT7T4FNIxan6g83JpgRbyxw
|
201
|
+
ATpEZg/BHhwu0GBk6CNo9S3DuVcPHPbedQdi8kwTuouKmuSRu7uIkYjliPw9
|
202
|
+
aCfKvbUAM5KwBmBzXE8AA5+SwCs5J0IHNMSbCzaQqLecVyhSQ6U89xaaSJqW
|
203
|
+
RBknCWEVoogYJFXQYH3/ebaIzfEOf0zJZrC9o99/qrlxUagUUvEA5DwvmZsq
|
204
|
+
sJxiYvl/xVtSvqiM/IqcHqSiaeQGB0/JBGSAFZouVV2bXK2ya3dKdP4chjp9
|
205
|
+
n8rWpPC2YrUW/Kysp7Z4wRzQpnU0Msw+tHVV6zziNrU3HFH1XhZQ6Vk1ohLg
|
206
|
+
UhZUZcWXC2GB6W13IbdURC2LD6bz/G8j3TlL3JjuWdaJ1H5T8fJB2djkS93T
|
207
|
+
6NGnbQmdRyCgjsWzBTQNi8ol/bxB+oeAT0NNZY2GapWvIcOHcO351tBFhg6h
|
208
|
+
iVwysBA2bBsR20DaTYA3q52/Yo9ktYz4++et5oy386SfPG8u24xHGKbBZZ/I
|
209
|
+
egX9JeplO46CgJTnOWo8NYHELQ7lc31lCOfPRNZ8NR7su5cwqHS6umL9C5SH
|
210
|
+
Q4hcx3Z1x8S+Za0d7K4xQgOTYIPoqESZdwEavR1ZE+rD4ZuwbXF8BZ4qsUsh
|
211
|
+
57PsXXng1rFz7PwG7Hlx6Z4JAAA=
|
212
|
+
http_version:
|
213
|
+
recorded_at: Wed, 05 Oct 2016 14:33:02 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.
|
4
|
+
version: 1.4.2
|
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-10-
|
12
|
+
date: 2016-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: middleman-core
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- spec/fixtures/space_hash_fixtures/.foobar-space-hash
|
241
241
|
- spec/fixtures/space_hash_fixtures/.my_space-space-hash
|
242
242
|
- spec/fixtures/vcr_fixtures/entries/localized_references.yml
|
243
|
+
- spec/fixtures/vcr_fixtures/entries/localized_references_localized_assets.yml
|
243
244
|
- spec/fixtures/vcr_fixtures/entries/nil_file.yml
|
244
245
|
- spec/fixtures/vcr_fixtures/helpers/preview.yml
|
245
246
|
- spec/fixtures/vcr_fixtures/instance/entries_1.yml
|
@@ -302,6 +303,7 @@ test_files:
|
|
302
303
|
- spec/fixtures/space_hash_fixtures/.foobar-space-hash
|
303
304
|
- spec/fixtures/space_hash_fixtures/.my_space-space-hash
|
304
305
|
- spec/fixtures/vcr_fixtures/entries/localized_references.yml
|
306
|
+
- spec/fixtures/vcr_fixtures/entries/localized_references_localized_assets.yml
|
305
307
|
- spec/fixtures/vcr_fixtures/entries/nil_file.yml
|
306
308
|
- spec/fixtures/vcr_fixtures/helpers/preview.yml
|
307
309
|
- spec/fixtures/vcr_fixtures/instance/entries_1.yml
|