Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/samples/class-book.rb
diff options
context:
space:
mode:
Diffstat (limited to 'samples/class-book.rb')
-rw-r--r--samples/class-book.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/samples/class-book.rb b/samples/class-book.rb
new file mode 100644
index 0000000..54b56ec
--- /dev/null
+++ b/samples/class-book.rb
@@ -0,0 +1,43 @@
+require 'yaml'
+
+class Book < Shoes
+ url '/', :index
+ url '/incidents/(\d+)', :incident
+
+ def index
+ incident(0)
+ end
+
+ INCIDENTS = YAML.load_file('class-book.yaml')
+
+ def table_of_contents
+ toc = []
+ INCIDENTS.each_with_index do |(title, story), i|
+ toc.push "(#{i + 1}) ",
+ link(title, :click => "/incidents/#{i}"),
+ " / "
+ end
+ toc.pop
+ span *toc
+ end
+
+ def incident(num)
+ num = num.to_i
+ background white
+ stack :margin => 10, :margin_left => 190, :margin_top => 20 do
+ banner "Incident", :margin => 4
+ para strong("No. #{num + 1}: #{INCIDENTS[num][0]}"), :margin => 4
+ end
+ flow :width => 180, :margin_left => 10, :margin_top => 0 do
+ para table_of_contents, :size => 8
+ end
+ stack :width => -190, :margin => 10, :margin_top => 0 do
+ INCIDENTS[num][1].split(/\n\n+/).each do |p|
+ para p
+ end
+ end
+ end
+end
+
+Shoes.app :width => 640, :height => 700,
+ :title => "Incidents, a Book"