-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigoletexas.rb
540 lines (502 loc) · 17 KB
/
bigoletexas.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
require 'camping'
require 'yaml'
Camping.goes :Texas
module Texas
def r404(path)
render :fouroh
end
def r501(method)
render :fiveoh
end
def r500(klass, method, ex)
puts "#{klass}##{method} #{ex}"
render :fiveohoh
end
end
module Texas::Controllers
class Index < R '/'
def get
render :bigole
end
def post
redirect '/'
end
end
class BigOle < R '/git-sum'
@@texas_bigger = []
@@texas_smaller = []
@@search_data = YAML::load_file('data/base.yaml')
File.open('data/texas-bigger.data','r').each_line do |line|
@@texas_bigger << line.chomp("\n")
end
File.open('data/texas-smaller.data','r').each_line do |line|
@@texas_smaller << line.chomp("\n")
end
def get
redirect '/'
end
def post
if not input.search_region or input.search_region.to_s.empty?
render :fail
else
@search_term = input.search_region.to_s
flattened_string = @search_term.downcase.gsub(/\s+/, "")
if flattened_string == "mom"
@search_term = "Your Mom"
flattened_string = "yourmom"
end
@texas_bigger = Array.new(@@texas_bigger).shuffle!
@texas_smaller = Array.new(@@texas_smaller).shuffle!
@search_data = @@search_data.clone
results = @search_data.keys.select{|k| k.downcase.gsub(/\s+/, '') == flattened_string }
if results.empty?
results = @search_data.keys.select{|k| k.downcase.gsub(/\s+/, '').include?(flattened_string) }.sort_by{|k|k.size}
end
if results.empty?
render :fail
else
results.uniq!
@search_result = @search_data[results.first]
if results.first != @search_term
@search_term = results.first
end
render :gitsum
end
end
end
end
class Howdy < R '/howdy-yall'
def get
render :howdy
end
def post
redirect '/'
end
end
class Thanks < R '/thanks-yall'
def get
render :thanks
end
def post
redirect '/'
end
end
class Static < R '/static/(.+)'
MIME_TYPES = {
'.css' => 'text/css',
'.js' => 'text/javascript',
'.png' => 'image/png'
}
PATH = File.expand_path(File.dirname(__FILE__))
def get(path)
@headers['Content-Type'] = MIME_TYPES[path[/\.\w+$/, 0]] || 'text/plain'
unless path.include? ".." # prevent directory traversal attacks
@headers['X-Sendfile'] = "#{PATH}/static/#{path}"
else
@status = '403'
'403'
end
end
end
end
module Texas::Views
def layout
html do
head do
link :rel => 'shortcut icon', :href => 'static/image/favicon.ico'
title { "Big 'Ole Texas" }
link :rel => 'stylesheet', :type => 'text/css', :href => 'static/css/reset.css'
link :rel => 'stylesheet', :type => 'text/css', :href => 'static/css/text.css'
link :rel => 'stylesheet', :type => 'text/css', :href => 'static/css/960.css'
link :rel => 'stylesheet', :type => 'text/css', :href => 'static/css/bot.css'
script :type => 'text/js', :src => 'static/js/jquery.js'
script :type => 'text/js', :src => 'static/js/breakpoints.js'
script :type => 'text/js', :src => 'static/js/adjust-size.js'
#script :type => "text/javascript" do
# File.read('js/league-gothic.js')
#end
#script :type => "text/javascript" do
# File.read('js/league-gothic.js')
#end
#script :type => "text/javascript" do
# File.read('js/analytics.js')
#end
end
body do
div.header! :class => "container_16 alpha omega" do
div.bot! :class => "grid_16 alpha omega", :style => "width: 100%;" do
img :src => 'static/image/header.png', :border => "0", :width => "100%", :height => "15%"
end
end
div.bodyContainer! do
div.main! do
self << yield
end
end
div.footer! :class => "container_12" do
div :class => "grid_2" do end
div.howdy! :class => "grid_2" do
a :href => '/howdy-yall' do
img :src => "static/image/howdy.png", :border => "0";
end
end
div :class => "grid_1" do end
div.logo! :class => "grid_2" do
a :href => '/' do
img :src => "static/image/logo.png", :border => "0";
end
end
div :class => "grid_1" do end
div.thanks! :class => "grid_2" do
a :href => '/thanks-yall' do
img :src => "static/image/thanks.png", :border => "0";
end
end
div :class => "grid_2" do end
end
end
end
end
def howdy
div.formWrapper! :class => "container_12" do
div.grid_12 do end
div.grid_12 do
text! "Howdy, y'all! In case you were hankerin' to know, Big Ole Texas is a StumpGrindin' Production.".upcase
br
br
end
div.grid_12 do
text! "We sure hope you enjoyed it, as there is more to come! But don't be a stranger, ya hear? Shoot us an e-mail at '[email protected]'.".upcase
end
div.grid_12 do
text! "Or, if you're one of them city-slicker types, you might reckon to check us out on ".upcase
a :href => "https://twitter.com/stumpgrindinc" do
"Twitter.".upcase
end
end
div.grid_12 do
br
text! "Want to know more about all things Texas? Check out ".upcase
a :href => "https://www.facebook.com/allthingstexan" do
"All Things Texan!".upcase
end
br
end
div.grid_12 do
text! "Y'all come back real soon, now, ya hear? ".upcase
br
end
div.grid_12 do end
end
end
def thanks
div.formWrapper! :class => "container_12" do
div.grid_12 do end
div.grid_12 do
text! "Woowee, folks! Hosting a website is TUFF business! That's why we wanted to give a quick holler to the kind folks down at Dotgeek!".upcase
br
end
div.grid_12 do
text! "So thanks, Dotgeek, for streamlining the development of this site (and giving us some hosting)!".upcase
br
end
div.grid_12 do
text! "We Texans aren't ones to take things lightly, so for your service to this great state, we've bestowed you the title of Honorary Texan's.".upcase
end
div.grid_12 do
a :href => "http://dotgeek.org" do
img.honorary! :src => 'static/image/honorary.png'
end
end
div.grid_12 do
"(Just don't get uppity like them yankee folk, ya hear now?!)".upcase
end
div.grid_12 do end
end
end
def bigole
div.formWrapper! :class => "container_12" do
div :class => 'wrapper' do
div.formLabel! :class => 'grid_6' do
div.text do
"Folks, there's no denying it.".upcase
end
div :style => "padding:8px;" do end
div.text do
span.biggest do
"Texas".upcase
end
span do
" is ".upcase
end
span.biggest do
"big".upcase
end
span do
"."
end
end
div :style => "padding:8px;" do end
div.text do
span do
"Ever wonder just ".upcase
end
span.bigger do
"how".upcase
end
span do
" big".upcase
end
end
div.text do
"Big Ole Texas is?".upcase
end
div.text do
"Enter a country or US state".upcase
end
div.text do
"and see for yerself!".upcase
end
end
div.formItem! :class => 'grid_6' do
form.bigole! :action => R(BigOle), :method => 'post' do
input.region! :name => 'search_region', :type => 'text', :style => "font-size:30px; font-weight:bold; text-align:center;"; br
input.submit! :type => 'image', :src => 'static/image/getsome.png', :alt => 'Gitcha Sum TX!'
end
end
end
end
end
def gitsum
div_name = ''
script :type => "text/javascript", :src => 'static/js/rmHeader.js'
def trunc(dubble)
if dubble.include? '.'
chunks = dubble.split('.')
"#{chunks[0]}.#{chunks[1][0..1]}"
else
dubble
end
end
case @search_result["bigger"]
when "true"
div_name = 'smaller'
index = rand(@texas_smaller.size)
phrase = @texas_smaller[index]
ratio = trunc(@search_result["ratio"])
else
div_name = 'bigger'
index = rand(@texas_bigger.size)
phrase = @texas_bigger[index]
ratio = trunc((1.0/@search_result["ratio"].to_f).to_s)
end
if @search_term.include?("Texas")
t = ["Yippee! Searching for Texas tickles my fancy and makes me wanna do my fiddlin' jig!","Texas is Texas, ya nitwit! Shouldnt you be searching for something fresh, cowboy?"]
phrase = t.shuffle.first
ratio = 1.0
else
temp = @search_term.downcase.gsub(/\s+/,"")
if temp == "yourmom" or temp == "yomom" or temp == "mom" or temp == "yomomma" or temp == "yomama"
t = ["Yeeeeehawww! Ain't no steer in our cattle yard as big as yo momma!",
"Error: numeric overflow attempting to calculate size of 'Your Mom'.",
"Shucks, partner, Texas is big, but it ain't that big! Yo momma is SIZE_TERM larger than Texas."]
phrase = t.shuffle.first
end
end
if phrase.include?("SIZE_TERM_INC")
t = rand()
if t < 0.25
phrase = phrase.gsub("SIZE_TERM_INC","100X")
elsif t < 0.5
phrase = phrase.gsub("SIZE_TERM_INC","200X")
else
phrase = phrase.gsub("SIZE_TERM_INC","300X")
end
end
if phrase.include?("BIG_RANDOM")
big_random = rand(712345897) + rand(99999999) + 100100100
phrase = phrase.gsub("BIG_RANDOM", big_random.to_s)
end
processed = phrase.gsub("REGION_TERM",@search_term).gsub("SIZE_TERM","#{ratio}X")
div.postFormWrapper! :class => "container_12" do
div.phrase! :class => 'grid_12' do
processed.to_s.upcase
end
if ratio != 1.0
div.wrapper do
div.grid_6.raptor_texas! :style => "padding-top: 25px;" do
img.r_t! :align => "middle", :src => 'static/image/raptor.png'
end
div.grid_6.raptor_other! :style => "padding-top: 25px;" do
img.r_o! :align => "middle", :src => 'static/image/raptor.png'
end
end
div.wrapper do
div.grid_6 :style => "padding-top: 25px;" do
"TEXAS"
end
div.grid_6 :style => "padding-top: 25px;" do
@search_term.upcase
end
end
div.wrapper :style => "padding-top: 45px; padding-bottom: 10px;" do
div.formLabel! :class => 'grid_6', :style => "padding-top: 20px;" do
"Have another go, partner?".upcase
end
div.formItem! :style => "position: relative; bottom:0px;" do
form :action => R(BigOle), :method => 'post' do
input.grid_4 :name => 'search_region', :type => 'text', :style => "font-size:30px; font-weight:bold; text-align:center;margin-top:45px;"; br
input.grid_2 :style => "height:9%;padding-top:42px;", :type => 'image', :src => 'static/image/getsome.png', :alt => 'Gitcha Sum TX!'
end
end
end
else
div.wrapper :style => "padding-top: 45px; padding-bottom: 10px;" do
div.formLabel! :class => 'grid_6', :style => "padding-top: 20px;" do
"Have another go, partner?".upcase
end
div.formItem! :style => "position: relative; bottom:0px;" do
form :action => R(BigOle), :method => 'post' do
input.grid_4 :name => 'search_region', :type => 'text', :style => "font-size:30px; font-weight:bold; text-align:center;margin-top:45px;"; br
input.grid_2 :style => "height:9%; padding-top:15px;", :type => 'image', :src => 'static/image/getsome.png', :alt => 'Gitcha Sum TX!'
end
end
end
div.svgAnchor! :class => 'grid_12' do end
end
end
div.percentageContainer! :style => "display: none; visibility: hidden;" do
ratio
end
div.isBigger! :style => "display: none; visibility: hidden;" do
div_name
end
if ratio == 1.0
script :type => "text/javascript", :src => 'static/js/SVG.js'
else
script :type => "text/javascript", :src => 'static/js/explodeImg.js'
end
end
def fail
script :type => "text/javascript", :src => 'static/js/rmHeader.js'
if @search_term.to_s.empty?
text = [
"Hold yer horses! Just because we talk slow doesn't mean we are slow. Gotta enter something there first.",
"Shucks! Ya gotta enter something, ya pinhead!"
]
t = rand
if t < 0.25 or t > 0.65
phrase = text[0]
else
phrase = text[1]
end
else
unless @texas_notfound
@texas_notfound = []
File.open('data/texas-notfound.data','r').each_line do |line|
@texas_notfound << line.chomp("\n")
end
end
index = rand(@texas_notfound.size)
phrase = @texas_notfound[index]
if phrase.include?("REGION_TERM")
phrase = phrase.gsub("REGION_TERM", @search_term.to_s)
end
end
div.postFormWrapper! :class => "container_12" do
div.phrase! :class => "grid_12" do phrase.upcase end
div.svgAnchor! :class => "grid_12" do end
div.wrapper :style => "padding-top: 45px; padding-bottom: 10px;" do
div.formLabel! :class => 'grid_6', :style => "padding-top: 20px;" do
"Have another go, partner?".upcase
end
div.formItem! :style => "position: relative; bottom:0px;" do
form :action => R(BigOle), :method => 'post' do
input.grid_4 :name => 'search_region', :type => 'text', :style => "font-size:30px; font-weight:bold; text-align:center;margin-top:45px;"; br
input.grid_2 :style => "height:9%;", :type => 'image', :src => 'static/image/getsome.png', :alt => 'Gitcha Sum TX!'
end
end
end
end
div.percentageContainer! :style => "display: none; visibility: hidden;" do
"1.00"
end
script :type => "text/javascript", :src => 'static/js/SVG.js'
end
def fouroh
div.formWrapper! :class => "container_12" do
div.grid_12 do
"Shucks, partner! I reckon you're diggin' for clams in a goddamned cornfield! We ain't got no pages here!".upcase
end
end
end
def fiveoh
div.formWrapper! :class => "container_12" do
div.grid_12 do
"Well, I'll be damned! Looks like our scientists done messed up...".upcase
end
end
end
def fiveohoh
div.formWrapper! :class => "container_12" do
div.grid_12 do
"Hooowee! This interweb voodoo is corn-fusing me! Looks like we log-jammed our pipes!".upcase
end
end
end
end
=begin
module Texas::Models
class Region < Base; end
class Bigger < Base; end
class Smaller < Base; end
class NotFound < Base; end
class CreateTheBasics < V 1.0
def self.up
create_table Region.table_name, :force => true do |t|
t.column :id, :integer, :null => false
t.column :name, :string, :limit => 255, :null => false
t.column :area, :string, :limit => 32, :null => false
t.column :ratio, :string, :limit => 32, :null => false
t.column :bigger, :integer, :null => false
t.column :notes, :string, :limit => 1000, :null => false
end
YAML::load_file('data/base.yaml').each do |k,v|
bigger = (v["bigger"] == "true")? 1 : 0
Region.create(:name => k.to_s, :area => v["size"].to_s,
:ratio => v["ratio"].to_s, :bigger => bigger, :notes => v["notes"].to_s)
end
#
create_table Bigger.table_name, :force => true do |t|
t.column :id, :integer, :null => false
t.column :text, :string, :limit => 300, :null => false
end
File.open('data/texas-bigger.data','r').each_line do |line|
Bigger.create :text => line.chomp("\n")
end
#
create_table Smaller.table_name, :force => true do |t|
t.column :id, :integer, :null => false
t.column :text, :string, :limit => 300, :null => false
end
File.open('data/texas-smaller.data','r').each_line do |line|
Smaller.create :text => line.chomp("\n")
end
#
create_table NotFound.table_name, :force => true do |t|
t.column :id, :integer, :null => false
t.column :text, :string, :limit => 300, :null => false
end
File.open('data/texas-notfound.data','r').each_line do |line|
NotFound.create :text => line.chomp("\n")
end
end
def self.down
drop_table Region.table_name
drop_table Bigger.table_name
drop_table Smaller.table_name
drop_table NotFound.table_name
end
end
end
=end