Skip to content

Commit

Permalink
changing week 2 examples to views
Browse files Browse the repository at this point in the history
  • Loading branch information
runemadsen committed Oct 23, 2012
1 parent 0cc8493 commit 2d7efd8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 37 deletions.
5 changes: 1 addition & 4 deletions examples/week2/first_route/app.rb
Expand Up @@ -2,10 +2,7 @@

# Main route - this is the form where we take the input
get '/' do
<<-HTML
This is an example of simple routes.
Check out this <a href='/~irs221/sinatra/same_route_twice/same_route'>route</a>
HTML
"This is an example of simple routes. Check out this <a href='/~irs221/sinatra/same_route_twice/same_route'>route</a>"
end

get '/same_route' do
Expand Down
7 changes: 1 addition & 6 deletions examples/week2/params/app.rb
Expand Up @@ -2,12 +2,7 @@

# Main route - this is the form where we take the input
get '/' do
<<-HTML
This is an example of simple routes.
Check out <a href='/~irs221/sinatra/url_params/route/1'>route 1</a> or
<a href='/~irs221/sinatra/url_params/route/2'>route 2</a> or
<a href='/~irs221/sinatra/url_params/route/4032467'>route 4032467</a>!
HTML
"This is an example of simple routes. Check out <a href='/~irs221/sinatra/url_params/route/1'>route 1</a> or <a href='/~irs221/sinatra/url_params/route/2'>route 2</a> or <a href='/~irs221/sinatra/url_params/route/4032467'>route 4032467</a>!"
end

get '/route/:id' do
Expand Down
6 changes: 1 addition & 5 deletions examples/week2/returning_something/app.rb
Expand Up @@ -2,11 +2,7 @@

# Main route - this is the form where we take the input
get '/' do
<<-HTML
This is an example of simple routes.
Check out the <a href='/~irs221/sinatra/returns_last_line/first_route'>first route</a> or
the <a href='/~irs221/sinatra/returns_last_line/second_route'>second route</a>
HTML
"This is an example of simple routes. Check out the <a href='/~irs221/sinatra/returns_last_line/first_route'>first route</a> or the <a href='/~irs221/sinatra/returns_last_line/second_route'>second route</a>"
end

# You can see this at http://itp.nyu.edu/~irs221/sinatra/returns_last_line/first_route
Expand Down
27 changes: 10 additions & 17 deletions examples/week2/route_conditionals/app.rb
@@ -1,30 +1,23 @@
require 'sinatra'

get '/' do
<<-HTML
<form action="http://itp.nyu.edu/~irs221/sinatra/conditionals/conditional_greeting" method="GET">
<p><label>Enter your name:</label> <input type="text" name="yourname" /></p>
<p><input type="submit" value="Go" /></p>
</form>
HTML
erb :form
end

get '/conditional_greeting' do
image_url = ""

@image_url = ""

if (params[:yourname] == "World")
image_url = "http://www.buddhanet.info/wbd/images/maps/WBD_world-map.jpg"
@image_url = "http://www.buddhanet.info/wbd/images/maps/WBD_world-map.jpg"
elsif (params[:yourname] == "Flower")
image_url = "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/White_and_yellow_flower.JPG/250px-White_and_yellow_flower.JPG"
@image_url = "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/White_and_yellow_flower.JPG/250px-White_and_yellow_flower.JPG"
elsif (params[:yourname] == "Ruxy" || params[:yourname] == "Cat")
image_url = "http://www.vectorsigma.co.uk/blog/wp-content/uploads/2011/07/cute_cat1.jpg"
@image_url = "http://www.vectorsigma.co.uk/blog/wp-content/uploads/2011/07/cute_cat1.jpg"
else
image_url = "http://tectabs.com/wp-content/uploads/2011/07/hello-1769.jpg"
@image_url = "http://tectabs.com/wp-content/uploads/2011/07/hello-1769.jpg"
end

<<-HTML
<p>Hi, #{params[:yourname]}!</p>
<img src="#{image_url}"/>
HTML


erb :result

end
4 changes: 4 additions & 0 deletions examples/week2/route_conditionals/views/form.erb
@@ -0,0 +1,4 @@
<form action="http://itp.nyu.edu/~irs221/sinatra/conditionals/conditional_greeting" method="GET">
<p><label>Enter your name:</label> <input type="text" name="yourname" /></p>
<p><input type="submit" value="Go" /></p>
</form>
2 changes: 2 additions & 0 deletions examples/week2/route_conditionals/views/result.erb
@@ -0,0 +1,2 @@
<p>Hi, #{params[:yourname]}!</p>
<img src="#{@image_url}"/>
6 changes: 1 addition & 5 deletions examples/week2/routes/app.rb
Expand Up @@ -2,11 +2,7 @@

# Main route - this is the form where we take the input
get '/' do
<<-HTML
This is an example of simple routes.
Check out the <a href='/~irs221/sinatra/simple_routes/first_route'>first route</a> or
the <a href='/~irs221/sinatra/simple_routes/second_route'>second route</a>
HTML
"This is an example of simple routes. Check out the <a href='/~irs221/sinatra/simple_routes/first_route'>first route</a> or the <a href='/~irs221/sinatra/simple_routes/second_route'>second route</a>"
end

# You can see this at http://itp.nyu.edu/~irs221/sinatra/simple_routes/first_route
Expand Down

0 comments on commit 2d7efd8

Please sign in to comment.