Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
what-munch
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.1
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem "sinatra"
gem 'pry'
28 changes: 28 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.2)
method_source (0.9.0)
mustermann (1.0.1)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rack (2.0.3)
rack-protection (2.0.0)
rack
sinatra (2.0.0)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.0)
tilt (~> 2.0)
tilt (2.0.8)

PLATFORMS
ruby

DEPENDENCIES
pry
sinatra

BUNDLED WITH
1.16.0
40 changes: 17 additions & 23 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require "sinatra"
require "sinatra/reloader"
require 'pry'

$munch = []

get "/" do
munch_markup
template
end

Expand All @@ -13,33 +12,28 @@
end

post "/" do
$munch << params
redirect "/"
end


def munch_markup
munch = []
$munch.each do |munch|
munch << "<div>#{ munch[:what] } $#{ munch[:cost] }</div>"
params.each do |key, value|
$munch << "<div>#{ key } $#{ value }</div>"
end
munch.join("<br>")
end

redirect "/"
end


def template
"
<html>
<title>WhatMunch App</title>
<body>
<form action='/' method='post'>
What: <input name='what'>
Cost: <input name='cost'>
<button type='submit'>add munch</button>
</form>
#{ $munch_markup }
</body>
<title>WhatMunch App</title>
<body>
<form action='/' method='post'>
What: <input name='what'>
Cost: <input name='cost'>
<button type='submit'>
add munch
</button>
</form>
#{ $munch.join('') }
</body>
</html>
"
end
end
7 changes: 7 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rubygems'
require 'bundler'

Bundler.require

require './my_sinatra_app'
run MySinatraApp