prismic.io 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +4 -1
- data/README.md +2 -1
- data/lib/prismic/api.rb +14 -24
- data/lib/prismic/form.rb +15 -0
- data/lib/prismic/fragments/structured_text.rb +2 -2
- data/lib/prismic/json_parsers.rb +23 -25
- data/lib/prismic/version.rb +1 -1
- data/spec/fragments_spec.rb +1 -1
- data/spec/responses_mocks/structured_text_paragraph.json +1 -1
- data/spec/spec_helper.rb +3 -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: d3aab8aa8c04948a2b6be0c2b1a99f9991b916d5
|
4
|
+
data.tar.gz: 7d07488a5d104cbd2a57a764d5e66fa109e76eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17f223d1112c5c27a56e935e242c5577f925e26099fd514789e7ee095d57567af68ac4059e3cdaf65f0571d77d6b3f36c969cdd55a9c0db851f3dab2f01fad66
|
7
|
+
data.tar.gz: a9bc31cbc6eb1d747595d3e3f839c4cad2b6b4d25f3847c324415cf49d7492044a620f81a163d3dc034415e2c5fda32b7b6d4f2679ea2043ab48d43a6e72a8a5
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
prismic.io (1.0.
|
4
|
+
prismic.io (1.0.6)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
codeclimate-test-reporter (0.4.1)
|
10
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
9
11
|
diff-lcs (1.2.4)
|
10
12
|
mini_portile (0.5.1)
|
11
13
|
multi_json (1.8.0)
|
@@ -33,6 +35,7 @@ PLATFORMS
|
|
33
35
|
|
34
36
|
DEPENDENCIES
|
35
37
|
bundler (~> 1.3)
|
38
|
+
codeclimate-test-reporter
|
36
39
|
nokogiri (~> 1.6)
|
37
40
|
prismic.io!
|
38
41
|
rspec (~> 2.14)
|
data/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/prismic.io.png)](http://badge.fury.io/rb/prismic.io)
|
4
4
|
[![Build Status](https://api.travis-ci.org/prismicio/ruby-kit.png)](https://travis-ci.org/prismicio/ruby-kit)
|
5
|
-
[![Code Climate](https://codeclimate.com/github/prismicio/ruby-kit.
|
5
|
+
[![Code Climate](https://codeclimate.com/github/prismicio/ruby-kit/badges/gpa.svg)](https://codeclimate.com/github/prismicio/ruby-kit)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/prismicio/ruby-kit/badges/coverage.svg)](https://codeclimate.com/github/prismicio/ruby-kit)
|
6
7
|
|
7
8
|
### Getting Started
|
8
9
|
|
data/lib/prismic/api.rb
CHANGED
@@ -131,7 +131,7 @@ module Prismic
|
|
131
131
|
http_client = opts[:http_client] || Prismic::DefaultHTTPClient
|
132
132
|
access_token = opts[:access_token]
|
133
133
|
cache = opts[:cache]
|
134
|
-
cache ||= Prismic::DefaultCache unless cache
|
134
|
+
cache ||= Prismic::DefaultCache unless !cache
|
135
135
|
resp = get(url, access_token, http_client)
|
136
136
|
json = JSON.load(resp.body)
|
137
137
|
parse_api_response(json, access_token, http_client, cache)
|
@@ -143,17 +143,7 @@ module Prismic
|
|
143
143
|
new(data, access_token, http_client, cache) {|api|
|
144
144
|
api.bookmarks = data['bookmarks']
|
145
145
|
api.forms = Hash[data_forms.map { |k, form|
|
146
|
-
[k, Form.
|
147
|
-
api,
|
148
|
-
form['name'],
|
149
|
-
Hash[form['fields'].map { |k2, field|
|
150
|
-
[k2, Field.new(field['type'], field['default'], k2 == 'q')]
|
151
|
-
}],
|
152
|
-
form['method'],
|
153
|
-
form['rel'],
|
154
|
-
form['enctype'],
|
155
|
-
form['action'],
|
156
|
-
)]
|
146
|
+
[k, Form.from_json(api, form)]
|
157
147
|
}]
|
158
148
|
api.refs = Hash[data_refs.map { |ref|
|
159
149
|
scheduled_at = ref['scheduledAt']
|
@@ -168,12 +158,12 @@ module Prismic
|
|
168
158
|
|
169
159
|
def self.oauth_initiate_url(url, oauth_opts, api_opts={})
|
170
160
|
oauth =
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
161
|
+
begin
|
162
|
+
api = self.start(url, api_opts)
|
163
|
+
api.oauth
|
164
|
+
rescue PrismicWSAuthError => e
|
165
|
+
e.oauth
|
166
|
+
end
|
177
167
|
oauth.initiate_url(oauth_opts)
|
178
168
|
end
|
179
169
|
|
@@ -188,12 +178,12 @@ module Prismic
|
|
188
178
|
|
189
179
|
def self.oauth_check_token(url, oauth_params, api_opts={})
|
190
180
|
oauth =
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
181
|
+
begin
|
182
|
+
api = self.start(url, api_opts)
|
183
|
+
api.oauth
|
184
|
+
rescue PrismicWSAuthError => e
|
185
|
+
e.oauth
|
186
|
+
end
|
197
187
|
oauth.check_token(oauth_params)
|
198
188
|
end
|
199
189
|
|
data/lib/prismic/form.rb
CHANGED
@@ -20,5 +20,20 @@ module Prismic
|
|
20
20
|
def create_search_form(data={}, ref=nil)
|
21
21
|
SearchForm.new(@api, self, data, ref)
|
22
22
|
end
|
23
|
+
|
24
|
+
def self.from_json(api, json)
|
25
|
+
Form.new(
|
26
|
+
api,
|
27
|
+
json['name'],
|
28
|
+
Hash[json['fields'].map { |k2, field|
|
29
|
+
[k2, Field.new(field['type'], field['default'], k2 == 'q')]
|
30
|
+
}],
|
31
|
+
json['method'],
|
32
|
+
json['rel'],
|
33
|
+
json['enctype'],
|
34
|
+
json['action']
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
23
38
|
end
|
24
39
|
end
|
@@ -210,7 +210,7 @@ module Prismic
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
end
|
213
|
-
html
|
213
|
+
html.gsub("\n", '<br>')
|
214
214
|
end
|
215
215
|
|
216
216
|
def cgi_escape_html(string)
|
@@ -220,7 +220,7 @@ module Prismic
|
|
220
220
|
'&' => '&',
|
221
221
|
'"' => '"',
|
222
222
|
'<' => '<',
|
223
|
-
'>' => '>'
|
223
|
+
'>' => '>'
|
224
224
|
})
|
225
225
|
end
|
226
226
|
|
data/lib/prismic/json_parsers.rb
CHANGED
@@ -85,15 +85,6 @@ module Prismic
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def image_parser(json)
|
88
|
-
def self.view_parser(json)
|
89
|
-
Prismic::Fragments::Image::View.new(json['url'],
|
90
|
-
json['dimensions']['width'],
|
91
|
-
json['dimensions']['height'],
|
92
|
-
json['alt'],
|
93
|
-
json['copyright'],
|
94
|
-
json['linkTo'] ? link_parser(json['linkTo']) : nil)
|
95
|
-
end
|
96
|
-
|
97
88
|
main = view_parser(json['value']['main'])
|
98
89
|
views = {}
|
99
90
|
json['value']['views'].each do |name, view|
|
@@ -156,15 +147,10 @@ module Prismic
|
|
156
147
|
block['label']
|
157
148
|
)
|
158
149
|
when 'image'
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
block['dimensions']['height'],
|
163
|
-
block['alt'],
|
164
|
-
block['copyright'],
|
165
|
-
block['linkTo'] ? link_parser(block['linkTo']) : nil
|
150
|
+
Prismic::Fragments::StructuredText::Block::Image.new(
|
151
|
+
view_parser(block),
|
152
|
+
block['label']
|
166
153
|
)
|
167
|
-
Prismic::Fragments::StructuredText::Block::Image.new(view, block['label'])
|
168
154
|
when 'embed'
|
169
155
|
boembed = block['oembed']
|
170
156
|
Prismic::Fragments::Embed.new(
|
@@ -218,14 +204,7 @@ module Prismic
|
|
218
204
|
end
|
219
205
|
}]
|
220
206
|
|
221
|
-
linked_documents = json['linked_documents']
|
222
|
-
if linked_documents
|
223
|
-
linked_documents.map! do |linked_doc|
|
224
|
-
LinkedDocument.new(linked_doc['id'], linked_doc['slug'], linked_doc['type'], linked_doc['tags'])
|
225
|
-
end
|
226
|
-
else
|
227
|
-
linked_documents = []
|
228
|
-
end
|
207
|
+
linked_documents = linked_documents_parser(json['linked_documents'])
|
229
208
|
|
230
209
|
Prismic::Document.new(json['id'], json['type'], json['href'], json['tags'],
|
231
210
|
json['slugs'], linked_documents, fragments)
|
@@ -253,6 +232,25 @@ module Prismic
|
|
253
232
|
|
254
233
|
private
|
255
234
|
|
235
|
+
def view_parser(json)
|
236
|
+
Prismic::Fragments::Image::View.new(json['url'],
|
237
|
+
json['dimensions']['width'],
|
238
|
+
json['dimensions']['height'],
|
239
|
+
json['alt'],
|
240
|
+
json['copyright'],
|
241
|
+
json['linkTo'] ? link_parser(json['linkTo']) : nil)
|
242
|
+
end
|
243
|
+
|
244
|
+
def linked_documents_parser(json)
|
245
|
+
if json
|
246
|
+
json.map! do |linked_doc|
|
247
|
+
LinkedDocument.new(linked_doc['id'], linked_doc['slug'], linked_doc['type'], linked_doc['tags'])
|
248
|
+
end
|
249
|
+
else
|
250
|
+
[]
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
256
254
|
def link_parser(json)
|
257
255
|
if json['type'] == 'Link.document'
|
258
256
|
document_link_parser(json)
|
data/lib/prismic/version.rb
CHANGED
data/spec/fragments_spec.rb
CHANGED
@@ -139,7 +139,7 @@ describe 'Span' do
|
|
139
139
|
end
|
140
140
|
it 'serializes well into HTML' do
|
141
141
|
@structured_text.as_html(nil).should ==
|
142
|
-
'<p class="vanilla">Experience <a href="http://prismic.io">the</a> ultimate vanilla experience
|
142
|
+
'<p class="vanilla">Experience <a href="http://prismic.io">the</a> ultimate vanilla experience.<br>'\
|
143
143
|
'Our vanilla Macarons are made with our very own (in-house) <em>pure extract of Madagascar vanilla</em>, and subtly dusted with <strong>our own vanilla sugar</strong> (which we make from real vanilla beans).</p>'
|
144
144
|
end
|
145
145
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
"value": [{
|
4
4
|
"type": "paragraph",
|
5
5
|
"label": "vanilla",
|
6
|
-
"text": "Experience the ultimate vanilla experience
|
6
|
+
"text": "Experience the ultimate vanilla experience.\nOur vanilla Macarons are made with our very own (in-house) pure extract of Madagascar vanilla, and subtly dusted with our own vanilla sugar (which we make from real vanilla beans).",
|
7
7
|
"spans": [
|
8
8
|
{
|
9
9
|
"start": 103,
|
data/spec/spec_helper.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.6
|
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: 2014-
|
14
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|