Sha256: 8069fecccfc0b79db1c8abc111da4f4a0ae9bbe7ef85de2445bacc416b714959

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# * George Moschovitis  <gm@navel.gr>
# $Id: run.rb 267 2005-02-28 14:52:41Z gmosx $

require 'cgi'
require 'redcloth'
require 'yaml/store'
 
require 'nitro'; include N

# 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.

class Wiki < Component
  HP = 'HomePage'
  WIKI = YAML::Store.new('wiki.yml')

	def index
		request['p'] = HP 
		show	
	end
	
	def show
		p = request['p'].to_s
		o.h1(p)
		o.a(HP, :href => '/') unless p == HP 
		WIKI.transaction do
			if WIKI[p]
				o << RedCloth.new(WIKI[p]).to_html.gsub(/([A-Z]\w+){2}/) { "<a href='show?p=#$&'>#$&</a>" }
				o.a 'Edit', :href => "edit?p=#{p}"
			else
				o.p("No page #{p}. ").a('Create?', :href => "edit?p=#{p}")
			end
		end
	end

	def edit
		p = request['p'].to_s
		if c = request['c']
			WIKI.transaction { WIKI[p] = c.to_s } 
			redirect "show?p=#{p}"
		end
		WIKI.transaction do
			o.h1 "Editing #{p}"
			o.a('Show', :href => "show?p=#{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
end

require 'nitro/adapters/webrick'
Webrick.start(:dispatcher => Dispatcher.new(Wiki))

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.11.0 examples/why_wiki/run.rb