picky-generators 4.2.4 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/prototypes/all_in_one/sinatra/app.rb +1 -7
- data/prototypes/all_in_one/sinatra/book.rb +10 -10
- data/prototypes/all_in_one/sinatra/images/picky.png +0 -0
- data/prototypes/all_in_one/sinatra/javascripts/picky.min.js +19 -17
- data/prototypes/all_in_one/sinatra/stylesheets/application.css +82 -18
- data/prototypes/all_in_one/sinatra/stylesheets/images/background.png +0 -0
- data/prototypes/all_in_one/sinatra/stylesheets/images/cancel.svg +10 -0
- data/prototypes/all_in_one/sinatra/stylesheets/picky.css +277 -135
- data/prototypes/all_in_one/sinatra/views/search.haml +232 -58
- data/prototypes/client/sinatra/app.rb +19 -30
- data/prototypes/client/sinatra/book.rb +9 -9
- data/prototypes/client/sinatra/images/picky.png +0 -0
- data/prototypes/client/sinatra/javascripts/picky.min.js +19 -17
- data/prototypes/client/sinatra/stylesheets/application.css +82 -18
- data/prototypes/client/sinatra/stylesheets/images/background.png +0 -0
- data/prototypes/client/sinatra/stylesheets/images/cancel.svg +10 -0
- data/prototypes/client/sinatra/stylesheets/picky.css +277 -135
- data/prototypes/client/sinatra/views/search.haml +232 -58
- metadata +14 -12
- data/prototypes/all_in_one/sinatra/views/configure.haml +0 -188
- data/prototypes/client/sinatra/views/configure.haml +0 -188
@@ -1,60 +1,232 @@
|
|
1
1
|
!!!
|
2
2
|
%html{ :lang => 'en' }
|
3
3
|
%head
|
4
|
-
%link{:href => "stylesheets/picky.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
|
5
4
|
%link{:href => "stylesheets/application.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
|
6
|
-
|
5
|
+
%link{:href => "stylesheets/picky.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
|
7
6
|
= js 'jquery-1.5.0.min'
|
8
7
|
= js 'history.min'
|
9
8
|
= js 'history.adapter.jquery.min'
|
10
9
|
= js 'picky.min'
|
11
10
|
|
12
11
|
%body
|
13
|
-
%
|
14
|
-
|
15
|
-
%
|
16
|
-
|
17
|
-
%
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
A simple word,
|
24
|
-
= succeed "." do
|
25
|
-
%a{:href => "#", :onclick => "pickyClient.insert('alan');"} alan
|
26
|
-
%span.explanation
|
27
|
-
(Finds Alan in the title, and Alans who wrote books. The title is ranked higher due to weighing.)
|
28
|
-
%span
|
29
|
-
%p
|
30
|
-
With qualifier,
|
31
|
-
= succeed "." do
|
32
|
-
%a{:href => "#", :onclick => "pickyClient.insert('title:women');"} title:women
|
33
|
-
%span.explanation
|
34
|
-
(Finds "women*" just in titles.)
|
35
|
-
%span
|
36
|
-
%p
|
37
|
-
With similarity,
|
38
|
-
= succeed "." do
|
39
|
-
%a{:href => "#", :onclick => "pickyClient.insert('pinchn~');"} pinchn~
|
40
|
-
%span.explanation (Finds "pynchon", note: Only title in example with similarity. Uses a combination of double metaphone and Levenshtein.)
|
41
|
-
%p
|
42
|
-
More complex,
|
43
|
-
= succeed "." do
|
44
|
-
%a{:href => "#", :onclick => "pickyClient.insert('title:lyterature~');"} title:lyterature~
|
45
|
-
%span.explanation (Finds similar titles)
|
46
|
-
%p
|
47
|
-
With choice,
|
48
|
-
= succeed "." do
|
49
|
-
%a{:href => "#", :onclick => "pickyClient.insert('sp');"} sp
|
50
|
-
%span.explanation (Finds "sp*" in multiple categories. Choose the one you're looking for.)
|
51
|
-
%p
|
52
|
-
More complex,
|
53
|
-
= succeed "." do
|
54
|
-
%a{:href => "#", :onclick => "pickyClient.insert('soc* p');"} soc* p
|
55
|
-
%span.explanation (This is where Picky really shines, "the title started with soc, and the author starts with p")
|
12
|
+
%hgroup
|
13
|
+
/ Replace these headers with your code
|
14
|
+
%img{ :class => 'picky', :src => "images/picky.png"}/
|
15
|
+
%h1 Picky
|
16
|
+
%h2
|
17
|
+
Scaffold: A great start into your
|
18
|
+
%em fantastic
|
19
|
+
search engine!
|
20
|
+
☛
|
21
|
+
%a{ :href => "http://florianhanke.com/picky" } Picky Homepage
|
56
22
|
.content
|
57
23
|
= Picky::Helper.cached_interface
|
24
|
+
%section
|
25
|
+
%h1 Examples:
|
26
|
+
%p
|
27
|
+
%a{:href => "", :onclick => "pickyClient.insert('alan');"} alan
|
28
|
+
finds Alan in the title, and Alans who wrote books. The title is ranked higher due to weighing.
|
29
|
+
%p
|
30
|
+
%a{:href => "", :onclick => "pickyClient.insert('title:women');"} title:women
|
31
|
+
finds "women*" just in titles.
|
32
|
+
%p
|
33
|
+
%a{:href => "", :onclick => "pickyClient.insert('pinchn~');"} pinchn~
|
34
|
+
finds the similar "pynchon".
|
35
|
+
%p
|
36
|
+
%a{:href => "", :onclick => "pickyClient.insert('title:lyterature~');"} title:lyterature~
|
37
|
+
finds similar titles.
|
38
|
+
%p
|
39
|
+
%a{:href => "", :onclick => "pickyClient.insert('sp');"} sp
|
40
|
+
finds "sp*" in multiple categories. Choose the one you're looking for.
|
41
|
+
%p
|
42
|
+
%a{:href => "", :onclick => "pickyClient.insert('soc* p');"} soc* p
|
43
|
+
means "find something that starts with soc, and another thing starting with p".
|
44
|
+
%section
|
45
|
+
%h1 Already made it this far? You're good!
|
46
|
+
%p I think you're ready for configuring me for your own purposes.
|
47
|
+
%h2 Configuring the Picky client.
|
48
|
+
%p
|
49
|
+
There are two places where you configure the Picky client:
|
50
|
+
%ol
|
51
|
+
%li
|
52
|
+
%a{ :href => '#controller' } In the controller.
|
53
|
+
(client to Picky server)
|
54
|
+
%li
|
55
|
+
%a{ :href => '#view' } In the view.
|
56
|
+
(javascript client interface)
|
57
|
+
%h2#controller Controller
|
58
|
+
%p
|
59
|
+
Open the file
|
60
|
+
%strong app.rb
|
61
|
+
and take a peek inside.
|
62
|
+
%p
|
63
|
+
First you need both a client instance for a
|
64
|
+
%strong full
|
65
|
+
or a
|
66
|
+
%strong live search
|
67
|
+
depending on what you need (Full gets results with IDs, Live without and is used for updating the counter).
|
68
|
+
%p
|
69
|
+
In the example, I called it
|
70
|
+
%strong BookSearch
|
71
|
+
\.
|
72
|
+
%code
|
73
|
+
%pre
|
74
|
+
:preserve
|
75
|
+
BookSearch = Picky::Client.new host: 'localhost',
|
76
|
+
port: 8080,
|
77
|
+
path: '/books'
|
78
|
+
%p
|
79
|
+
Both clients offer the options:
|
80
|
+
%dl
|
81
|
+
%dt
|
82
|
+
%strong host
|
83
|
+
%dd The Picky search server host.
|
84
|
+
%dt
|
85
|
+
%strong port
|
86
|
+
%dd The Picky search server port (see unicorn.rb in the server).
|
87
|
+
%dt
|
88
|
+
%strong path
|
89
|
+
%dd The Picky search path (see app.rb in the server).
|
90
|
+
%p
|
91
|
+
Then, use these Client instances in your actions. For example like this:
|
92
|
+
%code
|
93
|
+
%pre
|
94
|
+
:preserve
|
95
|
+
get '/search/full' do
|
96
|
+
results = BookSearch.search params[:query],
|
97
|
+
:ids => params[:ids],
|
98
|
+
:offset => params[:offset]
|
99
|
+
results.extend Picky::Convenience
|
100
|
+
results.populate_with Book do |book|
|
101
|
+
book.to_s
|
102
|
+
end
|
103
|
+
ActiveSupport::JSON.encode results
|
104
|
+
end
|
105
|
+
%p
|
106
|
+
This part gets a
|
107
|
+
%strong hash
|
108
|
+
with the results:
|
109
|
+
%code
|
110
|
+
%pre
|
111
|
+
:preserve
|
112
|
+
results = BookSearch.search params[:query],
|
113
|
+
:ids => params[:ids],
|
114
|
+
:offset => params[:offset]
|
115
|
+
%p
|
116
|
+
This part takes the
|
117
|
+
%strong hash
|
118
|
+
and extends it with a few useful and convenient methods:
|
119
|
+
%code
|
120
|
+
%pre results.extend Picky::Convenience
|
121
|
+
%p
|
122
|
+
One of these methods is the
|
123
|
+
%strong populate_with
|
124
|
+
method which takes a
|
125
|
+
%strong model
|
126
|
+
as parameter, and then gets the corresponding
|
127
|
+
%strong model instances
|
128
|
+
for each id in the result.
|
129
|
+
%code
|
130
|
+
%pre
|
131
|
+
:preserve
|
132
|
+
results.populate_with Book do |book|
|
133
|
+
book.to_s
|
134
|
+
end
|
135
|
+
The
|
136
|
+
%strong book.to_s
|
137
|
+
simulates rendering a book.
|
138
|
+
You can do whatever with the book instance if you just return a rendered thing that's supposed to be shown in the front end.
|
139
|
+
%p
|
140
|
+
If you don't want to render in the controller, you can do so in a view. In the controller just call
|
141
|
+
%code
|
142
|
+
%pre
|
143
|
+
results.populate_with Book
|
144
|
+
and then render the books in a view using:
|
145
|
+
%code
|
146
|
+
%pre
|
147
|
+
:preserve
|
148
|
+
results.entries do |book|
|
149
|
+
render book # or book.to_s, or however you like to render the book.
|
150
|
+
end
|
151
|
+
%p
|
152
|
+
At the end, encode the hash in JSON:
|
153
|
+
%code
|
154
|
+
%pre
|
155
|
+
ActiveSupport::JSON.encode results
|
156
|
+
That's it for the controller.
|
157
|
+
%p
|
158
|
+
All the steps in one:
|
159
|
+
%code
|
160
|
+
%pre
|
161
|
+
:preserve
|
162
|
+
BookSearch = Picky::Client.new host: 'localhost',
|
163
|
+
port: 8080,
|
164
|
+
path: '/books'
|
165
|
+
|
166
|
+
get '/search/full' do
|
167
|
+
results = BookSearch.search params[:query],
|
168
|
+
ids: params[:ids],
|
169
|
+
offset: params[:offset]
|
170
|
+
|
171
|
+
results.extend Picky::Convenience
|
172
|
+
results.populate_with Book do |book|
|
173
|
+
book.to_s
|
174
|
+
end
|
175
|
+
|
176
|
+
ActiveSupport::JSON.encode results
|
177
|
+
end
|
178
|
+
%h2#view View
|
179
|
+
%p
|
180
|
+
The view is even easier. Just add the line
|
181
|
+
%code
|
182
|
+
%pre
|
183
|
+
:preserve
|
184
|
+
= Picky::Helper.cached_interface
|
185
|
+
if you use just one language, or
|
186
|
+
%code
|
187
|
+
%pre
|
188
|
+
:preserve
|
189
|
+
= Picky::Helper.interface button: 'search',
|
190
|
+
no_results: 'No results!',
|
191
|
+
more: 'more'
|
192
|
+
if you use multiple languages.
|
193
|
+
(You'd use the options
|
194
|
+
%code
|
195
|
+
%pre
|
196
|
+
:preserve
|
197
|
+
button: t(:'search.button'),
|
198
|
+
no_results: t(:'search.no_results'),
|
199
|
+
more: t(:'search.more')
|
200
|
+
of course, with proper i18n)
|
201
|
+
The same options can be used for
|
202
|
+
%strong #cached_interface
|
203
|
+
but they will be cached, so you can only set them once and then reused.
|
204
|
+
%p
|
205
|
+
You're almost finished. Take a look at the file
|
206
|
+
%strong views/search.haml
|
207
|
+
where you'll find javascript at the end. It looks something like this:
|
208
|
+
%code
|
209
|
+
%pre
|
210
|
+
:preserve
|
211
|
+
:javascript
|
212
|
+
pickyClient = new PickyClient({
|
213
|
+
// A full query displays the rendered results.
|
214
|
+
//
|
215
|
+
full: '/search/full',
|
216
|
+
|
217
|
+
// etc.
|
218
|
+
Just take a look at the possible javascript client options in that file.
|
219
|
+
%p
|
220
|
+
%strong Good luck my friend!
|
221
|
+
%em *waves several stubby pink tentacles*
|
222
|
+
%footer
|
223
|
+
Website design by
|
224
|
+
%a{ :href => 'http://twitter.com/thijs' } Thijs van der Vossen
|
225
|
+
of
|
226
|
+
%a{ :href => 'http://fngtps.com' } Fingertips
|
227
|
+
with modifications by
|
228
|
+
= succeed('.') do
|
229
|
+
%a{ :href => 'http://twitter.com/hanke' } Florian Hanke
|
58
230
|
:javascript
|
59
231
|
$(window).load(function() {
|
60
232
|
pickyClient = new PickyClient({
|
@@ -63,13 +235,12 @@
|
|
63
235
|
full: '/search/full',
|
64
236
|
// fullResults: 100, // Optional. Amount of ids to search for, default 20.
|
65
237
|
|
66
|
-
// A live query just updates the count
|
67
|
-
// to render (could go straight to the search server).
|
238
|
+
// A live query just updates the count.
|
68
239
|
//
|
69
240
|
live: '/search/live',
|
70
241
|
// liveResults: 0, // Optional. Amount of ids to search for, default 0.
|
71
242
|
|
72
|
-
// showResultsLimit:
|
243
|
+
// showResultsLimit: 100, // Optional. Default is 10.
|
73
244
|
|
74
245
|
// Wrap each li group (like author-title, or title-isbn etc.) of results
|
75
246
|
// in this element.
|
@@ -77,7 +248,7 @@
|
|
77
248
|
//
|
78
249
|
// wrapResults: '<div class="hello"><ol class="world"></ol></div>',
|
79
250
|
|
80
|
-
// before: function(query, params) { }, // Optional. Before Picky sends any data. Return modified query
|
251
|
+
// before: function(query, params) { }, // Optional. Before Picky sends any data. Return modified query.
|
81
252
|
// success: function(data, query) { }, // Optional. Just after Picky receives data. (Get a PickyData object)
|
82
253
|
// after: function(data, query) { }, // Optional. After Picky has handled the data and updated the view.
|
83
254
|
|
@@ -103,14 +274,17 @@
|
|
103
274
|
choices: {
|
104
275
|
en:{
|
105
276
|
'title': {
|
106
|
-
format: "<strong>%1$s</strong>",
|
277
|
+
format: "Called <strong>%1$s</strong>",
|
107
278
|
filter: function(text) { return text.toUpperCase(); },
|
108
|
-
ignoreSingle:
|
279
|
+
ignoreSingle: true
|
109
280
|
},
|
110
|
-
'author
|
111
|
-
'
|
112
|
-
'
|
113
|
-
'author,
|
281
|
+
'author': 'Written by %1$s',
|
282
|
+
'subjects': 'Being about %1$s',
|
283
|
+
'publisher': 'Published by %1$s',
|
284
|
+
'author,title': 'Called %1$s, written by %2$s',
|
285
|
+
'title,author': 'Called %2$s, written by %1$s',
|
286
|
+
'title,subjects': 'Called %1$s, about %2$s',
|
287
|
+
'author,subjects': '%1$s who wrote about %2$s'
|
114
288
|
}
|
115
289
|
},
|
116
290
|
|
@@ -122,9 +296,9 @@
|
|
122
296
|
en:{
|
123
297
|
title: 'titled',
|
124
298
|
author: 'written by',
|
125
|
-
year: 'published in'
|
126
|
-
|
127
|
-
|
299
|
+
year: 'published in',
|
300
|
+
publisher: 'published by',
|
301
|
+
subjects: 'with subjects'
|
128
302
|
}
|
129
303
|
}
|
130
304
|
});
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky-generators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70259370500900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,29 +21,29 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70259370500900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: picky
|
27
|
-
requirement: &
|
27
|
+
requirement: &70259370500400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 4.
|
32
|
+
version: 4.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70259370500400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: picky-client
|
38
|
-
requirement: &
|
38
|
+
requirement: &70259370499900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 4.
|
43
|
+
version: 4.3.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70259370499900
|
47
47
|
description: Generators for Picky.
|
48
48
|
email: florian.hanke+picky-generators@gmail.com
|
49
49
|
executables:
|
@@ -70,8 +70,9 @@ files:
|
|
70
70
|
- prototypes/all_in_one/sinatra/Rakefile
|
71
71
|
- prototypes/all_in_one/sinatra/spec/integration_spec.rb
|
72
72
|
- prototypes/all_in_one/sinatra/stylesheets/application.css
|
73
|
+
- prototypes/all_in_one/sinatra/stylesheets/images/background.png
|
74
|
+
- prototypes/all_in_one/sinatra/stylesheets/images/cancel.svg
|
73
75
|
- prototypes/all_in_one/sinatra/stylesheets/picky.css
|
74
|
-
- prototypes/all_in_one/sinatra/views/configure.haml
|
75
76
|
- prototypes/all_in_one/sinatra/views/search.haml
|
76
77
|
- prototypes/client/sinatra/app.rb
|
77
78
|
- prototypes/client/sinatra/book.rb
|
@@ -85,8 +86,9 @@ files:
|
|
85
86
|
- prototypes/client/sinatra/library.csv
|
86
87
|
- prototypes/client/sinatra/Rakefile
|
87
88
|
- prototypes/client/sinatra/stylesheets/application.css
|
89
|
+
- prototypes/client/sinatra/stylesheets/images/background.png
|
90
|
+
- prototypes/client/sinatra/stylesheets/images/cancel.svg
|
88
91
|
- prototypes/client/sinatra/stylesheets/picky.css
|
89
|
-
- prototypes/client/sinatra/views/configure.haml
|
90
92
|
- prototypes/client/sinatra/views/search.haml
|
91
93
|
- prototypes/server/sinatra/app.rb
|
92
94
|
- prototypes/server/sinatra/log/README
|
@@ -1,188 +0,0 @@
|
|
1
|
-
!!!
|
2
|
-
%html{ :lang => 'en' }
|
3
|
-
%head
|
4
|
-
%link{:href => "stylesheets/application.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
|
5
|
-
%body
|
6
|
-
%img{:src => "images/picky.png"}/
|
7
|
-
%p
|
8
|
-
%a{:href => "http://floere.github.com/picky"} To the Picky Homepage
|
9
|
-
\/
|
10
|
-
%a{:href => '/' } Back to the example
|
11
|
-
.content
|
12
|
-
%h1 Already made it this far? You're good!
|
13
|
-
%p I think you're ready for configuring me for your own purposes.
|
14
|
-
%h2 Configuring the Picky client.
|
15
|
-
%p
|
16
|
-
There are two places where you configure the Picky client:
|
17
|
-
%ol
|
18
|
-
%li
|
19
|
-
%a{ :href => '#controller' } In the controller.
|
20
|
-
(client to Picky server)
|
21
|
-
%li
|
22
|
-
%a{ :href => '#view' } In the view.
|
23
|
-
(javascript client interface)
|
24
|
-
%h2#controller Controller
|
25
|
-
%p
|
26
|
-
Open the file
|
27
|
-
%strong app.rb
|
28
|
-
and take a peek inside.
|
29
|
-
%p
|
30
|
-
First you need a client instance.
|
31
|
-
%p
|
32
|
-
In the example, I called it
|
33
|
-
%strong BookSearch
|
34
|
-
respectively.
|
35
|
-
%code
|
36
|
-
%pre
|
37
|
-
:preserve
|
38
|
-
BookSearch = Picky::Client.new :host => 'localhost',
|
39
|
-
:port => 8080,
|
40
|
-
:path => '/books'
|
41
|
-
%p
|
42
|
-
Both clients offer the options:
|
43
|
-
%dl
|
44
|
-
%dt
|
45
|
-
%strong host
|
46
|
-
%dd The Picky search server host.
|
47
|
-
%dt
|
48
|
-
%strong port
|
49
|
-
%dd The Picky search server port (see unicorn.rb in the server).
|
50
|
-
%dt
|
51
|
-
%strong path
|
52
|
-
%dd The Picky search path (see app/application.rb in the server for the mapping path => query).
|
53
|
-
%p
|
54
|
-
Then, use these Client instances in your actions. For example like this:
|
55
|
-
%code
|
56
|
-
%pre
|
57
|
-
:preserve
|
58
|
-
get '/search/full' do
|
59
|
-
results = BookSearch.search params[:query],
|
60
|
-
:ids => params[:ids],
|
61
|
-
:offset => params[:offset]
|
62
|
-
results.extend Picky::Convenience
|
63
|
-
results.populate_with Book do |book|
|
64
|
-
book.to_s
|
65
|
-
end
|
66
|
-
ActiveSupport::JSON.encode results
|
67
|
-
end
|
68
|
-
%p
|
69
|
-
This part gets a
|
70
|
-
%strong hash
|
71
|
-
with the results:
|
72
|
-
%code
|
73
|
-
%pre
|
74
|
-
:preserve
|
75
|
-
results = BookSearch.search params[:query],
|
76
|
-
:ids => params[:ids],
|
77
|
-
:offset => params[:offset]
|
78
|
-
%p
|
79
|
-
This part takes the
|
80
|
-
%strong hash
|
81
|
-
and extends it with a few useful and convenient methods:
|
82
|
-
%code
|
83
|
-
%pre
|
84
|
-
results.extend Picky::Convenience
|
85
|
-
%p
|
86
|
-
One of these methods is the
|
87
|
-
%strong populate_with
|
88
|
-
method which takes a
|
89
|
-
%strong model
|
90
|
-
as parameter, and then gets the corresponding
|
91
|
-
%strong model instances
|
92
|
-
for each id in the result.
|
93
|
-
%code
|
94
|
-
%pre
|
95
|
-
:preserve
|
96
|
-
results.populate_with Book do |book|
|
97
|
-
book.to_s
|
98
|
-
end
|
99
|
-
The
|
100
|
-
%strong book.to_s
|
101
|
-
simulates rendering a book.
|
102
|
-
You can do whatever with the book instance if you just return a rendered thing that's supposed to be shown in the front end.
|
103
|
-
%p
|
104
|
-
If you don't want to render in the controller, you can do so in a view. In the controller just call
|
105
|
-
%code
|
106
|
-
%pre
|
107
|
-
results.populate_with Book
|
108
|
-
and then render the books in a view using:
|
109
|
-
%code
|
110
|
-
%pre
|
111
|
-
:preserve
|
112
|
-
results.entries do |book|
|
113
|
-
# Or use book.to_s, or however you like
|
114
|
-
# to render the book.
|
115
|
-
#
|
116
|
-
render book
|
117
|
-
end
|
118
|
-
%p
|
119
|
-
At the end, encode the hash in JSON:
|
120
|
-
%code
|
121
|
-
%pre
|
122
|
-
ActiveSupport::JSON.encode results
|
123
|
-
That's it for the controller.
|
124
|
-
%p
|
125
|
-
All the steps in one:
|
126
|
-
%code
|
127
|
-
%pre
|
128
|
-
:preserve
|
129
|
-
BookSearch = Picky::Client.new :host => 'localhost',
|
130
|
-
:port => 8080,
|
131
|
-
:path => '/books'
|
132
|
-
|
133
|
-
get '/search/full' do
|
134
|
-
results = BookSearch.search params[:query],
|
135
|
-
:ids => params[:ids],
|
136
|
-
:offset => params[:offset]
|
137
|
-
|
138
|
-
results.extend Picky::Convenience
|
139
|
-
results.populate_with Book do |book|
|
140
|
-
book.to_s
|
141
|
-
end
|
142
|
-
|
143
|
-
ActiveSupport::JSON.encode results
|
144
|
-
end
|
145
|
-
%h2#view View
|
146
|
-
%p
|
147
|
-
The view is even easier. Just add the line
|
148
|
-
%code
|
149
|
-
%pre
|
150
|
-
:preserve
|
151
|
-
= Picky::Helper.cached_interface
|
152
|
-
if you use just one language, or
|
153
|
-
%code
|
154
|
-
%pre
|
155
|
-
:preserve
|
156
|
-
= Picky::Helper.interface :button => 'search',
|
157
|
-
:no_results => 'No results!',
|
158
|
-
:more => 'more'
|
159
|
-
if you use multiple languages.
|
160
|
-
(You'd use the options
|
161
|
-
%code
|
162
|
-
%pre
|
163
|
-
:preserve
|
164
|
-
:button => t(:'search.button'),
|
165
|
-
:no_results => t(:'search.no_results'),
|
166
|
-
:more => t(:'search.more')
|
167
|
-
of course, with proper i18n)
|
168
|
-
The same options can be used for
|
169
|
-
%strong #cached_interface
|
170
|
-
but they will be cached, so you can only set them once and then reused.
|
171
|
-
%p
|
172
|
-
You're almost finished. Take a look at the file
|
173
|
-
%strong views/search.haml
|
174
|
-
where you'll find javascript at the end. It looks something like this:
|
175
|
-
%code
|
176
|
-
%pre
|
177
|
-
:preserve
|
178
|
-
:javascript
|
179
|
-
pickyClient = new PickyClient({
|
180
|
-
// A full query displays the rendered results.
|
181
|
-
//
|
182
|
-
full: '/search/full',
|
183
|
-
|
184
|
-
// etc.
|
185
|
-
//
|
186
|
-
Just take a look at the possible javascript client options in that file.
|
187
|
-
%p
|
188
|
-
%strong Good luck my friend! *waves several stubby pink tentacles*
|