prismic.io 1.4.5 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/prismic/fragments/slices.rb +51 -2
- data/lib/prismic/json_parsers.rb +16 -1
- data/lib/prismic/version.rb +1 -1
- data/spec/fragments_spec.rb +32 -2
- data/spec/responses_mocks/composite_slice.json +63 -0
- data/spec/responses_mocks/{slices.json → simple_slice.json} +0 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8474490a3982e6d9d3b995b3a848f08ecc9dda67
|
4
|
+
data.tar.gz: da268f235d65b3bf88fef8a5fb8d18d37f3556fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d4282305f84eb5ec333a80559ffe8691bd3ff3224e4042af1fe6f04cf4824f4b3c0f5595992af71eefc63c8f5b8f4b029ccf3bd6ba29e46d284392e29d5e29b
|
7
|
+
data.tar.gz: 9600c487806277d86ada6b55a02c3e86768ca5bc477dcd75310a03f2cb72f98faba2dc72cd33fe75d4e0d58467f0d6e25937edde7733cfd70455326041098284
|
data/Gemfile.lock
CHANGED
@@ -2,8 +2,57 @@
|
|
2
2
|
module Prismic
|
3
3
|
module Fragments
|
4
4
|
|
5
|
-
# A fragment of type
|
6
|
-
class
|
5
|
+
# A fragment of type CompositeSlice, an item in a SliceZone
|
6
|
+
class CompositeSlice < Fragment
|
7
|
+
attr_accessor :slice_type
|
8
|
+
attr_accessor :slice_label
|
9
|
+
attr_accessor :non_repeat
|
10
|
+
attr_accessor :repeat
|
11
|
+
|
12
|
+
def initialize(slice_type, slice_label, non_repeat, repeat)
|
13
|
+
@slice_type = slice_type
|
14
|
+
@slice_label = slice_label
|
15
|
+
@non_repeat = non_repeat
|
16
|
+
@repeat = repeat
|
17
|
+
end
|
18
|
+
|
19
|
+
# Generate an text representation of the group
|
20
|
+
#
|
21
|
+
# @return [String] the text representation
|
22
|
+
def as_text
|
23
|
+
non_repeat_text = ''
|
24
|
+
@non_repeat.each do |fragment_key, fragment_value|
|
25
|
+
non_repeat_text += fragment_value.as_text
|
26
|
+
end
|
27
|
+
|
28
|
+
"#{non_repeat_text}\n#{@repeat.as_text}"
|
29
|
+
end
|
30
|
+
|
31
|
+
# Generate an HTML representation of the group
|
32
|
+
#
|
33
|
+
# @param link_resolver [LinkResolver] The LinkResolver used to build
|
34
|
+
# application's specific URL
|
35
|
+
#
|
36
|
+
# @return [String] the HTML representation
|
37
|
+
def as_html(link_resolver=nil)
|
38
|
+
classes = ['slice']
|
39
|
+
unless (@slice_label.nil?)
|
40
|
+
classes.push(@slice_label)
|
41
|
+
end
|
42
|
+
|
43
|
+
non_repeat_html = ''
|
44
|
+
@non_repeat.each do |fragment_key, fragment_value|
|
45
|
+
non_repeat_html += fragment_value.as_html(link_resolver)
|
46
|
+
end
|
47
|
+
|
48
|
+
repeat_html = repeat.as_html(link_resolver)
|
49
|
+
|
50
|
+
%[<div data-slicetype="#{@slice_type}" class="#{classes.join(' ')}">#{non_repeat_html + repeat_html}</div>]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# A fragment of type SimpleSlice, an item in a SliceZone
|
55
|
+
class SimpleSlice < Fragment
|
7
56
|
attr_accessor :slice_type
|
8
57
|
attr_accessor :slice_label
|
9
58
|
attr_accessor :value
|
data/lib/prismic/json_parsers.rb
CHANGED
@@ -208,8 +208,23 @@ module Prismic
|
|
208
208
|
|
209
209
|
def slices_parser(json)
|
210
210
|
slices = []
|
211
|
+
|
211
212
|
json['value'].each do |data|
|
212
|
-
|
213
|
+
slice_type = data['slice_type']
|
214
|
+
slice_label = data['slice_label']
|
215
|
+
|
216
|
+
if data.key?('value')
|
217
|
+
slices << Prismic::Fragments::SimpleSlice.new(slice_type, slice_label, fragment_parser(data['value']))
|
218
|
+
else
|
219
|
+
non_repeat = {}
|
220
|
+
data['non-repeat'].each do |fragment_key, fragment_value|
|
221
|
+
non_repeat[fragment_key] = fragment_parser(fragment_value)
|
222
|
+
end
|
223
|
+
|
224
|
+
repeat = group_parser({ 'type' => 'Group', 'value' => data['repeat']})
|
225
|
+
|
226
|
+
slices << Prismic::Fragments::CompositeSlice.new(slice_type, slice_label, non_repeat, repeat)
|
227
|
+
end
|
213
228
|
end
|
214
229
|
Prismic::Fragments::SliceZone.new(slices)
|
215
230
|
end
|
data/lib/prismic/version.rb
CHANGED
data/spec/fragments_spec.rb
CHANGED
@@ -720,9 +720,9 @@ describe 'Group' do
|
|
720
720
|
|
721
721
|
end
|
722
722
|
|
723
|
-
describe '
|
723
|
+
describe 'Simple slice' do
|
724
724
|
before do
|
725
|
-
@raw_json_slices = File.read("#{File.dirname(__FILE__)}/responses_mocks/
|
725
|
+
@raw_json_slices = File.read("#{File.dirname(__FILE__)}/responses_mocks/simple_slice.json")
|
726
726
|
@json_slices = JSON.load(@raw_json_slices)
|
727
727
|
@doc = Prismic::JsonParser.document_parser(@json_slices)
|
728
728
|
@slices = @doc.get_slice_zone("article.blocks")
|
@@ -734,4 +734,34 @@ describe 'Slices' do
|
|
734
734
|
@slices.as_html(@link_resolver).gsub(''', "'").should == %[<div data-slicetype="features" class="slice features-label"><section data-field="illustration"><img src="https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg" alt="" width="4285" height="709" /></section>\n<section data-field="title"><span class="text">c'est un bloc features</span></section></div>\n<div data-slicetype="text" class="slice"><p>C'est un bloc content</p></div>\n<div data-slicetype="separator" class="slice"><section data-field="sep"><hr class="separator" /></section></div>]
|
735
735
|
end
|
736
736
|
|
737
|
+
it 'get item correctly' do
|
738
|
+
expected_url = 'https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg'
|
739
|
+
@slices.slices[0].value[0]["illustration"].url.should == expected_url
|
740
|
+
end
|
741
|
+
end
|
742
|
+
|
743
|
+
describe 'Composite slice' do
|
744
|
+
before do
|
745
|
+
@raw_json_slices = File.read("#{File.dirname(__FILE__)}/responses_mocks/composite_slice.json")
|
746
|
+
@json_slices = JSON.load(@raw_json_slices)
|
747
|
+
@doc = Prismic::JsonParser.document_parser(@json_slices)
|
748
|
+
@slices = @doc.get_slice_zone("nav-nodejs.items")
|
749
|
+
@link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.type}/#{doc_link.id}" }
|
750
|
+
end
|
751
|
+
|
752
|
+
it 'get html' do
|
753
|
+
@slices.as_html(@link_resolver).gsub(''', "'").should == %[<div data-slicetype="with-submenu" class="slice"><p>Getting Started</p><section data-field="label"><p>Start from Scratch</p></section>\n<section data-field="link"><a href="http://localhost/page-nodejs/WPeD0SoAACsABzNC">page---nodejs---getting-started-with-the-starter-kit</a></section></div>]
|
754
|
+
end
|
755
|
+
|
756
|
+
it 'get text' do
|
757
|
+
@slices.as_text.should == %[Getting Started\nStart from Scratch\n]
|
758
|
+
end
|
759
|
+
|
760
|
+
it 'get item in non-repeat correctly' do
|
761
|
+
@slices.slices[0].non_repeat['label'].as_text.should == 'Getting Started'
|
762
|
+
end
|
763
|
+
|
764
|
+
it 'get item in repeat correctly' do
|
765
|
+
@slices.slices[0].repeat[0]['label'].as_text.should == 'Start from Scratch'
|
766
|
+
end
|
737
767
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
{
|
2
|
+
"id": "WPeLbyoAACsAB1Su",
|
3
|
+
"uid": null,
|
4
|
+
"type": "nav-nodejs",
|
5
|
+
"href": "http://prismicio-docs.prismic.io/api/v1/documents/search?ref=WXnqmigAALs3V7Kx&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22WPeLbyoAACsAB1Su%22%29+%5D%5D",
|
6
|
+
"tags": [],
|
7
|
+
"first_publication_date": "2017-04-19T16:08:43+0000",
|
8
|
+
"last_publication_date": "2017-07-07T11:26:27+0000",
|
9
|
+
"slugs": ["navigation---nodejs", "navigation-nodejs"],
|
10
|
+
"data": {
|
11
|
+
"nav-nodejs": {
|
12
|
+
"display-name": {
|
13
|
+
"type": "StructuredText",
|
14
|
+
"value": [{
|
15
|
+
"type": "paragraph",
|
16
|
+
"text": "Navigation - NodeJS",
|
17
|
+
"spans": []
|
18
|
+
}]
|
19
|
+
},
|
20
|
+
"items": {
|
21
|
+
"type": "SliceZone",
|
22
|
+
"value": [{
|
23
|
+
"type": "Slice",
|
24
|
+
"slice_type": "with-submenu",
|
25
|
+
"slice_label": null,
|
26
|
+
"repeat": [{
|
27
|
+
"label": {
|
28
|
+
"type": "StructuredText",
|
29
|
+
"value": [{
|
30
|
+
"type": "paragraph",
|
31
|
+
"text": "Start from Scratch",
|
32
|
+
"spans": []
|
33
|
+
}]
|
34
|
+
},
|
35
|
+
"link": {
|
36
|
+
"type": "Link.document",
|
37
|
+
"value": {
|
38
|
+
"document": {
|
39
|
+
"id": "WPeD0SoAACsABzNC",
|
40
|
+
"type": "page-nodejs",
|
41
|
+
"tags": [],
|
42
|
+
"slug": "page---nodejs---getting-started-with-the-starter-kit",
|
43
|
+
"uid": "prismic-from-scratch-with-nodejs"
|
44
|
+
},
|
45
|
+
"isBroken": false
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}],
|
49
|
+
"non-repeat": {
|
50
|
+
"label": {
|
51
|
+
"type": "StructuredText",
|
52
|
+
"value": [{
|
53
|
+
"type": "paragraph",
|
54
|
+
"text": "Getting Started",
|
55
|
+
"spans": []
|
56
|
+
}]
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}]
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prismic.io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Étienne Vallette d'Osia"
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-07-
|
14
|
+
date: 2017-07-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -218,11 +218,12 @@ files:
|
|
218
218
|
- spec/predicates_spec.rb
|
219
219
|
- spec/prismic_spec.rb
|
220
220
|
- spec/responses_mocks/api.json
|
221
|
+
- spec/responses_mocks/composite_slice.json
|
221
222
|
- spec/responses_mocks/document.json
|
222
223
|
- spec/responses_mocks/document_with_unknown_fragment.json
|
223
224
|
- spec/responses_mocks/experiments.json
|
224
225
|
- spec/responses_mocks/fragments.json
|
225
|
-
- spec/responses_mocks/
|
226
|
+
- spec/responses_mocks/simple_slice.json
|
226
227
|
- spec/responses_mocks/structured_text_heading.json
|
227
228
|
- spec/responses_mocks/structured_text_image_with_link.json
|
228
229
|
- spec/responses_mocks/structured_text_linkfile.json
|
@@ -265,11 +266,12 @@ test_files:
|
|
265
266
|
- spec/predicates_spec.rb
|
266
267
|
- spec/prismic_spec.rb
|
267
268
|
- spec/responses_mocks/api.json
|
269
|
+
- spec/responses_mocks/composite_slice.json
|
268
270
|
- spec/responses_mocks/document.json
|
269
271
|
- spec/responses_mocks/document_with_unknown_fragment.json
|
270
272
|
- spec/responses_mocks/experiments.json
|
271
273
|
- spec/responses_mocks/fragments.json
|
272
|
-
- spec/responses_mocks/
|
274
|
+
- spec/responses_mocks/simple_slice.json
|
273
275
|
- spec/responses_mocks/structured_text_heading.json
|
274
276
|
- spec/responses_mocks/structured_text_image_with_link.json
|
275
277
|
- spec/responses_mocks/structured_text_linkfile.json
|