#!/usr/local/ruby-1.8.0/bin/ruby -w require 'cgi' require "amrita/template" include Amrita raise unless RUBY_VERSION >= '1.8.0' TITLE = 'Ruby - An Object Oriented Scripting Language : ' SLIDE_DIR = './slides/' LEFT_ARROW = 171.chr RIGHT_ARROW = 187.chr def stacktrace; %Q(#{$!}\n#{$!.backtrace.join("\n")}); end begin cgi = CGI.new action = cgi['action'] this = File.basename($0) content = nil action = 'show' if not action or action.empty? case action when /show/ n = cgi['n'].to_i slides = Dir['slides/*'].sort_by{|path| File.basename(path).to_i} n_slides = slides.size last = n_slides - 1 np = n > 0 ? n - 1 : 0 nn = n < last ? n + 1 : last index = Array.new(10,'.') index[(n * 10.0) / last] = n lines = IO.readlines "./slides/#{n}" lines.map!{|line| Amrita::SanitizedString[line]} heading = lines.shift data = { :title => "#{TITLE}:#{n} - #{heading}", :prev => a(:href => this + "?n=#{np}"){(LEFT_ARROW * 2) + ' prev'}, :next => a(:href => this + "?n=#{nn}"){'next ' + (RIGHT_ARROW * 2)}, :start => a(:href => this + "?n=0") {LEFT_ARROW}, :end => a(:href => this + "?n=#{last}") {RIGHT_ARROW}, :heading => heading, :list => lines, :index => e(:a, :href => this + "?action=list"){index.join}, :left_arrow => a(:href => this + "?n=0") {LEFT_ARROW}, } content = SHOW_TEMPLATE.expand '', data when /list/ slides = Dir['slides/*'].sort_by{|path| File.basename(path).to_i} list = [] slides.each do |slide| n = File.basename(slide) lines = IO.readlines "./slides/#{n}" lines.map!{|line| Amrita::SanitizedString[line]} heading = lines.shift n, heading = [n, heading].map{|s| e(:a, :href => this + "?n=#{n}"){s}} list << {:n => n, :heading => heading} end data = { :title => "#{TITLE}:#{action}", :list => list, } content = LIST_TEMPLATE.expand '', data else raise "INVALID ACTION #{action}" end puts "Content-type: text/html\r\n\r\n", content rescue Exception puts "Content-type: text/plain\r\n\r\n", stacktrace end BEGIN{ require 'amrita/template' SHOW_TEMPLATE = Amrita::TemplateText.new <<-txt
   


txt LIST_TEMPLATE = Amrita::TemplateText.new <<-txt
slideheading

txt }