Sha256: e4fd176e666d999d270b6d2e11d811291b95771390ffd70940e55e19d017d04d

Contents?: true

Size: 1.61 KB

Versions: 9

Compression:

Stored size: 1.61 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
  engine :Slippers
  def index
    @tasks = []
    TodoList.original.each do |title, value|
      if value[:done]
        status = 'done'
        toggle = 'open'
      else
        status = 'not done'
        toggle = 'close'
      end
      @tasks << {:title => title, :status => status, :resource => title, :toggle => toggle}
    end
    @heading = "TodoList"
    #@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}
      redirect route('/', :title => title)
    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_referrer }

  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

9 entries across 9 versions & 2 rubygems

Version Path
starapor-slippers-0.0.5 examples/todolist/controller/main.rb
starapor-slippers-0.0.6 examples/todolist/controller/main.rb
starapor-slippers-0.0.8 examples/todolist/controller/main.rb
starapor-slippers-0.0.9 examples/todolist/controller/main.rb
slippers-0.0.14 examples/todolist/controller/main.rb
slippers-0.0.13 examples/todolist/controller/main.rb
slippers-0.0.12 examples/todolist/controller/main.rb
slippers-0.0.11 examples/todolist/controller/main.rb
slippers-0.0.10 examples/todolist/controller/main.rb