File: start.rb

package info (click to toggle)
ruby-innate 2013.02.21-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 848 kB
  • ctags: 622
  • sloc: ruby: 4,340; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 798 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# The minimal _why wiki in Innate with ERB

%w[rubygems innate erb maruku yaml/store].each{|l| require(l) }

DB = YAML::Store.new('wiki.yaml') unless defined?(DB)

class Wiki
  Innate.node '/'
  layout 'wiki'
  provide :html, :engine => :ERB

  def index(page = 'Home')
    @page = page
    @text = 'foo'
    sync{
      @text = DB[page].to_s.dup
      @text.gsub!(/\[\[(.*?)\]\]/) do
        %(<a href="#{r($1)}" class="#{DB[$1] ? 'exists' : 'missing'}">#{h($1)}</a>)
      end
    }
  end

  def edit(page)
    @page = page
    @text = sync{ DB[page].to_s }
  end

  def save
    page, text = request[:page, :text]
    sync{ DB[page] = text } if request.post? and page and text

    redirect(r(page))
  end

  private

  def sync
    Innate.sync{ DB.transaction{ yield }}
  end
end

Innate.start