prismic.io 1.4.2 → 1.4.3
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/README.md +3 -25
- data/lib/prismic/api.rb +2 -1
- data/lib/prismic/predicates.rb +4 -0
- data/lib/prismic/version.rb +1 -1
- data/spec/fragments_spec.rb +11 -0
- data/spec/predicates_spec.rb +11 -0
- data/spec/responses_mocks/structured_text_image_with_link.json +21 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe3fbf71a36faca94508e34025888f01161bde97
|
4
|
+
data.tar.gz: af1281ebfc68219a92b15e4ca0092f16ade38dcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 885abba55dbd68875a34e736a63c81e077dca50507264978b66535e595661bedfc25a7ade19e96412ed29b5177a202284d5b93aacec128c2b9efd180dac95eb8
|
7
|
+
data.tar.gz: 0134fc549d395befc527dc8f6ba5b73cd792d2a907329b61bb0b2a6b003753417d911846a6585305e7cf232d1bec6275fd20bfef07d9bb70b978ba9b583b254d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -38,45 +38,23 @@ gem 'prismic.io', require: 'prismic'
|
|
38
38
|
|
39
39
|
The quickstart is not available for Ruby yet, but if you understand Javascript you can easily adapt the code.
|
40
40
|
|
41
|
-
#### Specific Ruby kit syntax
|
42
|
-
|
43
|
-
Thanks to Ruby's syntax, this kit contains some mild differences and syntastic sugar over [the "Kits and helpers" section of our API documentation](https://developers.prismic.io/documentation/UjBe8bGIJ3EKtgBZ/api-documentation#kits-and-helpers) in general (which you should read first). They are listed here:
|
44
|
-
|
45
|
-
* When calling the API, a faster way to pass the `ref`: directly as a parameter of the `submit` method (no need to use the `ref` method then): `api.form("everything").submit(@ref)`.
|
46
|
-
* Accessing type-dependent fields from a `document` is done through the `[]` operator (rather than a `get()` method). Printing the HTML version of a field therefore looks like `document["title_user_friendly"].as_html(link_resolver(@ref))`.
|
47
|
-
* Two of the fields in the `DocumentLink` object (the one used to write your `link_resolver` method, for instance) were renamed to fit Ruby's best practice: `doc.type` is in fact `doc.link_type`, and `doc.isBroken` is in fact `doc.broken?`.
|
48
|
-
* You don't need to pass a `ctx` object in `as_html()`, you can use the `Prismic.link_resolver` static method to build a link resolver object that takes the `ref` into account, like this: `@link_resolver = Prismic.link_resolver(@ref) { |doc| ... }`. Then you can simply go: `fragment.as_html(@link_resolver)`. Note: the Rails starter kit provides you with a helper allowing you to pass the ref each time you call the link resolver, like this: `fragment.as_html(link_resolver(@ref))`.
|
49
|
-
* the `Response` class is fit to work with the [Kaminari](https://github.com/amatsuda/kaminari) gem. So if you have a `@response` object in your controller, you can display a whole pagination for it in your view like this: `<%= paginate @response %>` (this works with any Rails 3 or 4 app with the Kaminari gem installed).
|
50
|
-
|
51
|
-
Knowing all that, here is typical code written with the Ruby kit:
|
52
|
-
|
53
|
-
* A typical API object instantiation looks like this: `Prismic.api(url, opts)`
|
54
|
-
* A typical querying looks like this: `api.query('[[:d = at(document.type, "product")]]')`
|
55
|
-
* A typical fragment manipulation looks like this: `doc['article.image'].get_view('icon').url`
|
56
|
-
* A typical fragment serialization to HTML looks like this: `doc['article.body'].as_html(@link_resolver)`
|
57
|
-
|
58
41
|
#### Configuring Alternative API Caches
|
59
42
|
|
60
|
-
The default cache stores data in-memory, in the server. You may want to use a different cache, for example to share it between several servers (with memcached or similar). A null cache (does no caching) is also available if you need a predictible behavior for testing or VCR. To use it (or any other compliant cache), simply add `api_cache
|
61
|
-
to the options passed to `Prismic.api`.
|
43
|
+
The default cache stores data in-memory, in the server. You may want to use a different cache, for example to share it between several servers (with memcached or similar). A null cache (does no caching) is also available if you need a predictible behavior for testing or VCR. To use it (or any other compliant cache), simply add `api_cache: Prismic::BasicNullCache.new` to the options passed to `Prismic.api`.
|
62
44
|
|
63
45
|
### Changelog
|
64
46
|
|
65
47
|
Need to see what changed, or to upgrade your kit? We keep our changelog on [this repository's "Releases" tab](https://github.com/prismicio/ruby-kit/releases).
|
66
48
|
|
67
|
-
### Contribute to the kit
|
68
|
-
|
69
|
-
Contribution is open to all developer levels, read our "[Contribute to the official kits](https://developers.prismic.io/documentation/UszOeAEAANUlwFpp/contribute-to-the-official-kits)" documentation to learn more.
|
70
|
-
|
71
49
|
#### Install the kit locally
|
72
50
|
|
73
51
|
Of course, you're going to need [Ruby installed](https://www.ruby-lang.org/en/downloads/) on your computer, as well as [RubyGems](http://rubygems.org/pages/download) and [Bundler](http://bundler.io/).
|
74
52
|
|
75
|
-
Clone the kit, then run
|
53
|
+
Clone the kit, then run `bundle install`.
|
76
54
|
|
77
55
|
#### Test
|
78
56
|
|
79
|
-
Please write tests for any bugfix or new feature, by placing your tests in the [spec/](spec/) folder, following the [RSpec](http://rspec.info/) syntax. Launch the tests by running
|
57
|
+
Please write tests for any bugfix or new feature, by placing your tests in the [spec/](spec/) folder, following the [RSpec](http://rspec.info/) syntax. Launch the tests by running `rspec`
|
80
58
|
|
81
59
|
If you find existing code that is not optimally tested and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request.
|
82
60
|
|
data/lib/prismic/api.rb
CHANGED
@@ -108,6 +108,7 @@ module Prismic
|
|
108
108
|
alias :getByID :get_by_id
|
109
109
|
|
110
110
|
# Retrieve one document by its uid
|
111
|
+
# @param typ [String] the document type's name
|
111
112
|
# @param uid [String] the uid to search
|
112
113
|
# @param opts [Hash] query options (ref, etc.)
|
113
114
|
# @return the document, or nil if not found
|
@@ -126,7 +127,7 @@ module Prismic
|
|
126
127
|
alias :getByIDs :get_by_ids
|
127
128
|
|
128
129
|
# Retrieve one single typed document by its type
|
129
|
-
# @param
|
130
|
+
# @param typ [String] the document type's name
|
130
131
|
# @param opts [Hash] query options (ref, etc.)
|
131
132
|
# @return the document, or nil if not found
|
132
133
|
def get_single(typ, opts={})
|
data/lib/prismic/predicates.rb
CHANGED
data/lib/prismic/version.rb
CHANGED
data/spec/fragments_spec.rb
CHANGED
@@ -143,6 +143,17 @@ describe 'Span' do
|
|
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
|
146
|
+
describe 'in structured texts when image with link' do
|
147
|
+
before do
|
148
|
+
@raw_json_structured_text = File.read("#{File.dirname(__FILE__)}/responses_mocks/structured_text_image_with_link.json")
|
149
|
+
@json_structured_text = JSON.load(@raw_json_structured_text)
|
150
|
+
@structured_text = Prismic::JsonParser.structured_text_parser(@json_structured_text)
|
151
|
+
end
|
152
|
+
it 'serializes well into HTML' do
|
153
|
+
@structured_text.as_html(nil).should ==
|
154
|
+
'<p class="block-img"><a href="http://prismic.io"><img src="https://wroomdev.s3.amazonaws.com/tutoblanktemplate%2F97109f41-140e-4dc9-a2c8-96fb10f14051_star.gif" alt="" width="960" height="800" /></a></p>'
|
155
|
+
end
|
156
|
+
end
|
146
157
|
end
|
147
158
|
|
148
159
|
describe 'Text' do
|
data/spec/predicates_spec.rb
CHANGED
@@ -21,6 +21,17 @@ describe 'predicates' do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
describe 'not predicate' do
|
25
|
+
it 'as an array serializes well' do
|
26
|
+
form = @api.form('everything').query(['not', 'document.id', 'UrjI1gEAALOCeO5i'])
|
27
|
+
form.data['q'].should == ['[[:d = not(document.id, "UrjI1gEAALOCeO5i")]]']
|
28
|
+
end
|
29
|
+
it 'with helper serializes well' do
|
30
|
+
form = @api.form('everything').query(Predicates.not('document.id', 'UrjI1gEAALOCeO5i'))
|
31
|
+
form.data['q'].should == ['[[:d = not(document.id, "UrjI1gEAALOCeO5i")]]']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
24
35
|
describe 'any predicate' do
|
25
36
|
it 'with helper serializes well' do
|
26
37
|
form = @api.form('everything').query(Predicates.any('document.type', ['article', 'blog-post']))
|
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"type": "StructuredText",
|
3
|
+
"value": [
|
4
|
+
{
|
5
|
+
"type": "image",
|
6
|
+
"url": "https://wroomdev.s3.amazonaws.com/tutoblanktemplate%2F97109f41-140e-4dc9-a2c8-96fb10f14051_star.gif",
|
7
|
+
"alt": null,
|
8
|
+
"copyright": null,
|
9
|
+
"dimensions": {
|
10
|
+
"width": 960,
|
11
|
+
"height": 800
|
12
|
+
},
|
13
|
+
"linkTo": {
|
14
|
+
"type": "Link.web",
|
15
|
+
"value": {
|
16
|
+
"url": "http://prismic.io"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}
|
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.
|
4
|
+
version: 1.4.3
|
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:
|
14
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- spec/responses_mocks/fragments.json
|
225
225
|
- spec/responses_mocks/slices.json
|
226
226
|
- spec/responses_mocks/structured_text_heading.json
|
227
|
+
- spec/responses_mocks/structured_text_image_with_link.json
|
227
228
|
- spec/responses_mocks/structured_text_linkfile.json
|
228
229
|
- spec/responses_mocks/structured_text_paragraph.json
|
229
230
|
- spec/responses_mocks/structured_text_with_labels.json
|
@@ -270,6 +271,7 @@ test_files:
|
|
270
271
|
- spec/responses_mocks/fragments.json
|
271
272
|
- spec/responses_mocks/slices.json
|
272
273
|
- spec/responses_mocks/structured_text_heading.json
|
274
|
+
- spec/responses_mocks/structured_text_image_with_link.json
|
273
275
|
- spec/responses_mocks/structured_text_linkfile.json
|
274
276
|
- spec/responses_mocks/structured_text_paragraph.json
|
275
277
|
- spec/responses_mocks/structured_text_with_labels.json
|