prismic.io 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/deploy-doc.sh +9 -0
- data/lib/prismic.rb +26 -7
- data/lib/prismic/fragments/group.rb +1 -0
- data/lib/prismic/fragments/structured_text.rb +14 -3
- data/lib/prismic/predicates.rb +101 -0
- data/lib/prismic/version.rb +1 -1
- data/spec/fragments_spec.rb +3 -3
- data/spec/micro_spec.rb +1 -1
- data/spec/predicates_spec.rb +86 -0
- metadata +7 -3
- data/Changelog.md +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0efa24b3f98e9f3dc05f26b50f7125e45409afa2
|
4
|
+
data.tar.gz: fb6164ea1e1fa198951e92353429fc985e4432b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7af5bae716dcdf93e5672a8639b71ce1974c903a352739c2cf27d8dbf600b16b396bd5c4f273787f723c612aff16f1e6f4750f68cb3f40f8288d6a115e8e2501
|
7
|
+
data.tar.gz: 14d0b5d69449eeb4e3ec27a8524a0eb69358ad45545b46cc75d5cea1ee061a59cee26e6c672392a4ea555c7561b73fe41132f3eb72b696027eec99919a1cd091
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -95,3 +95,4 @@ Copyright 2013 Zengularity (http://www.zengularity.com).
|
|
95
95
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
96
96
|
|
97
97
|
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
98
|
+
|
data/deploy-doc.sh
ADDED
data/lib/prismic.rb
CHANGED
@@ -142,10 +142,33 @@ module Prismic
|
|
142
142
|
@ref = ref
|
143
143
|
end
|
144
144
|
|
145
|
-
#
|
146
|
-
# Specify a query for this form.
|
145
|
+
# Specify a query for this form.
|
147
146
|
# @param query [String] The query
|
148
147
|
# @return [SearchForm] self
|
148
|
+
def query(*query)
|
149
|
+
q(*query)
|
150
|
+
end
|
151
|
+
|
152
|
+
def q(*query)
|
153
|
+
def serialize(field)
|
154
|
+
if field.kind_of?(String) and not (field.start_with?('my.') or field.start_with?('document.'))
|
155
|
+
%("#{field}")
|
156
|
+
elsif field.kind_of?(Array)
|
157
|
+
%([#{field.map{ |arg| serialize(arg) }.join(', ')}])
|
158
|
+
else
|
159
|
+
%(#{field})
|
160
|
+
end
|
161
|
+
end
|
162
|
+
if query[0].kind_of?(String)
|
163
|
+
set('q', query[0])
|
164
|
+
else
|
165
|
+
predicates = query.map { |q|
|
166
|
+
op = q.shift
|
167
|
+
"[:d = #{op}(#{q.map { |arg| serialize(arg) }.join(', ')})]"
|
168
|
+
}
|
169
|
+
set('q', "[#{predicates * ''}]")
|
170
|
+
end
|
171
|
+
end
|
149
172
|
|
150
173
|
# @!method orderings(orderings)
|
151
174
|
# Specify a orderings for this form.
|
@@ -169,11 +192,6 @@ module Prismic
|
|
169
192
|
meth_name = name.gsub(/([A-Z])/, '_\1').downcase
|
170
193
|
return if respond_to?(meth_name)
|
171
194
|
define_singleton_method(meth_name){|value| set(name, value) }
|
172
|
-
if name == 'q'
|
173
|
-
class << self
|
174
|
-
alias :query :q
|
175
|
-
end
|
176
|
-
end
|
177
195
|
end
|
178
196
|
private :create_field_helper_method
|
179
197
|
|
@@ -605,6 +623,7 @@ end
|
|
605
623
|
require 'prismic/api'
|
606
624
|
require 'prismic/form'
|
607
625
|
require 'prismic/fragments'
|
626
|
+
require 'prismic/predicates'
|
608
627
|
require 'prismic/json_parsers'
|
609
628
|
require 'prismic/cache/lru'
|
610
629
|
require 'prismic/cache/basic'
|
@@ -190,16 +190,27 @@ module Prismic
|
|
190
190
|
if pos < text.length
|
191
191
|
if stack.empty?
|
192
192
|
# Top level text
|
193
|
-
html +=
|
193
|
+
html += cgi_escape_html(text[pos])
|
194
194
|
else
|
195
195
|
# Inner text of a span
|
196
|
-
stack[-1][:html] +=
|
196
|
+
stack[-1][:html] += cgi_escape_html(text[pos])
|
197
197
|
end
|
198
198
|
end
|
199
199
|
end
|
200
200
|
html
|
201
201
|
end
|
202
202
|
|
203
|
+
def cgi_escape_html(string)
|
204
|
+
# We don't use CGI::escapeHTML because the implementation changed from 1.9 to 2.0 and that break tests
|
205
|
+
string.gsub(/['&\"<>]/, {
|
206
|
+
"'" => ''',
|
207
|
+
'&' => '&',
|
208
|
+
'"' => '"',
|
209
|
+
'<' => '<',
|
210
|
+
'>' => '>',
|
211
|
+
})
|
212
|
+
end
|
213
|
+
|
203
214
|
# Building two span Hashes:
|
204
215
|
# * start_spans, with the starting positions as keys, and spans as values
|
205
216
|
# * end_spans, with the ending positions as keys, and spans as values
|
@@ -234,7 +245,7 @@ module Prismic
|
|
234
245
|
end
|
235
246
|
end
|
236
247
|
|
237
|
-
private :class_code
|
248
|
+
private :class_code, :cgi_escape_html
|
238
249
|
end
|
239
250
|
|
240
251
|
class Heading < Text
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Prismic
|
2
|
+
module Predicates
|
3
|
+
|
4
|
+
def self.at(fragment, value)
|
5
|
+
['at', fragment, value]
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.any(fragment, values)
|
9
|
+
['any', fragment, values]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.fulltext(fragment, values)
|
13
|
+
['fulltext', fragment, values]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.similar(fragment, value)
|
17
|
+
['similar', fragment, value]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.gt(fragment, value)
|
21
|
+
['number.gt', fragment, value]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.lt(fragment, value)
|
25
|
+
['number.lt', fragment, value]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.in_range(fragment, before, after)
|
29
|
+
['number.inRange', fragment, before, after]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.date_before(fragment, before)
|
33
|
+
['date.before', fragment, before]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.date_after(fragment, after)
|
37
|
+
['date.after', fragment, after]
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.date_between(fragment, before, after)
|
41
|
+
['date.between', fragment, before, after]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.day_of_month(fragment, day)
|
45
|
+
['date.day-of-month', fragment, day]
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.day_of_month_after(fragment, day)
|
49
|
+
['date.day-of-month-after', fragment, day]
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.day_of_month_before(fragment, day)
|
53
|
+
['date.day-of-month-before', fragment, day]
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.day_of_week(fragment, day)
|
57
|
+
['date.day-of-week', fragment, day]
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.day_of_week_after(fragment, day)
|
61
|
+
['date.day-of-week-after', fragment, day]
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.day_of_week_before(fragment, day)
|
65
|
+
['date.day-of-week-before', fragment, day]
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.month(fragment, month)
|
69
|
+
['date.month', fragment, month]
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.month_before(fragment, month)
|
73
|
+
['date.month-before', fragment, month]
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.month_after(fragment, month)
|
77
|
+
['date.month-after', fragment, month]
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.year(fragment, year)
|
81
|
+
['date.year', fragment, year]
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.hour(fragment, hour)
|
85
|
+
['date.hour', fragment, hour]
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.hour_before(fragment, hour)
|
89
|
+
['date.hour-before', fragment, hour]
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.hour_after(fragment, hour)
|
93
|
+
['date.hour-after', fragment, hour]
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.near(fragment, latitude, longitude, radius)
|
97
|
+
['geopoint.near', fragment, latitude, longitude, radius]
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
data/lib/prismic/version.rb
CHANGED
data/spec/fragments_spec.rb
CHANGED
@@ -663,10 +663,10 @@ end
|
|
663
663
|
|
664
664
|
describe 'Group' do
|
665
665
|
before do
|
666
|
-
@micro_api = Prismic.api(
|
666
|
+
@micro_api = Prismic.api('https://micro.prismic.io/api', nil)
|
667
667
|
@master_ref = @micro_api.master_ref
|
668
|
-
@docchapter = @micro_api.form(
|
669
|
-
@link_resolver = Prismic.link_resolver(
|
668
|
+
@docchapter = @micro_api.form('everything').query('[[:d = at(document.type, "docchapter")]]').orderings('[my.docchapter.priority]').submit(@master_ref)[0]
|
669
|
+
@link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.link_type}/#{doc_link.id}" }
|
670
670
|
end
|
671
671
|
|
672
672
|
it 'accesses fields the proper way' do
|
data/spec/micro_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe 'micro' do
|
|
10
10
|
|
11
11
|
describe 'embed block in structured text fragments' do
|
12
12
|
it 'is of the right Embed object, and serializes well' do
|
13
|
-
fragment = @api.form("everything").query(%(
|
13
|
+
fragment = @api.form("everything").query(%w(at document.id UrjI1gEAALOCeO5i)).submit(@master_ref)[0]['article.body']
|
14
14
|
fragment.blocks[4].is_a?(Prismic::Fragments::Embed).should == true
|
15
15
|
fragment.as_html(@link_resolver).gsub(/[\n\r]+/, '').gsub(/ +/, ' ').gsub(/'/, "'").should == %(<h2>The meta-micro mailing-list</h2><p>This is where you go to give feedback, and discuss the future of micro. <a href="https://groups.google.com/forum/?hl=en#!forum/micro-meta-framework">Subscribe to the list now</a>!</p><h2>The micro GitHub repository</h2><p>This is where you get truly active, by forking the project's source code, and making it better. Please always feel free to send us pull requests.</p> <div data-oembed="" data-oembed-type="link" data-oembed-provider="object"><div data-type="object"><a href="https://github.com/rudyrigot/meta-micro"><h1>rudyrigot/meta-micro</h1><img src="https://avatars2.githubusercontent.com/u/552279?s=400"><p>The meta-micro-framework you simply need</p></a></div></div><h2>Report bugs on micro</h2><p>If you think micro isn't working properly in one of its features, <a href="https://github.com/rudyrigot/meta-micro/issues">open a new issue in the micro GitHub repository</a>.</p><h2>Ask for help</h2><p>Feel free to ask a new question <a href="http://stackoverflow.com/questions/tagged/meta-micro">on StackOverflow</a>.</p>)
|
16
16
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
Predicates = Prismic::Predicates
|
5
|
+
|
6
|
+
describe 'predicates' do
|
7
|
+
before do
|
8
|
+
@api = Prismic.api('https://micro.prismic.io/api', nil)
|
9
|
+
@master_ref = @api.master_ref
|
10
|
+
@link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.id}" }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'at predicate' do
|
14
|
+
it 'as an array serializes well' do
|
15
|
+
form = @api.form('everything').query(['at', 'document.id', 'UrjI1gEAALOCeO5i'])
|
16
|
+
form.data['q'].should == ['[[:d = at(document.id, "UrjI1gEAALOCeO5i")]]']
|
17
|
+
end
|
18
|
+
it 'with helper serializes well' do
|
19
|
+
form = @api.form('everything').query(Predicates.at('document.id', 'UrjI1gEAALOCeO5i'))
|
20
|
+
form.data['q'].should == ['[[:d = at(document.id, "UrjI1gEAALOCeO5i")]]']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'any predicate' do
|
25
|
+
it 'with helper serializes well' do
|
26
|
+
form = @api.form('everything').query(Predicates.any('document.type', ['article', 'blog-post']))
|
27
|
+
form.data['q'].should == ['[[:d = any(document.type, ["article", "blog-post"])]]']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'similar predicate' do
|
32
|
+
it 'as an array serializes well' do
|
33
|
+
form = @api.form('everything').query(['similar', 'idOfSomeDocument', 10])
|
34
|
+
form.data['q'].should == ['[[:d = similar("idOfSomeDocument", 10)]]']
|
35
|
+
end
|
36
|
+
it 'with helpers serializes well' do
|
37
|
+
form = @api.form('everything').query(Predicates.similar('idOfSomeDocument', 10))
|
38
|
+
form.data['q'].should == ['[[:d = similar("idOfSomeDocument", 10)]]']
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'multiple predicates' do
|
43
|
+
it 'as an array serializes well' do
|
44
|
+
form = @api.form('everything').query(
|
45
|
+
['date.month-after', 'my.blog-post.publication-date', 4],
|
46
|
+
['date.month-before', 'my.blog-post.publication-date', 'December']
|
47
|
+
)
|
48
|
+
form.data['q'].should == ['[[:d = date.month-after(my.blog-post.publication-date, 4)][:d = date.month-before(my.blog-post.publication-date, "December")]]']
|
49
|
+
end
|
50
|
+
it 'with helpers serializes well' do
|
51
|
+
form = @api.form('everything').query(
|
52
|
+
Predicates.month_after('my.blog-post.publication-date', 4),
|
53
|
+
Predicates.month_before('my.blog-post.publication-date', 'December')
|
54
|
+
)
|
55
|
+
form.data['q'].should == ['[[:d = date.month-after(my.blog-post.publication-date, 4)][:d = date.month-before(my.blog-post.publication-date, "December")]]']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'number LT' do
|
60
|
+
it 'with helpers serializes well' do
|
61
|
+
form = @api.form('everything').query(
|
62
|
+
Predicates.lt('my.blog-post.publication-date', 4)
|
63
|
+
)
|
64
|
+
form.data['q'].should == ['[[:d = number.lt(my.blog-post.publication-date, 4)]]']
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'number in range' do
|
69
|
+
it 'with helpers serializes well' do
|
70
|
+
form = @api.form('everything').query(
|
71
|
+
Predicates.in_range('my.product.price', 2, 4.5)
|
72
|
+
)
|
73
|
+
form.data['q'].should == ['[[:d = number.inRange(my.product.price, 2, 4.5)]]']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'geopoint near' do
|
78
|
+
it 'with helpers serializes well' do
|
79
|
+
form = @api.form('everything').query(
|
80
|
+
Predicates.near('my.store.coordinates', 40.689757, -74.0451453, 15)
|
81
|
+
)
|
82
|
+
form.data['q'].should == ['[[:d = geopoint.near(my.store.coordinates, 40.689757, -74.0451453, 15)]]']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
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.2
|
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-10-06 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -79,11 +79,11 @@ files:
|
|
79
79
|
- .gitignore
|
80
80
|
- .travis.yml
|
81
81
|
- .yardopts
|
82
|
-
- Changelog.md
|
83
82
|
- Gemfile
|
84
83
|
- Gemfile.lock
|
85
84
|
- README.md
|
86
85
|
- Rakefile
|
86
|
+
- deploy-doc.sh
|
87
87
|
- lib/prismic.rb
|
88
88
|
- lib/prismic/api.rb
|
89
89
|
- lib/prismic/cache/basic.rb
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/prismic/fragments/text.rb
|
106
106
|
- lib/prismic/fragments/timestamp.rb
|
107
107
|
- lib/prismic/json_parsers.rb
|
108
|
+
- lib/prismic/predicates.rb
|
108
109
|
- lib/prismic/version.rb
|
109
110
|
- prismic.gemspec
|
110
111
|
- spec/cache_spec.rb
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- spec/lesbonneschoses_spec.rb
|
114
115
|
- spec/micro_spec.rb
|
115
116
|
- spec/oauth_spec.rb
|
117
|
+
- spec/predicates_spec.rb
|
116
118
|
- spec/prismic_spec.rb
|
117
119
|
- spec/responses_mocks/api.json
|
118
120
|
- spec/responses_mocks/document.json
|
@@ -155,6 +157,7 @@ test_files:
|
|
155
157
|
- spec/lesbonneschoses_spec.rb
|
156
158
|
- spec/micro_spec.rb
|
157
159
|
- spec/oauth_spec.rb
|
160
|
+
- spec/predicates_spec.rb
|
158
161
|
- spec/prismic_spec.rb
|
159
162
|
- spec/responses_mocks/api.json
|
160
163
|
- spec/responses_mocks/document.json
|
@@ -166,3 +169,4 @@ test_files:
|
|
166
169
|
- spec/responses_mocks/structured_text_with_labels.json
|
167
170
|
- spec/responses_mocks/structured_text_with_tricky_spans.json
|
168
171
|
- spec/spec_helper.rb
|
172
|
+
has_rdoc:
|