prismic.io 1.5.0 → 1.6.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 +4 -1
- data/lib/prismic/fragments/image.rb +1 -1
- data/lib/prismic/fragments/link.rb +20 -12
- data/lib/prismic/fragments/structured_text.rb +2 -0
- data/lib/prismic/json_parsers.rb +12 -4
- data/lib/prismic/version.rb +1 -1
- data/spec/fragments_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af0cbe24e42c28896b268e59fdf8f0b197f04549
|
4
|
+
data.tar.gz: da04358f02966fd3a2b6149f8a39445d03a8070c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6acd277f5532003856c9ac1a574d48b12a5af167123686353287ca2999afbec78a0bc6e2dc3ea988705b1514875049456de8eea360b77c24a735773228427622
|
7
|
+
data.tar.gz: a89fc85d61a78e888c1609a8a6ac55cb5c02151bd84956a7f7a007dd8721cc1b58e7dbac65e304e07c7bb2d82ef47ba9bbacdf0d5450ce04ad6cb21c1811b95a
|
data/Gemfile.lock
CHANGED
@@ -53,7 +53,7 @@ module Prismic
|
|
53
53
|
|
54
54
|
def as_html(link_resolver=nil)
|
55
55
|
html = []
|
56
|
-
html << (link_to.nil? ? '' : link_to.start_html(link_resolver))
|
56
|
+
html << (link_to.nil? ? '' : link_to.start_html(link_resolver, link_to.target))
|
57
57
|
html << %(<img src="#@url" alt="#@alt" width="#@width" height="#@height" />)
|
58
58
|
html << (link_to.nil? ? '' : link_to.end_html)
|
59
59
|
html.join
|
@@ -3,8 +3,12 @@ module Prismic
|
|
3
3
|
module Fragments
|
4
4
|
class Link < Fragment
|
5
5
|
|
6
|
-
def start_html(link_resolver = nil)
|
7
|
-
|
6
|
+
def start_html(link_resolver = nil, target = nil)
|
7
|
+
unless target.nil?
|
8
|
+
%(<a href="#{url(link_resolver)}" target="#{target}" rel="noopener">)
|
9
|
+
else
|
10
|
+
%(<a href="#{url(link_resolver)}">)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def end_html
|
@@ -12,7 +16,7 @@ module Prismic
|
|
12
16
|
end
|
13
17
|
|
14
18
|
def as_html(link_resolver=nil)
|
15
|
-
%(#{start_html(link_resolver)}#{url(link_resolver)}#{end_html})
|
19
|
+
%(#{start_html(link_resolver, @target)}#{url(link_resolver)}#{end_html})
|
16
20
|
end
|
17
21
|
|
18
22
|
# Returns the URL of the link
|
@@ -27,10 +31,11 @@ module Prismic
|
|
27
31
|
end
|
28
32
|
|
29
33
|
class WebLink < Link
|
30
|
-
attr_accessor :url
|
34
|
+
attr_accessor :url, :target
|
31
35
|
|
32
|
-
def initialize(url)
|
36
|
+
def initialize(url, target = nil)
|
33
37
|
@url = url
|
38
|
+
@target = target
|
34
39
|
end
|
35
40
|
|
36
41
|
# Returns the URL of the link
|
@@ -47,13 +52,14 @@ module Prismic
|
|
47
52
|
end
|
48
53
|
|
49
54
|
class FileLink < Link
|
50
|
-
attr_accessor :url, :name, :kind, :size
|
55
|
+
attr_accessor :url, :name, :kind, :size, :target
|
51
56
|
|
52
|
-
def initialize(url, name, kind, size)
|
57
|
+
def initialize(url, name, kind, size, target = nil)
|
53
58
|
@url = url
|
54
59
|
@name = name
|
55
60
|
@kind = kind
|
56
61
|
@size = size
|
62
|
+
@target = target
|
57
63
|
end
|
58
64
|
|
59
65
|
def as_html(link_resolver=nil)
|
@@ -75,10 +81,11 @@ module Prismic
|
|
75
81
|
end
|
76
82
|
|
77
83
|
class ImageLink < Link
|
78
|
-
attr_accessor :url
|
84
|
+
attr_accessor :url, :target
|
79
85
|
|
80
|
-
def initialize(url)
|
86
|
+
def initialize(url, target = nil)
|
81
87
|
@url = url
|
88
|
+
@target = target
|
82
89
|
end
|
83
90
|
|
84
91
|
# Returns the URL of the link
|
@@ -96,9 +103,9 @@ module Prismic
|
|
96
103
|
|
97
104
|
class DocumentLink < Link
|
98
105
|
include Prismic::WithFragments
|
99
|
-
attr_accessor :id, :uid, :type, :tags, :slug, :lang, :fragments, :broken
|
106
|
+
attr_accessor :id, :uid, :type, :tags, :slug, :lang, :fragments, :broken, :target
|
100
107
|
|
101
|
-
def initialize(id, uid, type, tags, slug, lang, fragments, broken)
|
108
|
+
def initialize(id, uid, type, tags, slug, lang, fragments, broken, target = nil)
|
102
109
|
@id = id
|
103
110
|
@uid = uid
|
104
111
|
@type = type
|
@@ -107,9 +114,10 @@ module Prismic
|
|
107
114
|
@lang = lang
|
108
115
|
@fragments = fragments
|
109
116
|
@broken = broken
|
117
|
+
@target = target
|
110
118
|
end
|
111
119
|
|
112
|
-
def start_html(link_resolver)
|
120
|
+
def start_html(link_resolver, target = nil)
|
113
121
|
broken? ? %(<span>) : super
|
114
122
|
end
|
115
123
|
|
@@ -138,6 +138,8 @@ module Prismic
|
|
138
138
|
def serialize(text, link_resolver = nil)
|
139
139
|
if link.is_a? Prismic::Fragments::DocumentLink and link.broken
|
140
140
|
"<span>#{text}</span>"
|
141
|
+
elsif !link.target.nil?
|
142
|
+
%(<a href="#{link.url(link_resolver)}" target="#{link.target}" rel="noopener">#{text}</a>)
|
141
143
|
else
|
142
144
|
%(<a href="#{link.url(link_resolver)}">#{text}</a>)
|
143
145
|
end
|
data/lib/prismic/json_parsers.rb
CHANGED
@@ -50,15 +50,23 @@ module Prismic
|
|
50
50
|
URI.unescape(doc['slug']),
|
51
51
|
doc['lang'],
|
52
52
|
fragments,
|
53
|
-
json['value']['isBroken']
|
53
|
+
json['value']['isBroken'],
|
54
|
+
json['value']['target'] ? json['value']['target'] : nil)
|
54
55
|
end
|
55
56
|
|
56
57
|
def image_link_parser(json)
|
57
|
-
Prismic::Fragments::ImageLink.new(
|
58
|
+
Prismic::Fragments::ImageLink.new(
|
59
|
+
json['value']['image']['url'],
|
60
|
+
json['value']['target'] ? json['value']['target'] : nil)
|
58
61
|
end
|
59
62
|
|
60
63
|
def file_link_parser(json)
|
61
|
-
Prismic::Fragments::FileLink.new(
|
64
|
+
Prismic::Fragments::FileLink.new(
|
65
|
+
json['value']['file']['url'],
|
66
|
+
json['value']['file']['name'],
|
67
|
+
json['value']['file']['kind'],
|
68
|
+
json['value']['file']['size'],
|
69
|
+
json['value']['target'] ? json['value']['target'] : nil )
|
62
70
|
end
|
63
71
|
|
64
72
|
def text_parser(json)
|
@@ -74,7 +82,7 @@ module Prismic
|
|
74
82
|
end
|
75
83
|
|
76
84
|
def web_link_parser(json)
|
77
|
-
Prismic::Fragments::WebLink.new(json['value']['url'])
|
85
|
+
Prismic::Fragments::WebLink.new(json['value']['url'], json['value']['target'])
|
78
86
|
end
|
79
87
|
|
80
88
|
def date_parser(json)
|
data/lib/prismic/version.rb
CHANGED
data/spec/fragments_spec.rb
CHANGED
@@ -11,6 +11,7 @@ end
|
|
11
11
|
describe 'WebLink' do
|
12
12
|
before do
|
13
13
|
@web_link = Prismic::Fragments::WebLink.new('my_url')
|
14
|
+
@target_blank = Prismic::Fragments::WebLink.new('my_url', '_blank')
|
14
15
|
end
|
15
16
|
describe 'as_html' do
|
16
17
|
it "returns an <a> HTML element" do
|
@@ -28,6 +29,14 @@ describe 'WebLink' do
|
|
28
29
|
it "returns a HTML element whose content is the link" do
|
29
30
|
Nokogiri::XML(@web_link.as_html).child.content.should == 'my_url'
|
30
31
|
end
|
32
|
+
|
33
|
+
it "returns an <a> HTML element with a target attribute" do
|
34
|
+
Nokogiri::XML(@target_blank.as_html).child.has_attribute?('target').should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns an <a> HTML element with an target blank attribute" do
|
38
|
+
Nokogiri::XML(@target_blank.as_html).child.attribute('target').value.should == '_blank'
|
39
|
+
end
|
31
40
|
end
|
32
41
|
|
33
42
|
describe 'as_text' do
|
@@ -650,6 +659,8 @@ describe 'StructuredText::Hyperlink' do
|
|
650
659
|
)
|
651
660
|
@hyperlink = Prismic::Fragments::StructuredText::Span::Hyperlink.new(0, 0, @link)
|
652
661
|
@link_resolver = Prismic.link_resolver("master"){|doc_link| "http://localhost/#{doc_link.id}" }
|
662
|
+
@target_blank = Prismic::Fragments::WebLink.new("link_url", "_blank")
|
663
|
+
@target_hyperlink = Prismic::Fragments::StructuredText::Span::Hyperlink.new(0, 0, @target_blank)
|
653
664
|
end
|
654
665
|
|
655
666
|
describe 'as_html' do
|
@@ -663,6 +674,9 @@ describe 'StructuredText::Hyperlink' do
|
|
663
674
|
@link.broken = true
|
664
675
|
@hyperlink.serialize('', @link_resolver).should == '<span></span>'
|
665
676
|
end
|
677
|
+
it "can generate valid html for target blank" do
|
678
|
+
@target_hyperlink.serialize('', @link_resolver).should == '<a href="link_url" target="_blank" rel="noopener"></a>'
|
679
|
+
end
|
666
680
|
end
|
667
681
|
end
|
668
682
|
|
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.6.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-
|
14
|
+
date: 2017-11-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|