Sha256: 15ba836cfa489da97cbb5aee7602fbff8442aab8a07b38f41dde5defa9b087e8
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
# * George Moschovitis <gm@navel.gr> # $Id: run.rb 18 2005-04-15 09:17:08Z gmosx $ require 'cgi' require 'redcloth' require 'yaml/store' require 'nitro' require 'nitro/adapters/webrick' include Nitro # A simple wiki. A straight conversion of the redhanded.hobix.com # example. Original code by why the lucky stiff. # This is just a cool example, not the preffered way to write # Nitro applications. WIKI = YAML::Store.new('wiki.yml') class Wiki < Controller def index @p = 'Home' show end def show o.h1(@p) o.a('Home', :href => '/') unless @p == 'Home' WIKI.transaction do if WIKI[@p] o << RedCloth.new(WIKI[@p]).to_html.gsub(/([A-Z]\w+){2}/) { "<a href='/show/#$&'>#$&</a>" } o.a 'Edit', :href => "/edit/#@p" else o.p("No page #{p}. ").a('Create?', :href => "/edit/#@p") end end end action :show, :route => /show\/(.*)/, 'p' => String def edit if c = request['c'] WIKI.transaction { WIKI[@p] = c } redirect "/show/#@p" end WIKI.transaction do o.h1 "Editing #@p" o.a('Show', :href => "/show/#@p").br.br o.form(:method => 'post') { o.input :type => 'hidden', :name => 'p', :value => @p o.textarea WIKI[@p].to_s, :name => 'c', :style => 'width: 90%; height: 200px' o.br.br.submit } end end action :edit, :route => /edit\/(.*)/, 'p' => String end Webrick.start(:dispatcher => Dispatcher.new(Wiki))
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.16.0 | examples/why_wiki/run.rb |
nitro-0.17.0 | examples/why_wiki/run.rb |