contentful_middleman 2.1.1 → 2.1.2

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: 7d3cf9d63abb5e3bf74efca714827687e72ee6db
4
- data.tar.gz: 609b5a7b692b432baeac066758c943201ca6a49a
3
+ metadata.gz: ee66e9f9a3bd4d95df237d74d9e4e112e2bf3ea3
4
+ data.tar.gz: 59ce9a704e69c4b5b0c96f82dd5b4e6debe15a92
5
5
  SHA512:
6
- metadata.gz: 85ebc4e4256b007c9fc3e61a5fb3abfd41eb051cc0f04ee0ecc0471d0f2a02ec878bb5c0d15688dfefbc62b24cb542e107abe027e78c548970b2d205b7cd933f
7
- data.tar.gz: 1e135095400bc614778e93253abb36bb2ede7e8532f06776e48694ba9968a0e48f732ab91effddef3c869a0aac0fc998ef42f205904fe652807709f7c70973b2
6
+ metadata.gz: ac290f4886ea33f87d16b720f9e8ced955524b883a2c7351a4684effb3bae691d015a8d95431ee04e37065d211a26e88fe2333d1c359ef2dbbef20fd83336dcc
7
+ data.tar.gz: df49b31585e907db09bff424e86c51a3608ce40a97fc4aa9a8e295682e20a277cbcf6ffab7fe731c592bf4e70d67b7b253f769f7ab5f14404f18be5266caa88e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Change Log
2
2
  ## Unreleased
3
3
 
4
+ ## 2.1.2
5
+ ### Fixed
6
+ * `localize` helpers now properly serialized nested resources [#131](https://github.com/contentful/contentful_middleman/pull/131)
7
+
4
8
  ## 2.1.1
5
9
  ### Fixed
6
10
  * `localize` helpers now properly serialize `_meta` attributes [#124](https://github.com/contentful/contentful_middleman/issues/124) [#128](https://github.com/contentful/contentful_middleman/issues/128)
@@ -48,7 +48,7 @@ def self.BackrefMapper(content_type_id, content_type_field, backref_field)
48
48
 
49
49
  def map(context, entry)
50
50
  super
51
- content_type_entries = @entries.select { |e| e.sys[:contentType].id == @@content_type_id }
51
+ content_type_entries = @entries.select { |e| e.sys[:content_type].id == @@content_type_id }
52
52
  referencing_entries = content_type_entries.select{ |e| e.send(@@content_type_field).map{|x| x.id}.include? entry.id }
53
53
  referencing_ids = referencing_entries.map{ |e| e.id }
54
54
  context.set(@@backref_field, map_value(referencing_ids))
@@ -1,3 +1,4 @@
1
+ require 'thor/core_ext/hash_with_indifferent_access'
1
2
  require 'contentful_middleman/tools/preview_proxy'
2
3
 
3
4
  module ContentfulMiddleman
@@ -7,7 +8,7 @@ module ContentfulMiddleman
7
8
  end
8
9
 
9
10
  def localize_entry(entry, locale, fallback_locale='en-US')
10
- localized_entry = {}
11
+ localized_entry = ::Thor::CoreExt::HashWithIndifferentAccess.new
11
12
  entry.each do |field, value|
12
13
  localized_entry[field] = localize(entry, field, locale, fallback_locale)
13
14
  end
@@ -28,10 +29,11 @@ module ContentfulMiddleman
28
29
  end
29
30
 
30
31
  def localize_value(value, locale, fallback_locale='en-US')
31
- if value.respond_to? :fetch
32
- return value.fetch(locale) if value.key? locale
33
- return value.fetch(fallback_locale) if value.key? fallback_locale
34
- end
32
+ value = value.fetch(locale) if value.respond_to?(:fetch) && value.respond_to?(:key?) && value.key?(locale)
33
+ value = value.fetch(fallback_locale) if value.respond_to?(:fetch) && value.respond_to?(:key?) && value.key?(fallback_locale)
34
+
35
+ return localize_array(value, locale, fallback_locale) if value.is_a? ::Array
36
+ return localize_entry(value, locale, fallback_locale) if value.is_a? ::Hash
35
37
  value
36
38
  end
37
39
 
@@ -1,3 +1,3 @@
1
1
  module ContentfulMiddleman
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
@@ -22,7 +22,42 @@ describe ContentfulMiddleman::Helpers do
22
22
  'es' => 'foobar',
23
23
  'en-US' => 'baz'
24
24
  }
25
- ]
25
+ ],
26
+ nested_array: {
27
+ 'en-US' => [
28
+ {
29
+ id: 'foo',
30
+ _meta: {
31
+ id: 'foo'
32
+ },
33
+ name: {
34
+ 'es' => 'foo',
35
+ 'en-US' => 'bar'
36
+ }
37
+ }, {
38
+ id: 'foo',
39
+ _meta: {
40
+ id: 'foo'
41
+ },
42
+ name: {
43
+ 'en-NZ' => 'bar',
44
+ 'en-US' => 'foo'
45
+ },
46
+ }
47
+ ]
48
+ },
49
+ nested_hash: {
50
+ 'en-US' => {
51
+ id: 'foo',
52
+ _meta: {
53
+ id: 'foo'
54
+ },
55
+ name: {
56
+ 'es' => 'foo',
57
+ 'en-US' => 'bar'
58
+ }
59
+ }
60
+ }
26
61
  }
27
62
  end
28
63
 
@@ -92,11 +127,38 @@ describe ContentfulMiddleman::Helpers do
92
127
  end
93
128
 
94
129
  it '#localize_entry' do
95
- expect(subject.localize_entry(entry, 'es')).to eq({
96
- _meta: { id: 'foo' },
97
- value_field: 'foo',
98
- array_field: ['foobar']
130
+ localized_entry = subject.localize_entry(entry, 'es')
131
+ expect(localized_entry).to eq({
132
+ '_meta' => { 'id' => 'foo' },
133
+ 'value_field' => 'foo',
134
+ 'array_field' => ['foobar'],
135
+ 'nested_array' => [
136
+ {
137
+ 'id' => 'foo',
138
+ '_meta' => {
139
+ 'id' => 'foo'
140
+ },
141
+ 'name' => 'foo'
142
+ }, {
143
+ 'id' => 'foo',
144
+ '_meta' => {
145
+ 'id' => 'foo'
146
+ },
147
+ 'name' => 'foo'
148
+ }
149
+ ],
150
+ 'nested_hash' => {
151
+ 'id' => 'foo',
152
+ '_meta' => {
153
+ 'id' => 'foo'
154
+ },
155
+ 'name' => 'foo'
156
+ }
99
157
  })
158
+
159
+ expect(localized_entry[:_meta]).to eq({ 'id' => 'foo' })
160
+ expect(localized_entry[:nested_array][0][:id]).to eq('foo')
161
+ expect(localized_entry[:nested_hash][:id]).to eq('foo')
100
162
  end
101
163
  end
102
164
 
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: 2.1.1
4
+ version: 2.1.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: 2017-07-12 00:00:00.000000000 Z
12
+ date: 2017-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
@@ -297,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
297
297
  version: '0'
298
298
  requirements: []
299
299
  rubyforge_project:
300
- rubygems_version: 2.6.12
300
+ rubygems_version: 2.6.11
301
301
  signing_key:
302
302
  specification_version: 4
303
303
  summary: Include mangablable content from the Contentful CMS and API into your Middleman