picky-generators 1.1.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.
Files changed (40) hide show
  1. data/bin/picky-generate +14 -0
  2. data/lib/picky-generators.rb +7 -0
  3. data/lib/picky-generators/generators/base.rb +120 -0
  4. data/lib/picky-generators/generators/client/sinatra.rb +39 -0
  5. data/lib/picky-generators/generators/not_found_exception.rb +35 -0
  6. data/lib/picky-generators/generators/selector.rb +46 -0
  7. data/lib/picky-generators/generators/server/unicorn.rb +41 -0
  8. data/prototypes/client/sinatra/Gemfile +13 -0
  9. data/prototypes/client/sinatra/app.rb +65 -0
  10. data/prototypes/client/sinatra/book.rb +42 -0
  11. data/prototypes/client/sinatra/config.ru +2 -0
  12. data/prototypes/client/sinatra/images/picky.png +0 -0
  13. data/prototypes/client/sinatra/javascripts/jquery-1.3.2.js +4376 -0
  14. data/prototypes/client/sinatra/javascripts/jquery-1.4.3.min.js +166 -0
  15. data/prototypes/client/sinatra/javascripts/jquery.scrollTo-1.4.2.js +215 -0
  16. data/prototypes/client/sinatra/javascripts/jquery.timer.js +75 -0
  17. data/prototypes/client/sinatra/javascripts/picky.min.js +17 -0
  18. data/prototypes/client/sinatra/library.csv +540 -0
  19. data/prototypes/client/sinatra/stylesheets/stylesheet.css +184 -0
  20. data/prototypes/client/sinatra/stylesheets/stylesheet.sass +225 -0
  21. data/prototypes/client/sinatra/views/configure.haml +170 -0
  22. data/prototypes/client/sinatra/views/search.haml +96 -0
  23. data/prototypes/server/unicorn/Gemfile +30 -0
  24. data/prototypes/server/unicorn/Rakefile +11 -0
  25. data/prototypes/server/unicorn/app/README +5 -0
  26. data/prototypes/server/unicorn/app/application.rb +50 -0
  27. data/prototypes/server/unicorn/app/db.yml +13 -0
  28. data/prototypes/server/unicorn/app/library.csv +540 -0
  29. data/prototypes/server/unicorn/app/logging.rb +20 -0
  30. data/prototypes/server/unicorn/config.ru +35 -0
  31. data/prototypes/server/unicorn/log/README +1 -0
  32. data/prototypes/server/unicorn/script/console +34 -0
  33. data/prototypes/server/unicorn/tmp/README +0 -0
  34. data/prototypes/server/unicorn/tmp/pids/README +0 -0
  35. data/prototypes/server/unicorn/unicorn.ru +15 -0
  36. data/spec/lib/picky-generators/generators/base_spec.rb +83 -0
  37. data/spec/lib/picky-generators/generators/client/sinatra_spec.rb +35 -0
  38. data/spec/lib/picky-generators/generators/selector_spec.rb +42 -0
  39. data/spec/lib/picky-generators/generators/server/unicorn_spec.rb +35 -0
  40. metadata +147 -0
@@ -0,0 +1,184 @@
1
+ body {
2
+ text-align: center;
3
+ font-family: Lucida Grande; }
4
+
5
+ img {
6
+ margin: -2px 0px 0px; }
7
+
8
+ p span.explanation {
9
+ color: #999999; }
10
+
11
+ pre {
12
+ padding: 10px;
13
+ background-color: #efede5; }
14
+
15
+ div.content {
16
+ width: 800px;
17
+ margin: 0 auto;
18
+ text-align: left; }
19
+
20
+ #picky {
21
+ text-align: left;
22
+ margin: 0px auto;
23
+ width: 560px;
24
+ overflow: hidden; }
25
+ #picky .dashboard {
26
+ position: relative;
27
+ overflow: hidden;
28
+ background-color: lightGrey;
29
+ padding: 5px 5px 7px 5px;
30
+ height: 26px;
31
+ margin-bottom: 3px; }
32
+ #picky .status {
33
+ float: left;
34
+ width: 45px;
35
+ height: 26px;
36
+ line-height: 26px;
37
+ text-align: center;
38
+ padding: 0 0 0 2px;
39
+ font-weight: bold;
40
+ color: white;
41
+ margin-right: 5px; }
42
+ #picky .status.alert {
43
+ background-color: lightgreen; }
44
+ #picky .results {
45
+ margin-top: 0px;
46
+ padding: 0px; }
47
+ #picky .results div.book {
48
+ background-color: #ffeeee;
49
+ padding: 5px 25px;
50
+ margin: 3px 0px; }
51
+ #picky .results em {
52
+ font-style: normal;
53
+ background-color: #fff196; }
54
+ #picky .results .item {
55
+ display: block;
56
+ padding: 10px; }
57
+ #picky .results .addination {
58
+ position: relative;
59
+ text-align: center;
60
+ padding: 7px 5px 5px 5px;
61
+ background-color: #eeeeee;
62
+ color: #276abb;
63
+ cursor: pointer; }
64
+ #picky .results .addination .tothetop {
65
+ position: absolute;
66
+ top: 4px;
67
+ right: 0px; }
68
+ #picky .results .addination .tothetop a {
69
+ display: block;
70
+ width: 20px;
71
+ height: 20px; }
72
+ #picky .results .info {
73
+ color: #555555;
74
+ background-color: #eeeeee;
75
+ padding: 6px 5px 5px 8px; }
76
+ #picky .results .info .tothetop {
77
+ float: right;
78
+ margin-top: -4px; }
79
+ #picky .feedback {
80
+ width: 460px;
81
+ float: left;
82
+ border: 1px solid #cccccc;
83
+ padding: 0;
84
+ margin: 0; }
85
+ #picky .feedback .reset {
86
+ float: right;
87
+ width: 18px;
88
+ height: 18px;
89
+ margin: 3px 3px 0px 0px;
90
+ cursor: pointer;
91
+ opacity: 0; }
92
+ #picky .empty .status {
93
+ background-color: #8cacda; }
94
+ #picky .empty .feedback {
95
+ background-color: #d0e2ff; }
96
+ #picky .none .status {
97
+ background-color: red; }
98
+ #picky .none .feedback {
99
+ background-color: #ffdddd; }
100
+ #picky .support .status {
101
+ background-color: #ff6600; }
102
+ #picky .support .feedback {
103
+ background-color: #faf3d0; }
104
+ #picky .ok .status {
105
+ background-color: #09be01; }
106
+ #picky .ok .feedback {
107
+ background-color: #bcf0b3; }
108
+ #picky input.search_button {
109
+ margin: 5px 15px; }
110
+ #picky input.query {
111
+ float: left;
112
+ width: 380px;
113
+ height: 100%;
114
+ font-size: 1em;
115
+ font-weight: bold;
116
+ border-style: solid;
117
+ border-width: 0px 0px 3px 0px;
118
+ border-color: transparent;
119
+ margin: 0;
120
+ padding: 4px 0 0 0;
121
+ outline: none;
122
+ background: none; }
123
+ #picky .allocations {
124
+ clear: both;
125
+ overflow: hidden;
126
+ background-color: white;
127
+ padding-bottom: 2px; }
128
+ #picky .allocations ol.hidden {
129
+ display: none; }
130
+ #picky .allocations ol.more:hover {
131
+ background-color: #cccccc;
132
+ cursor: pointer; }
133
+ #picky .allocations ol.more {
134
+ background-color: #eeeeee;
135
+ display: none;
136
+ text-align: center;
137
+ height: 32px;
138
+ line-height: 32px; }
139
+ #picky .allocations ol.more li {
140
+ text-align: center; }
141
+ #picky .allocations ol {
142
+ list-style-position: outside;
143
+ list-style: none;
144
+ padding: 0;
145
+ margin: 0px;
146
+ overflow: hidden; }
147
+ #picky .allocations ol li {
148
+ margin: 0px;
149
+ margin-bottom: 3px;
150
+ padding: 10px 13px;
151
+ cursor: pointer;
152
+ display: block;
153
+ font: menu;
154
+ font-size: 1em;
155
+ line-height: 16px;
156
+ background-color: #f3f3f3;
157
+ overflow: hidden;
158
+ color: #276abb; }
159
+ #picky .allocations ol li .text {
160
+ max-width: 90%;
161
+ float: left; }
162
+ #picky .allocations ol li .count {
163
+ float: right;
164
+ color: #cccccc; }
165
+ #picky .allocations ol li:hover {
166
+ background-color: #d0e2ff; }
167
+ #picky .allocations .company, #picky .allocations .person {
168
+ width: 49%; }
169
+ #picky .allocations .person {
170
+ float: left;
171
+ margin-right: 10px; }
172
+ #picky .allocations .company {
173
+ float: right; }
174
+ #picky .no_results {
175
+ display: none;
176
+ clear: both;
177
+ overflow: hidden; }
178
+ #picky .no_results ul {
179
+ list-style-type: disc;
180
+ padding-left: 13px; }
181
+ #picky .no_results a {
182
+ display: block; }
183
+ #picky > .info {
184
+ display: none; }
@@ -0,0 +1,225 @@
1
+ body
2
+ :text-align center
3
+ :font-family Lucida Grande
4
+
5
+ img
6
+ :margin -2px 0px 0px
7
+
8
+ p
9
+ span.explanation
10
+ :color #999
11
+
12
+ pre
13
+ :padding 10px
14
+ :background-color #EFEDE5
15
+
16
+ div.content
17
+ :width 800px
18
+ :margin 0 auto
19
+ :text-align left
20
+
21
+ #picky
22
+ :text-align left
23
+ :margin 0px auto
24
+ :width 560px
25
+
26
+ .dashboard
27
+ :position relative
28
+ :overflow hidden
29
+ :background-color lightGrey
30
+ :padding 5px 5px 7px 5px
31
+ :height 26px
32
+ :margin-bottom 3px
33
+
34
+ .status
35
+ :float left
36
+ :width 45px
37
+ :height 26px
38
+ :line-height 26px
39
+ :text-align center
40
+ :padding 0 0 0 2px
41
+ :font-weight bold
42
+ :color white
43
+ :margin-right 5px
44
+ .status.alert
45
+ :background-color lightgreen
46
+
47
+ .results
48
+ :margin-top 0px
49
+ :padding 0px
50
+
51
+ div.book
52
+ :background-color #ffeeee
53
+ :padding 5px 25px
54
+ :margin 3px 0px
55
+
56
+ em
57
+ :font-style normal
58
+ :background-color #FFF196
59
+
60
+ .item
61
+ :display block
62
+ :padding 10px
63
+
64
+ .addination
65
+ :position relative
66
+ :text-align center
67
+ :padding 7px 5px 5px 5px
68
+ :background-color #eee
69
+ :color #276ABB
70
+ :cursor pointer
71
+
72
+ .tothetop
73
+ :position absolute
74
+ :top 4px
75
+ :right 0px
76
+
77
+ a
78
+ :display block
79
+ :width 20px
80
+ :height 20px
81
+
82
+ .info
83
+ :color #555
84
+ :background-color #eee
85
+ :padding 6px 5px 5px 8px
86
+
87
+ .tothetop
88
+ :float right
89
+ :margin-top -4px
90
+
91
+ :overflow hidden
92
+
93
+ // width only set because of IE
94
+ .feedback
95
+ :width 460px
96
+ :float left
97
+ :border 1px solid #ccc
98
+ :padding 0
99
+ :margin 0
100
+
101
+ .reset
102
+ :float right
103
+ :width 18px
104
+ :height 18px
105
+ :margin 3px 3px 0px 0px
106
+ :cursor pointer
107
+ :opacity 0
108
+
109
+ // Blue
110
+ .empty
111
+ .status
112
+ :background-color #8cacda
113
+ .feedback
114
+ :background-color #D0E2FF
115
+ // Red
116
+ .none
117
+ .status
118
+ :background-color #ff0000
119
+ .feedback
120
+ :background-color #ffdddd
121
+ // Orange
122
+ .support
123
+ .status
124
+ :background-color #ff6600
125
+ .feedback
126
+ :background-color #faf3d0
127
+ // Green
128
+ .ok
129
+ .status
130
+ :background-color #09be01
131
+ .feedback
132
+ :background-color #bcf0b3
133
+
134
+ input.search_button
135
+ :margin 5px 15px
136
+
137
+ input.query
138
+ :float left
139
+ :width 380px
140
+ :height 100%
141
+ :font-size 1em
142
+ :font-weight bold
143
+ :border-style solid
144
+ :border-width 0px 0px 3px 0px
145
+ :border-color transparent
146
+ :margin 0
147
+ :padding 4px 0 0 0
148
+ :outline none
149
+ :background none
150
+
151
+ .allocations
152
+ :clear both
153
+ :overflow hidden
154
+ :background-color white
155
+ :padding-bottom 2px
156
+
157
+ ol.hidden
158
+ :display none
159
+
160
+ ol.more:hover
161
+ :background-color #ccc
162
+ :cursor pointer
163
+ ol.more
164
+ :background-color #eee
165
+ :display none
166
+ :text-align center
167
+ :height 32px
168
+ :line-height 32px
169
+
170
+ li
171
+ :text-align center
172
+
173
+ ol
174
+ :list-style-position outside
175
+ :list-style none
176
+ :padding 0
177
+ :margin 0px
178
+ :overflow hidden
179
+
180
+ li
181
+ :margin 0px
182
+ :margin-bottom 3px
183
+ :padding 10px 13px
184
+ :cursor pointer
185
+ :display block
186
+ :font menu
187
+ :font-size 1em
188
+ :line-height 16px
189
+ :background-color #f3f3f3
190
+ :overflow hidden
191
+ :color #276ABB
192
+
193
+ .text
194
+ :max-width 90%
195
+ :float left
196
+
197
+ .count
198
+ :float right
199
+ :color #ccc
200
+
201
+ li:hover
202
+ :background-color #D0E2FF
203
+
204
+ .company, .person
205
+ :width 49%
206
+ .person
207
+ :float left
208
+ :margin-right 10px
209
+ .company
210
+ :float right
211
+
212
+ .no_results
213
+ :display none
214
+ :clear both
215
+ :overflow hidden
216
+
217
+ ul
218
+ :list-style-type disc
219
+ :padding-left 13px
220
+
221
+ a
222
+ :display block
223
+
224
+ & > .info
225
+ :display none
@@ -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*