Sha256: 977dd29fb278bf8a3be0db7400ed2b3eac702fe34a4b90b085ea45380c19b176

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# * George Moschovitis  <gm@navel.gr>
# $Id: run.rb 270 2005-03-07 17:52:16Z gmosx $

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

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

	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.12.0 examples/why_wiki/run.rb
nitro-0.13.0 examples/why_wiki/run.rb