Sha256: 5c0cbf3337137362ffdec36544440b36b43c3ec8d9016cf279083cd92211c965

Contents?: true

Size: 1.61 KB

Versions: 27

Compression:

Stored size: 1.61 KB

Contents

class Ramaze::Controller
  Page = Model::Page
  OldPage = Model::OldPage
end

class MainController < Ramaze::Controller
  def index(title = 'Main', version = nil)
    query = {:title => title}
    query[:version] = version.to_i if version
    model = version ? OldPage : Page

    if page = model[query]
      @text, @version = page.text, page.version
    else
      @text = "No Page known as '#{title}'"
      @version = false
    end
  end
end

class PageController < Ramaze::Controller
  map '/page'

  helper :aspect

  def create
    change "Created Page '%s'" do |title, text|
      Page.create(:title => title, :text => text, :version => 1)
      redirect R(MainController, title)
    end
  end

  def save
    change "Updated Page '%s'" do |title, text|
      page = Page[:title => title]
      page.backup
      page.text = text
      page.version += 1
      page.save
      redirect R(MainController, title)
    end
  end

  def delete(title)
    page = Page[:title => title]
    page.backup
    page.delete
  end

  def rename(title, to)
    change("Renamed #{title} to '%s'", to) do |title, text|
      page = Page[:title => title]
      page.backup
      page.title = to
      page.version += 1
      page.save
    end
  end

  def revert(title)
    page = Page[:title => title]
    page.revert
    redirect R(MainController, title)
  end

  before :create, :save do
    redirect_referer unless request.post?
  end

  private

  def change(message, redirect_to = '/')
    if title = request['title'] and text = request['text']
      yield(title, text)
      message % title
    end

    redirect(R(MainController, redirect_to))
  end
end

Version data entries

27 entries across 27 versions & 5 rubygems

Version Path
Pistos-ramaze-2008.09 examples/app/wikore/src/controller.rb
Pistos-ramaze-2008.12 examples/app/wikore/src/controller.rb
Pistos-ramaze-2009.01 examples/app/wikore/src/controller.rb
Pistos-ramaze-2009.02 examples/app/wikore/src/controller.rb
Pistos-ramaze-2009.04.08 examples/app/wikore/src/controller.rb
clivecrous-ramaze-0.3.9.5 examples/wikore/src/controller.rb
manveru-ramaze-2008.07 examples/app/wikore/src/controller.rb
manveru-ramaze-2008.08 examples/app/wikore/src/controller.rb
manveru-ramaze-2008.09 examples/app/wikore/src/controller.rb
manveru-ramaze-2008.10 examples/app/wikore/src/controller.rb
manveru-ramaze-2008.12 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.01 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.04.01 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.04.08 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.04.18 examples/app/wikore/src/controller.rb
ptomato-ramaze-2009.02.1 examples/app/wikore/src/controller.rb
ptomato-ramaze-2009.02 examples/app/wikore/src/controller.rb
ramaze-0.3.5 examples/wikore/src/controller.rb
ramaze-0.3.0 examples/wikore/src/controller.rb
ramaze-0.2.1 examples/wikore/src/controller.rb