Sha256: 3f726532e1b61d54b56625eee884098e3467bf90349f7fa1eb6c6b7af6f71bbf

Contents?: true

Size: 1.17 KB

Versions: 31

Compression:

Stored size: 1.17 KB

Contents

require 'innate'
require 'yaml/store'

STORE = YAML::Store.new('games.yaml')

def STORE.[](key) transaction{|s| super } end
def STORE.[]=(key, value) transaction{|s| super } end
def STORE.each(&block)
  YAML.load_file('games.yaml').sort_by{|k,v| -v }.each(&block)
end

STORE['Pacman'] = 1

class Games
  Innate.node('/')

  def index
    TEMPLATE
  end

  def create
    STORE[request[:name]] ||= 0 if request.post?

    redirect_referrer
  end

  def vote(name)
    STORE[name] += 1

    redirect_referrer
  end

  TEMPLATE = <<-'T'.strip
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Top Retro Games</title>
  </head>
  <body>
    <h1>Vote on your favorite Retro Game</h1>
    <form action="#{ r(:create) }" method="post">
      <input type="text" name="name" />
      <input type="submit" value="Add" />
    </form>
    <ol>
      <?r STORE.each do |name, votes| ?>
        <li>
          #{ a("Vote", r(:vote, u(name))) }
          #{ h "%5d => %s" % [votes, name] }
        </li>
      <?r end ?>
    </ol>
  </body>
</html>
  T
end

Innate.start

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
innate-2023.01.06 example/app/retro_games.rb
innate-2015.10.28 example/app/retro_games.rb
manveru-innate-2009.04.18 example/app/retro_games.rb
manveru-innate-2009.04 example/app/retro_games.rb
manveru-innate-2009.05 example/app/retro_games.rb
manveru-innate-2009.06.12 example/app/retro_games.rb
manveru-innate-2009.06 example/app/retro_games.rb
manveru-innate-2009.07 example/app/retro_games.rb
rjspotter-innate-2009.06.29 example/app/retro_games.rb
rjspotter-innate-2009.06.30 example/app/retro_games.rb
rjspotter-innate-2009.06.31 example/app/retro_games.rb
innate-2013.02.21 example/app/retro_games.rb
innate-2013.02 example/app/retro_games.rb
innate-2012.12 example/app/retro_games.rb
innate-2012.03 example/app/retro_games.rb
innate-2011.12 example/app/retro_games.rb
innate-2011.10 example/app/retro_games.rb
innate-2011.04 example/app/retro_games.rb
innate-2011.01 example/app/retro_games.rb
innate-2010.07 example/app/retro_games.rb