Sha256: 3f8f686ca0547298d0eb5e6896ebe3e8213f67c7106ff34419083594fb3ea623

Contents?: true

Size: 1.62 KB

Versions: 20

Compression:

Stored size: 1.62 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

# Default url mappings are:
#  a controller called Main is mapped on the root of the site: /
#  a controller called Something is mapped on: /something
# If you want to override this, add a line like this inside the class
#  map '/otherurl'
# this will force the controller to be mounted on: /otherurl

class MainController < Ramaze::Controller

  def index
    @tasks = []
    TodoList.original.each do |title, value|
      if value[:done]
        status = 'done'
        toggle = A('Open Task', :href => Rs(:open, title))
      else
        status = 'not done'
        toggle = A('Close Task', :href => Rs(:close, title))
      end
      delete = A('Delete', :href => Rs(:delete, title))
      @tasks << [title, status, toggle, delete]
    end
    @tasks.sort!
  end

  def create
    if title = request['title']
      title.strip!
      if title.empty?
        failed("Please enter a title")
        redirect '/new'
      end
      TodoList[title] = {:done => false}
    end
  end

  def open title
    task_status title, false
  end

  def close title
    task_status title, true
  end

  def delete title
    TodoList.delete title
  end

  helper :aspect
  after(:create, :open, :close, :delete){ redirect(Rs()) unless redirected? }

  private

  def failed(message)
    flash[:error] = message
  end

  def task_status title, status
    unless task = TodoList[title]
      failed "No such Task: `#{title}'"
      redirect_referer
    end

    task[:done] = status
    TodoList[title] = task
  end
end

Version data entries

20 entries across 20 versions & 5 rubygems

Version Path
Pistos-ramaze-2008.09 examples/app/todolist/src/controller/main.rb
Pistos-ramaze-2008.12 examples/app/todolist/src/controller/main.rb
Pistos-ramaze-2009.01 examples/app/todolist/src/controller/main.rb
Pistos-ramaze-2009.02 examples/app/todolist/src/controller/main.rb
clivecrous-ramaze-0.3.9.5 examples/todolist/src/controller/main.rb
manveru-ramaze-2008.07 examples/app/todolist/src/controller/main.rb
manveru-ramaze-2008.08 examples/app/todolist/src/controller/main.rb
manveru-ramaze-2008.09 examples/app/todolist/src/controller/main.rb
manveru-ramaze-2008.10 examples/app/todolist/src/controller/main.rb
manveru-ramaze-2008.12 examples/app/todolist/src/controller/main.rb
manveru-ramaze-2009.01 examples/app/todolist/src/controller/main.rb
ptomato-ramaze-2009.02.1 examples/app/todolist/src/controller/main.rb
ptomato-ramaze-2009.02 examples/app/todolist/src/controller/main.rb
ramaze-0.3.9.1 examples/todolist/src/controller/main.rb
ramaze-2009.01 examples/app/todolist/src/controller/main.rb
ramaze-2008.11 examples/app/todolist/src/controller/main.rb
ramaze-2008.06 examples/app/todolist/src/controller/main.rb
ramaze-0.3.9 examples/todolist/src/controller/main.rb
ramaze-2009.02 examples/app/todolist/src/controller/main.rb
ramaze-2009.03 examples/app/todolist/src/controller/main.rb