Sha256: 47afaacf71d045e5c14b7fadde7b50f7d59036de7144b68d4ad1e334e5f70f7d

Contents?: true

Size: 1.6 KB

Versions: 33

Compression:

Stored size: 1.6 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 Pages < Ramaze::Controller
  map '/page'

  def create
    redirect_referer unless request.post?

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

  def save
    redirect_referer unless request.post?

    change "Updated Page '%s'" do |title, text|
      page = Page[:title => title]
      page.backup
      page.text = text
      page.version += 1
      page.save
      redirect MainController.r(:/, 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 MainController.r(:/, title)
  end

  private

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

    redirect MainController.r(redirect_to)
  end
end

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
ramaze-2023.01.06 examples/app/wikore/src/controller.rb
Pistos-ramaze-2009.06.12 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.04.22 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.04 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.05.08 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.05 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.06.04 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.06.12 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.06 examples/app/wikore/src/controller.rb
manveru-ramaze-2009.07 examples/app/wikore/src/controller.rb
rjspotter-ramaze-2009.06.29 examples/app/wikore/src/controller.rb
rjspotter-ramaze-2009.06.31 examples/app/wikore/src/controller.rb
ramaze-2012.12.08 examples/app/wikore/src/controller.rb
ramaze-2012.12.08b examples/app/wikore/src/controller.rb
ramaze-2012.04.14 examples/app/wikore/src/controller.rb
ramaze-2012.03.07 examples/app/wikore/src/controller.rb
ramaze-2011.12.28 examples/app/wikore/src/controller.rb
ramaze-2011.10.23 examples/app/wikore/src/controller.rb
ramaze-2011.07.25 examples/app/wikore/src/controller.rb
ramaze-2011.01.30 examples/app/wikore/src/controller.rb