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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8474490a3982e6d9d3b995b3a848f08ecc9dda67
4
- data.tar.gz: da268f235d65b3bf88fef8a5fb8d18d37f3556fc
3
+ metadata.gz: af0cbe24e42c28896b268e59fdf8f0b197f04549
4
+ data.tar.gz: da04358f02966fd3a2b6149f8a39445d03a8070c
5
5
  SHA512:
6
- metadata.gz: 8d4282305f84eb5ec333a80559ffe8691bd3ff3224e4042af1fe6f04cf4824f4b3c0f5595992af71eefc63c8f5b8f4b029ccf3bd6ba29e46d284392e29d5e29b
7
- data.tar.gz: 9600c487806277d86ada6b55a02c3e86768ca5bc477dcd75310a03f2cb72f98faba2dc72cd33fe75d4e0d58467f0d6e25937edde7733cfd70455326041098284
6
+ metadata.gz: 6acd277f5532003856c9ac1a574d48b12a5af167123686353287ca2999afbec78a0bc6e2dc3ea988705b1514875049456de8eea360b77c24a735773228427622
7
+ data.tar.gz: a89fc85d61a78e888c1609a8a6ac55cb5c02151bd84956a7f7a007dd8721cc1b58e7dbac65e304e07c7bb2d82ef47ba9bbacdf0d5450ce04ad6cb21c1811b95a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prismic.io (1.4.5)
4
+ prismic.io (1.5.0)
5
5
  hashery (~> 2.1.1)
6
6
 
7
7
  GEM
@@ -44,3 +44,6 @@ DEPENDENCIES
44
44
  rspec (~> 2.14)
45
45
  simplecov (~> 0.7)
46
46
  yajl-ruby
47
+
48
+ BUNDLED WITH
49
+ 1.16.0
@@ -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
- %(<a href="#{url(link_resolver)}">)
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
@@ -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(json['value']['image']['url'])
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(json['value']['file']['url'], json['value']['file']['name'], json['value']['file']['kind'], json['value']['file']['size'])
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)
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Prismic
3
3
 
4
- VERSION = '1.5.0'
4
+ VERSION = '1.6.0'
5
5
 
6
6
  end
@@ -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.5.0
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-07-28 00:00:00.000000000 Z
14
+ date: 2017-11-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler