-
Notifications
You must be signed in to change notification settings - Fork 0
/
risingcode.rb
executable file
·2117 lines (2033 loc) · 59.8 KB
/
risingcode.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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/ruby
require 'gserver'
require 'uri'
require 'rubygems'
require 'sqlite3'
require 'time'
require 'redcloth'
require 'digest/md5'
require 'drb'
require 'net/smtp'
require "active_record"
require "rack"
require "rack/session"
require "camping"
require 'camping/session'
require "rexml/document"
#import into this file
require '/home/application/acts_as_taggable'
require '/home/application/tag_list'
require '/home/application/slugalizer'
require '/home/application/lockfile'
Camping.goes :RisingCode
class DocumentationServer
URI = "druby://:2527"
SERVER = DRbObject.new(nil, URI)
def self.daemon (argv)
DRb.start_service(URI, self.new)
DRb.thread.join
end
def highlight(content, extension)
now = Digest::MD5.hexdigest(content)
input_buffer = "/tmp/#{now}.#{extension}"
output_buffer = "/tmp/#{now}.html"
cache_buffer = "/tmp/#{now}.cache"
now.to_s
unless File.exists?(cache_buffer)
input = File.new(input_buffer, "w")
input.write(content)
input.close
input = nil
worker = nil
IO.popen("-") { |worker|
if worker == nil
ready = nil
cmd = "/home/application/tohtml #{input_buffer} #{output_buffer}"
if system(cmd) then
begin
xml = File.open(output_buffer)
doc = REXML::Document.new(xml)
code_a = ""
doc.root.elements["//body"].each { |element|
code_a += element.to_s.gsub(" ", " ").gsub("\n", "")
}
cache_content = '<span class="snippet">' + code_a + '</span>'
cache = File.new(cache_buffer, 'w')
cache.write(cache_content)
cache.close
cache = nil
rescue => problem
cache_content = problem.inspect
cache = File.new(cache_buffer, 'w')
cache.write(cache_content)
cache.close
cache = nil
end
end
Process.exit!(0)
else
i = 0
until ready = IO.select([worker], nil, nil, 1) do
break if (i+=1) > 10
end
true
end
}
end
File.open(cache_buffer).readlines.join("").gsub("\n", "")
end
end
module RisingCode
module Models
$ARV_EXTRAS = %{
def self.V(n)
@final = [n, @final.to_f].max
m = (@migrations ||= [])
Class.new(ActiveRecord::Migration[6.0]) do
meta_def(:version) { n }
meta_def(:inherited) { |k| m << k }
end
end
def self.create_schema(opts = {})
opts[:assume] ||= 0
opts[:version] ||= @final
if @migrations
unless SchemaInfo.table_exists?
ActiveRecord::Schema.define do
create_table SchemaInfo.table_name do |t|
t.column :version, :float
end
end
end
si = SchemaInfo.all.first || SchemaInfo.new(:version => opts[:assume])
if si.version < opts[:version]
@migrations.sort_by { |m| m.version }.each do |k|
k.migrate(:up) if si.version < k.version and k.version <= opts[:version]
k.migrate(:down) if si.version > k.version and k.version > opts[:version]
end
si.update(:version => opts[:version])
end
end
end
}
module_eval $ARV_EXTRAS
end
end
module RedCloth::Formatters::HTML
def quote1(opts)
"'#{opts[:text]}'"
end
def quote2(opts)
"\"#{opts[:text]}\""
end
end
module RisingCodeTags
def hard_breaks; false; end
def css(opts)
content = opts[:text]
begin
h = DocumentationServer::SERVER.highlight(content, "css")
j = content.split("\n").length
return ::Markaby::Builder.new.table {
tr {
td.lines {
j.times { |i|
text("#{i}\n")
br
}
}
td {
text(h)
}
}
}
rescue Exception => problem
problem.inspect
end
end
def ruby(opts)
content = opts[:text]
begin
return DocumentationServer::SERVER.highlight(content, "rb")
rescue Exception => problem
problem.inspect
end
end
def rhtml(opts)
content = opts[:text]
begin
return DocumentationServer::SERVER.highlight(content, "rhtml")
rescue Exception => problem
problem.inspect
end
end
def javascript(opts)
content = opts[:text]
begin
return DocumentationServer::SERVER.highlight(content, "js")
rescue Exception => problem
problem.inspect
end
end
def cpp(opts)
content = opts[:text]
begin
return DocumentationServer::SERVER.highlight(content, "cpp")
rescue Exception => problem
problem.inspect
end
end
def objc(opts)
content = opts[:text]
begin
return DocumentationServer::SERVER.highlight(content, "mm")
rescue Exception => problem
problem.inspect
end
end
def java(opts)
content = opts[:text]
begin
return DocumentationServer::SERVER.highlight(content, "java")
rescue Exception => problem
problem.inspect
end
end
end
class String
def textilize
wang = RedCloth.new(self, [:no_span_caps, :filter_html]).extend(::RisingCodeTags).to_html
wang
end
end
module RisingCode
#set :secret, "sql"
include Camping::Session
def user_logged_in
@state.authenticated == true
#false
end
def log_user_out
@state.authenticated = false
true
end
def view_images
@viewing_images = true
yield
end
def without_layout
@no_layout = true
yield
end
def other_layout
@content_class = "other"
@no_header = true
@no_sidebar = true
yield
end
def no_sidebar
@no_sidebar
end
def no_header
@no_header
end
def viewing_images
@viewing_images
end
def administer (current_action = nil)
if user_logged_in then
@administering = true
@current_action = current_action
other_layout {
yield
}
else
redirect(R(Controllers::Login, nil))
end
end
def administering
@administering
end
def display_identifier
@@display_identifier
end
end
module RisingCode::Models
class Base
def Base.table_name_prefix
end
end
class CreateRisingCode < V 1
def self.up
create_table :sessions, :force => true do |t|
t.column :hashid, :string, :limit => 32
t.column :created_at, :datetime
t.column :ivars, :text
end
create_table :articles, :force => true do |t|
t.column :title, :string, :limit => 255, :null => false
t.column :permalink, :string, :limit => 255, :null => false
t.column :excerpt, :string, :limit => 255
t.column :body, :text
t.column :created_at, :datetime, :null => false
t.column :updated_at, :datetime, :null => false
t.column :published_on, :datetime, :defaut => nil
end
create_table :tags, :force => true do |t|
t.column :name, :string
end
create_table :taggings, :force => true do |t|
t.column :tag_id, :integer
t.column :taggable_id, :integer
t.column :taggable_type, :string
t.column :created_at, :datetime
end
create_table :images, :force => true do |t|
t.column :permalink, :string, :null => false
t.column :created_at, :datetime, :null => false
end
add_column :tags, :include_in_header, :boolean, :default => false
add_index :taggings, :tag_id
add_index :taggings, [:taggable_id, :taggable_type]
end
def self.down
drop_table :articles
drop_table :taggings
drop_table :tags
drop_table :images
end
end
class Article < Base
validates_presence_of :title, :if => :title
validates_uniqueness_of :title
validates_uniqueness_of :permalink
acts_as_taggable
has_many :comments
belongs_to :user
def autopop(title = nil)
self.title = title
self.published_on = Time.now
(1..100).each { |i|
self.permalink = "/#{published_on.year}/#{published_on.month}/#{published_on.day}/#{i.ordinalize}"
break if valid?
}
end
end
#class Image < Base
# def put_key (x_key, blob)
# get_key(x_key).put(blob, 'public-read')
# end
# def get_key (x_key)
# RightAws::S3::Key.create(@@bucket, self.permalink + "_" + x_key.to_s)
# end
# def public_link(x_key = :main)
# get_key(x_key).public_link
# end
# def thumb_permalink
# public_link(:thumb)
# end
# def full_permalink
# public_link(:main)
# end
# def icon_permalink
# public_link(:icon)
# end
# def x_put (blob)
# self.permalink = SecureRandom.hex.to_s if self.permalink.blank?
# imgs = Magick::Image.from_blob(blob)
# first = imgs.first
# case first.get_exif_by_entry("Orientation") && first["EXIF:Orientation"]
# when "6"
# first.rotate!(90)
# first["EXIF:Orientation"] = "1"
# when "3"
# first.rotate!(180)
# first["EXIF:Orientation"] = "1"
# when "8"
# first.rotate!(270)
# first["EXIF:Orientation"] = "1"
# end
# sizes = {
# :main => {:cols => 640, :rows => 480},
# :thumb => {:cols => 400},
# :icon => {:cols => 128}
# }.each { |x_key, size|
# geometry = if size[:rows] then
# "#{size[:cols]}x#{size[:rows]}>"
# else
# "#{size[:cols]}x"
# end
# first.change_geometry(geometry) { |cols, rows, img|
# put_key(x_key, img.resize(cols, rows).to_blob)
# }
# }
# end
#end
class Tagging < Base
belongs_to :tag
belongs_to :taggable, :polymorphic => true
def after_destroy
if Tag.destroy_unused and tag.taggings.count.zero? then
tag.destroy
end
end
end
class Tag < Base
has_many :taggings
validates_presence_of :name
validates_uniqueness_of :name
validates :name, :format => { :with => /\A[a-zA-Z0-9\-]+\z/, :message => "Only letters allowed" }
cattr_accessor :destroy_unused
self.destroy_unused = false
def self.find_or_create_with_like_by_name(name)
where("name LIKE ?", name).first || create(:name => name)
end
def ==(object)
super || (object.is_a?(Tag) && name == object.name)
end
def to_s
name
end
def count
read_attribute(:count).to_i
end
end
end
module RisingCode::Controllers
class Index < R('/', '/(articles)', '/([a-zA-Z0-9 ]+)/(\d*)', '/(\d+)/(\d+)/(\d+)', '/(\w+)/(\w+)/(\w+)/([\w-]+)')
def get(*args)
@limit = 5
@offset = 0
@use_page_navigation = false
@use_date_navigation = false
@tags = Tag.all #(true)
@active_tab = "risingcode"
if args.empty? then
@limit = 1
@current_action = :index
@permalink = "%"
@now = Time.now
@use_date_navigation = true
elsif args.length == 1 then
@articles = Article.order("published_on asc").all
@use_date_navigation = true
return render(:articles)
elsif args.length == 2 then
@permalink = "%"
@now = Time.now
@tag = args[0]
@page = args[1].to_i
@offset = (@page - 1) * @limit if @page > 0
@articles = Article.find_tagged_with(
@tag,
:limit => @limit,
:offset => @offset,
:conditions => ["permalink like ? and (date(published_on) <= ?)", @permalink, @now],
:order => "published_on desc")
@current_action = @tag.to_s.intern
@use_page_navigation = true
elsif args.length == 3 then
@permalink = "%"
@now = Date.parse(args.join("/"))
@limit = 99;
@use_date_navigation = true
else
@permalink = "/" + args.join("/")
@now = Time.now
@limit = 1
@use_date_navigation = true
end
@articles = Article.where("permalink like ? and (date(published_on) <= ? or ?)", @permalink, @now, user_logged_in).order("published_on desc") if @articles.nil?
#@old_ranger = Article.find(
# :first,
# :conditions => ["date(published_on) <= ? and id < ?", Time.now, @articles.last.id],
# :limit => @limit,
# :order => "published_on asc") if @articles.length > 0
#@new_ranger = Article.find(
# :first,
# :conditions => ["date(published_on) <= ? and id > ?", Time.now, @articles.first.id],
# :limit => @limit,
# :order => "published_on desc") if @articles.length > 0
#@single = @articles.length == 1
render :index
end
end
class Logout < R("/dashboard/logout")
def get
log_user_out
redirect R(Index)
end
end
class Contact < R("/contact")
def get
primes = []
state = Numeric.new
(10000..15000).each { |i|
(2..(Math.sqrt(i).ceil)).each { |thing|
state = 1
if (i.divmod(thing)[1] == 0)
state = 0
break
end
}
primes << i unless (state == 0)
}
random_primes = primes.sort_by { rand }
@state.contact_me_token = SecureRandom.hex.to_s
@state.authentication_token = "#{primes[0]}x#{primes[1]}"
@large_factor = primes[0] * primes[1]
render :contact
end
def post(*args)
#begin
#Lockfile.new('/home/application/db/lock') do
# sleep 5
if @input.agree_to_tos.nil? and @input.i_am_not_a_robot == @state.contact_me_token and @input.authentication_token == @state.authentication_token then
@state.contact_me_token = SecureRandom.hex.to_s
##Net::SMTP.start('smtp.gmail.com', 25) do |smtp|
##smtp = Net::SMTP.new('aspmx.l.google.com', 25)
##smtp = Net::SMTP.new('smtp.gmail.com', 587)
#smtp = Net::SMTP.new('gmail-smtp-in.l.google.com', 25)
#smtp.enable_starttls
#smtp.enable_starttls_auto
#smtp.start('risingcode.com') do
# #smtp.mailfrom('[email protected]')
# #smtp.rcptto('[email protected]')
# smtp.send_message("From: [email protected]\r\nTo: [email protected]\r\nSubject: Contact Form Submission\r\n\r\n#{@input.inspect}", "[email protected]", "[email protected]")
#end
other_layout {
exit(1)
return render :thanks
}
else
@state.contact_me_token = SecureRandom.hex.to_s
return "<a href=\"#{R(Contact)}\">try again</a>"
end
#end
#rescue => problem
# return "really, don't do that #{problem.class} #{problem.inspect} #{problem}"
#end
end
end
class About < R('/about')
def get
@title = "Jon Bardin lives in the Land of the Rising Code"
@tags = Tag.where(:include_in_header => true)
@active_tab = "about"
render :about
end
end
class Resume < R('/about/resume')
def get
@tags = Tag.where(:include_in_header => true)
@active_tab = "about"
render :resume
end
end
class Login < R("/dashboard/login(.*)")
def get(*args)
other_layout {
render :login
}
end
def post(*args)
if @input.identity_url == ENV['SECRET_PASSWORD'] then #TODO: !!! real security !!!
@state.authenticated = true
return redirect(R(Dashboard))
else
raise "wtf"
end
end
end
class Dashboard < R("/dashboard")
def get
administer {
render :dashboard
}
end
end
=begin
class Images < R('/imagery')
def get (*args)
if args.length == 0 then
view_images {
@tags = Tag.find_all_by_include_in_header(true)
@active_tab = "risingcode"
@images = Image.find(:all, :order => "created_at desc")
render :images
}
else
args.inspect
end
end
end
class BookmarksByTag < R('/bookmarks/tagged/([a-zA-Z0-9\-]+)', '/bookmarks/tagged/([a-zA-Z0-9\-]+)/([0-9]+)')
def get (tag, page = nil)
@tag = tag
@tags = Tag.find_all_by_include_in_header(true)
@active_tab = "bookmarks"
raise "bookmarks model needs impl"
@bookmarks = Delicious::Bookmarks.all(0, 99999)
@bookmarks_for_tag = []
@bookmarks.each { |date, bookmarks|
bookmarks.each { |bookmark|
@bookmarks_for_tag << bookmark if (bookmark["tag"].include?(tag) or bookmark["href"].include?(tag))
}
}
@title = "Bookmarks tagged #{@tag}"
@page = page
if @page then
@offset = 10 * @page.to_i
else
@offset = 0
end
render :bookmarks_by_tag
end
end
class Bookmarks < R('/bookmarks', '/bookmarks/(\d+)/(\d+)/(\d+)')
def get (*args)
@tags = Tag.find_all_by_include_in_header(true)
@active_tab = "bookmarks"
return render :coming_soon
raise "bookmarks model needs impl"
@bookmarks = Delicious::Bookmarks.all(0, 99999)
@bookmarks_for_today = nil
@bookmarks_for_tomorrow = nil
@bookmarks_for_yesterday = nil
@days = @bookmarks.keys.sort
@index = nil
case args.length
when 0
@today = Time.now
until @index = @days.index(@today.strftime("%Y-%m-%d")) do
@today = @today - 24.hours
end
return redirect(R(Bookmarks, @today.year, @today.month, @today.day))
when 3
@today = Date.parse(args.join("/"))
@index = @days.index(@today.strftime("%Y-%m-%d"))
end
if @index then
@bookmarks_for_today = @bookmarks[@today.strftime("%Y-%m-%d")]
if @days[@index+1] then
@tomorrow = Date.parse(@days[@index+1])
@bookmarks_for_tomorrow = @bookmarks[@tomorrow.strftime("%Y-%m-%d")]
end
if @days[@index-1] then
@yesterday = Date.parse(@days[@index-1])
@bookmarks_for_yesterday = @bookmarks[@yesterday.strftime("%Y-%m-%d")]
end
@s = ""
@s += (Date::DAYNAMES[@today.wday])
words = {}
word = nil
@bookmarks.each { |date, bookmarks|
bookmarks.each { |bookmark|
words_ = bookmark["excerpt"].split(/([^a-zA-Z0-9])/)
words_.each { |word|
word.gsub!(/([a-zA-Z0-9])\..*/, '\1')
word.gsub!(/([^a-zA-Z0-9])/, '')
word.downcase!
words[word] = 0 if words[word].nil?
words[word] += 1
}
}
}
flex = 0
@found = []
until (@found.length == 1) do
@bookmarks_for_today.each { |bookmark|
bookmark["excerpt"].split(/([^a-zA-Z0-9])/).sort_by { |word| word.length }.each { |word|
word.gsub!(/([a-zA-Z0-9])\..*/, '\1')
word.gsub!(/([^a-zA-Z0-9])/, '')
word.downcase!
next if word.length < 6
next if words[word] > 13
next if @found.include?(word)
@found << word
break
}
}
break if ((flex += 1) > 4)
end
@title = @found.slice(0, 4).collect { |word| word.en.present_participle }.join(", ")
render :bookmarks
else
redirect(R(Bookmarks))
end
end
end
=end
class RetrieveArticles < R("/dashboard/articles")
def get
administer {
@articles = Article.all
render :list_articles
}
end
def post
@input.article_ids.each { |article_id|
article = Article.find(article_id)
article.destroy
}
redirect(R(RetrieveArticles))
end
end
class RetrieveTags < R("/dashboard/tags")
def get
administer {
@tags = Tag.all
render :list_tags
}
end
def post
@input.tag_ids.each { |tag_id|
tag = Tag.find(tag_id)
tag.destroy
}
redirect(R(RetrieveTags))
end
end
class CreateOrUpdateTag < R('/dashboard/tag/(\d*)')
def get (tag_id)
administer {
unless tag_id.blank?
@tag = Tag.find_by_id(tag_id)
else
@tag = Tag.new
end
render :create_or_update_tag
}
end
def post (tag_id)
administer {
unless tag_id.blank?
@tag = Tag.find_by_id(tag_id)
else
@tag = Tag.new
end
@tag.name = @input.name
@tag.include_in_header = (@input.include_in_header.nil? ? false : true)
if @tag.save! then
redirect(R(CreateOrUpdateTag, @tag.id))
else
render :create_or_update_tag
end
}
end
end
class CreateOrUpdateArticle < R('/dashboard/article/(\d*)')
def get (article_id)
administer {
unless article_id.blank?
@article = Article.find(article_id)
else
@article = Article.new
@article.autopop
end
render :create_or_update_article
}
end
def post (article_id)
administer {
unless article_id.blank?
@article = Article.find(article_id)
else
@article = Article.new
end
@article.title = @input.title
@article.permalink = @input.permalink
@article.excerpt = @input.excerpt
@article.body = @input.body
@article.published_on = @input.published_on
@article.tag_list = @input.tag_list
redirect(CreateOrUpdateArticle, @article.id) if @article.save!
}
end
end
class RetrieveImages < R("/dashboard/images")
def get
administer {
@images = Image.find(:all)
render :list_images
}
end
def post
@input.image_ids.each { |image_id|
image = Image.find(image_id)
image.destroy
}
redirect(R(RetrieveImages))
end
end
class CreateOrUpdateImage < R('/dashboard/image/(\d*)')
def get (image_id)
administer {
unless image_id.blank?
@image = Image.find_by_id(image_id)
else
@image = Image.new
end
render :create_or_update_image
}
end
def post (image_id)
administer {
unless image_id.blank?
@image = Image.find_by_id(image_id)
else
@image = Image.new
end
unless @input.the_file.is_a?(String) then
@image.x_put(@input.the_file[:tempfile].read)
end
@image.save!
redirect(R(CreateOrUpdateImage, @image.id))
}
end
end
end
module RisingCode::Views
def index
div {
@articles.each_with_index { |article, i|
ul {
li {
h2 {
a(:href => article.permalink) {
text(article.title)
}
}
}
li {
h3 {
text(" on ")
text(article.published_on.strftime("%B %d %Y"))
text(" I wondered... ")
}
}
li {
h3 {
text("tagged: ")
article.tags.reverse.each_with_index { |tag, i|
text(",") if i > 0
a(:href => R(Index, tag.name, nil)) {
text(tag.name)
}
}
}
} if article.tags.length > 0
li {
if @single and not article.excerpt.blank? then
article.excerpt.textilize + article.body.textilize
elsif not @single and not article.excerpt.blank? then
article.excerpt.textilize
else
article.body.textilize
end
}
}
}
if @use_date_navigation and (@old_ranger or @new_ranger) then
h2 {
"More articles dated"
}
ul.rangers_list {
li {
a(:href => R(Index, @old_ranger.published_on.year, @old_ranger.published_on.month, @old_ranger.published_on.day)) {
@old_ranger.published_on.strftime("%B %d %Y")
}
} if @old_ranger
li {
a(:href => R(Index, @new_ranger.published_on.year, @new_ranger.published_on.month, @new_ranger.published_on.day)) {
@new_ranger.published_on.strftime("%B %d %Y")
}
} if @new_ranger
}
end
}
end
def thanks
div {
h1 {
"Thanks!"
}
p {
"I will try to get back to you as soon as possible..."
}
a(:href => R(Index)) {
"return to index"
}
}
end
def contact
form(:action => R(Contact), :method => :post) {
ul {
li {
label {
"Please State Your Name"
}
input(:id => "your_name", :name => "name", :type => "text", :disabled => :disabled)
}
li {
label {
"And Your Business"
}
textarea(:id => "token", :class => @large_factor, :name => "business", :rows => 10, :cols => 10, :disabled => :disabled) {}
}
li {
table {
if rand > 0.5 then
i_am_a_robot
i_am_not_a_robot
else
i_am_not_a_robot
i_am_a_robot
end
}
}
li {
input(:id => "gotime", :class => @state.contact_me_token, :type => "submit", :value => "please wait...", :disabled => :disabled)
span.wait! {
" I am authenticating your session, please allow this script to finish before submitting"
}
}
}
}
script(:src => "/javascripts/prototype.js", :type => "text/javascript") {
"//foo"
}
script(:src => "/javascripts/filter.js", :type => "text/javascript") {
"//foo"
}
end
def i_am_a_robot
tr {
td.shrink {
input(:id => "i_am_a_robot", :type => "checkbox", :name => "agree_to_tos", :disabled => :disabled)
}
td.puff {
label(:for => "i_am_a_robot") {
"You are a robot"
}
}
}
end
def i_am_not_a_robot
tr {
td.human!(:class => "shrink") {
}
td.puff {
label(:for => "i_am_not_a_robot") {
"You are <em>not</em> a robot"
}
}
}
end
def layout
if @no_layout then
self << yield
return