picky-generators 4.2.4 → 4.3.0
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/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,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*
|