prismic.io 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd49e594dff30e85b1dce2393707441e716c88f6
4
- data.tar.gz: 18838f06eb596494d16fcac5bc461cbef642a12b
3
+ metadata.gz: d3aab8aa8c04948a2b6be0c2b1a99f9991b916d5
4
+ data.tar.gz: 7d07488a5d104cbd2a57a764d5e66fa109e76eed
5
5
  SHA512:
6
- metadata.gz: c2da8f9c018d2cb305d139d4a176a3d20efcb4024a40c0da9add1d8d1c60118840e283c368b2d880b6095e54aa1437c0a1e3fdf6b928aba6374bade151f1fff9
7
- data.tar.gz: a5aa83e595426ab090d6dfc97409b3d1705f2e8eb0d9a0a2854a79e2da9bbf60eca38e22ae947213cf99dbfa1ed360474e01d1a468edeaedcd1631265b7ab732
6
+ metadata.gz: 17f223d1112c5c27a56e935e242c5577f925e26099fd514789e7ee095d57567af68ac4059e3cdaf65f0571d77d6b3f36c969cdd55a9c0db851f3dab2f01fad66
7
+ data.tar.gz: a9bc31cbc6eb1d747595d3e3f839c4cad2b6b4d25f3847c324415cf49d7492044a620f81a163d3dc034415e2c5fda32b7b6d4f2679ea2043ab48d43a6e72a8a5
data/.travis.yml CHANGED
@@ -10,6 +10,9 @@ script: bundle exec rspec spec
10
10
  notifications:
11
11
  email:
12
12
  - evo@zenexity.com
13
+ addons:
14
+ code_climate:
15
+ repo_token: f46a7e216896abddbc4877ce065239e8ac9f575af7a120bdaa61a42be70777e9
13
16
  deploy:
14
17
  provider: rubygems
15
18
  api_key:
data/Gemfile CHANGED
@@ -4,5 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
+ gem "codeclimate-test-reporter", require: nil
7
8
  gem "yajl-ruby", require: 'yajl', platforms: [:ruby_19, :ruby_20, :ruby_21]
8
9
  end
10
+
data/Gemfile.lock CHANGED
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prismic.io (1.0.5)
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.png)](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 == false
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.new(
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
- begin
172
- api = self.start(url, api_opts)
173
- api.oauth
174
- rescue PrismicWSAuthError => e
175
- e.oauth
176
- end
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
- begin
192
- api = self.start(url, api_opts)
193
- api.oauth
194
- rescue PrismicWSAuthError => e
195
- e.oauth
196
- end
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
  '&' => '&amp;',
221
221
  '"' => '&quot;',
222
222
  '<' => '&lt;',
223
- '>' => '&gt;',
223
+ '>' => '&gt;'
224
224
  })
225
225
  end
226
226
 
@@ -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
- view = Prismic::Fragments::Image::View.new(
160
- block['url'],
161
- block['dimensions']['width'],
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)
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Prismic
3
3
 
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
 
6
6
  end
@@ -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. Our 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).",
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
@@ -1,4 +1,7 @@
1
1
  # encoding: utf-8
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+
2
5
  require 'nokogiri'
3
6
  begin
4
7
  require 'yajl/json_gem'
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.5
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-10-31 00:00:00.000000000 Z
14
+ date: 2014-11-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler