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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8622f78a1a654d406af4edf4471810ab14e0a4a2
4
- data.tar.gz: 3861bfec9717d19b0e047d86f4e28375b6f801d6
3
+ metadata.gz: 0efa24b3f98e9f3dc05f26b50f7125e45409afa2
4
+ data.tar.gz: fb6164ea1e1fa198951e92353429fc985e4432b1
5
5
  SHA512:
6
- metadata.gz: 962b52cb0b6fa39f30058653bbbc99e44d33be0516a30afd6a8ba3c7cae6ff1ef1643da2818e8eaa1cde8e751f532b4c881f83e75f0e929a6846a36da2e0c2f2
7
- data.tar.gz: 004429336746943544191ae573d28fddd03dc8147292020ca4a7836fddc6d47f2748384f86004070463f8ab15b331bae88561792f8577a279121120395532da0
6
+ metadata.gz: 7af5bae716dcdf93e5672a8639b71ce1974c903a352739c2cf27d8dbf600b16b396bd5c4f273787f723c612aff16f1e6f4750f68cb3f40f8288d6a115e8e2501
7
+ data.tar.gz: 14d0b5d69449eeb4e3ec27a8524a0eb69358ad45545b46cc75d5cea1ee061a59cee26e6c672392a4ea555c7561b73fe41132f3eb72b696027eec99919a1cd091
data/.gitignore CHANGED
@@ -2,4 +2,7 @@ coverage/
2
2
  pkg/*.gem
3
3
  .bundle/
4
4
  .idea/
5
+ .yardoc/
6
+ doc/
7
+
5
8
 
data/.travis.yml CHANGED
@@ -17,4 +17,5 @@ deploy:
17
17
  gemspec: prismic.gemspec
18
18
  on:
19
19
  tags: true
20
+ all_branches: true
20
21
  repo: prismicio/ruby-kit
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prismic.io (1.0.1)
4
+ prismic.io (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
@@ -0,0 +1,9 @@
1
+ yard && \
2
+ cd doc && \
3
+ rm -rf doc/phpdoc-cache-* && \
4
+ git init . && \
5
+ git add . && \
6
+ git commit -m "Update documentation."; \
7
+ git push "git@github.com:prismicio/ruby-kit.git" master:gh-pages --force && \
8
+ rm -rf .git
9
+
data/lib/prismic.rb CHANGED
@@ -142,10 +142,33 @@ module Prismic
142
142
  @ref = ref
143
143
  end
144
144
 
145
- # @!method query(query)
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'
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Prismic
2
3
  module Fragments
3
4
 
@@ -190,16 +190,27 @@ module Prismic
190
190
  if pos < text.length
191
191
  if stack.empty?
192
192
  # Top level text
193
- html += CGI::escapeHTML(text[pos])
193
+ html += cgi_escape_html(text[pos])
194
194
  else
195
195
  # Inner text of a span
196
- stack[-1][:html] += CGI::escapeHTML(text[pos])
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
+ "'" => '&#39;',
207
+ '&' => '&amp;',
208
+ '"' => '&quot;',
209
+ '<' => '&lt;',
210
+ '>' => '&gt;',
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
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Prismic
3
3
 
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
 
6
6
  end
@@ -663,10 +663,10 @@ end
663
663
 
664
664
  describe 'Group' do
665
665
  before do
666
- @micro_api = Prismic.api("https://micro.prismic.io/api", nil)
666
+ @micro_api = Prismic.api('https://micro.prismic.io/api', nil)
667
667
  @master_ref = @micro_api.master_ref
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}" }
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(%([[:d = at(document.id, "UrjI1gEAALOCeO5i")]])).submit(@master_ref)[0]['article.body']
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(/&#39;/, "'").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.1
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-09-23 00:00:00.000000000 Z
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:
data/Changelog.md DELETED
@@ -1,7 +0,0 @@
1
- ### 1.0.0.rc10 (2014-09-10)
2
-
3
- Features:
4
-
5
- - Support for links in images
6
- - Support for Timestamp fragments
7
- - Support for Geopoint fragments