picky-client 0.10.2 → 0.10.4
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.
- data/sinatra_prototype/Gemfile.lock +38 -0
- data/sinatra_prototype/app.rb +6 -0
- data/sinatra_prototype/stylesheets/stylesheet.css +9 -0
- data/sinatra_prototype/stylesheets/stylesheet.sass +9 -0
- data/sinatra_prototype/views/configure.haml +170 -0
- data/sinatra_prototype/views/search.haml +3 -1
- metadata +4 -2
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.1)
|
5
|
+
backports (1.18.2)
|
6
|
+
haml (3.0.23)
|
7
|
+
i18n (0.4.2)
|
8
|
+
monkey-lib (0.5.4)
|
9
|
+
backports
|
10
|
+
picky-client (0.10.1)
|
11
|
+
yajl-ruby (>= 0.7.8)
|
12
|
+
rack (1.2.1)
|
13
|
+
sinatra (1.1.0)
|
14
|
+
rack (~> 1.1)
|
15
|
+
tilt (~> 1.1)
|
16
|
+
sinatra-advanced-routes (0.5.1)
|
17
|
+
monkey-lib (~> 0.5.0)
|
18
|
+
sinatra (~> 1.0)
|
19
|
+
sinatra-sugar (~> 0.5.0)
|
20
|
+
sinatra-reloader (0.5.0)
|
21
|
+
sinatra (~> 1.0)
|
22
|
+
sinatra-advanced-routes (~> 0.5.0)
|
23
|
+
sinatra-sugar (0.5.0)
|
24
|
+
monkey-lib (~> 0.5.0)
|
25
|
+
sinatra (~> 1.0)
|
26
|
+
tilt (1.1)
|
27
|
+
yajl-ruby (0.7.8)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
activesupport
|
34
|
+
haml
|
35
|
+
i18n
|
36
|
+
picky-client
|
37
|
+
sinatra
|
38
|
+
sinatra-reloader
|
data/sinatra_prototype/app.rb
CHANGED
@@ -23,6 +23,12 @@ get '/' do
|
|
23
23
|
haml :'/search'
|
24
24
|
end
|
25
25
|
|
26
|
+
# Configure. The configuration info page.
|
27
|
+
#
|
28
|
+
get '/configure' do
|
29
|
+
haml :'/configure'
|
30
|
+
end
|
31
|
+
|
26
32
|
# For full results, you get the ids from the picky server
|
27
33
|
# and then populate the result with models (rendered, even).
|
28
34
|
#
|
@@ -0,0 +1,170 @@
|
|
1
|
+
!!!
|
2
|
+
%html{ :lang => 'en' }
|
3
|
+
%head
|
4
|
+
%link{:href => "stylesheets/stylesheet.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 both a client instance for a
|
31
|
+
%strong full
|
32
|
+
or a
|
33
|
+
%strong live search
|
34
|
+
depending on what you need (Full gets results with IDs, Live without and is used for updating the counter).
|
35
|
+
%p
|
36
|
+
In the example, I called it
|
37
|
+
%strong FullBooks
|
38
|
+
and
|
39
|
+
%strong LiveBooks
|
40
|
+
respectively.
|
41
|
+
%code
|
42
|
+
%pre
|
43
|
+
:preserve
|
44
|
+
FullBooks = Picky::Client::Full.new :host => 'localhost', :port => 8080, :path => '/books/full'
|
45
|
+
LiveBooks = Picky::Client::Live.new :host => 'localhost', :port => 8080, :path => '/books/live'
|
46
|
+
%p
|
47
|
+
Both clients offer the options:
|
48
|
+
%dl
|
49
|
+
%dt
|
50
|
+
%strong host
|
51
|
+
%dd The Picky search server host.
|
52
|
+
%dt
|
53
|
+
%strong port
|
54
|
+
%dd The Picky search server port (see unicorn.rb in the server).
|
55
|
+
%dt
|
56
|
+
%strong path
|
57
|
+
%dd The Picky search path (see app/application.rb in the server for the mapping path => query).
|
58
|
+
%p
|
59
|
+
Then, use these Client instances in your actions. For example like this:
|
60
|
+
%code
|
61
|
+
%pre
|
62
|
+
:preserve
|
63
|
+
get '/search/full' do
|
64
|
+
results = FullBooks.search :query => params[:query], :offset => params[:offset]
|
65
|
+
results.extend Picky::Convenience
|
66
|
+
results.populate_with Book do |book|
|
67
|
+
book.to_s
|
68
|
+
end
|
69
|
+
ActiveSupport::JSON.encode results
|
70
|
+
end
|
71
|
+
%p
|
72
|
+
This part gets a
|
73
|
+
%strong hash
|
74
|
+
with the results:
|
75
|
+
%code
|
76
|
+
%pre results = FullBooks.search :query => params[:query], :offset => params[:offset]
|
77
|
+
%p
|
78
|
+
This part takes the
|
79
|
+
%strong hash
|
80
|
+
and extends it with a few useful and convenient methods:
|
81
|
+
%code
|
82
|
+
%pre results.extend Picky::Convenience
|
83
|
+
%p
|
84
|
+
One of these methods is the
|
85
|
+
%strong populate_with
|
86
|
+
method which takes a
|
87
|
+
%strong model
|
88
|
+
as parameter, and then gets the corresponding
|
89
|
+
%strong model instances
|
90
|
+
for each id in the result.
|
91
|
+
%code
|
92
|
+
%pre
|
93
|
+
:preserve
|
94
|
+
results.populate_with Book do |book|
|
95
|
+
book.to_s
|
96
|
+
end
|
97
|
+
The
|
98
|
+
%strong book.to_s
|
99
|
+
simulates rendering a book.
|
100
|
+
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.
|
101
|
+
%p
|
102
|
+
If you don't want to render in the controller, you can do so in a view. In the controller just call
|
103
|
+
%code
|
104
|
+
%pre
|
105
|
+
results.populate_with Book
|
106
|
+
and then render the books in a view using:
|
107
|
+
%code
|
108
|
+
%pre
|
109
|
+
:preserve
|
110
|
+
results.entries do |book|
|
111
|
+
render book # or book.to_s, or however you like to render the book.
|
112
|
+
end
|
113
|
+
%p
|
114
|
+
At the end, encode the hash in JSON:
|
115
|
+
%code
|
116
|
+
%pre
|
117
|
+
ActiveSupport::JSON.encode results
|
118
|
+
That's it for the controller.
|
119
|
+
%p
|
120
|
+
All the steps in one:
|
121
|
+
%code
|
122
|
+
%pre
|
123
|
+
:preserve
|
124
|
+
FullBooks = Picky::Client::Full.new :host => 'localhost', :port => 8080, :path => '/books/full'
|
125
|
+
LiveBooks = Picky::Client::Live.new :host => 'localhost', :port => 8080, :path => '/books/live'
|
126
|
+
|
127
|
+
get '/search/full' do
|
128
|
+
results = FullBooks.search :query => params[:query], :offset => params[:offset]
|
129
|
+
|
130
|
+
results.extend Picky::Convenience
|
131
|
+
results.populate_with Book do |book|
|
132
|
+
book.to_s
|
133
|
+
end
|
134
|
+
|
135
|
+
ActiveSupport::JSON.encode results
|
136
|
+
end
|
137
|
+
%h2#view View
|
138
|
+
%p
|
139
|
+
The view is even easier. Just add the line
|
140
|
+
%code
|
141
|
+
%pre
|
142
|
+
\= Picky::Helper.cached_interface
|
143
|
+
if you use just one language, or
|
144
|
+
%code
|
145
|
+
%pre
|
146
|
+
\= Picky::Helper.interface :button => 'search', :no_results => 'No results!', :more => 'more'
|
147
|
+
if you use multiple languages.
|
148
|
+
(You'd use the options
|
149
|
+
%pre :button => t(:'search.button'), :no_results => t(:'search.no_results'), :more => t(:'search.more')
|
150
|
+
of course, with proper i18n)
|
151
|
+
The same options can be used for
|
152
|
+
%strong #cached_interface
|
153
|
+
but they will be cached, so you can only set them once and then reused.
|
154
|
+
%p
|
155
|
+
You're almost finished. Take a look at the file
|
156
|
+
%strong views/search.haml
|
157
|
+
where you'll find javascript at the end. It looks something like this:
|
158
|
+
%code
|
159
|
+
%pre
|
160
|
+
:preserve
|
161
|
+
:javascript
|
162
|
+
pickyClient = new PickyClient({
|
163
|
+
// A full query displays the rendered results.
|
164
|
+
//
|
165
|
+
full: '/search/full',
|
166
|
+
|
167
|
+
// etc.
|
168
|
+
Just take a look at the possible javascript client options in that file.
|
169
|
+
%p
|
170
|
+
%strong Good luck my friend! *waves several stubby pink tentacles*
|
@@ -22,7 +22,9 @@
|
|
22
22
|
%body
|
23
23
|
%img{:src => "images/picky.png"}/
|
24
24
|
%p
|
25
|
-
%a{:href => "http://floere.github.com/picky"}
|
25
|
+
%a{:href => "http://floere.github.com/picky"} To the Picky Homepage
|
26
|
+
\/
|
27
|
+
%a{:href => '/configure' } Configuring this app server
|
26
28
|
%p
|
27
29
|
Try a few examples
|
28
30
|
= succeed ":" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 10
|
8
|
-
-
|
9
|
-
version: 0.10.
|
8
|
+
- 4
|
9
|
+
version: 0.10.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- sinatra_prototype/book.rb
|
51
51
|
- sinatra_prototype/config.ru
|
52
52
|
- sinatra_prototype/Gemfile
|
53
|
+
- sinatra_prototype/Gemfile.lock
|
53
54
|
- sinatra_prototype/images/picky.png
|
54
55
|
- sinatra_prototype/javascripts/compiler.jar
|
55
56
|
- sinatra_prototype/javascripts/generate_bundles
|
@@ -73,6 +74,7 @@ files:
|
|
73
74
|
- sinatra_prototype/library.csv
|
74
75
|
- sinatra_prototype/stylesheets/stylesheet.css
|
75
76
|
- sinatra_prototype/stylesheets/stylesheet.sass
|
77
|
+
- sinatra_prototype/views/configure.haml
|
76
78
|
- sinatra_prototype/views/search.haml
|
77
79
|
- README.rdoc
|
78
80
|
- spec/picky-client/convenience_spec.rb
|