Old high school files. Lessson notes/codes/projects etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
667 B

#!/usr/bin/ruby
require "sinatra"
def read_page(page)
begin
content = File.read("public/#{page}.html")
return content
rescue Exception => err
return ":("
end
end
get("/") do
return "Hello world!"
end
get("/page/:page") do
page = params[:page]
page = page.gsub(".", "")
content = read_page(page).gsub("$TITLE", page.upcase())
return content
end
get("/fruits") do
fruits = %w(Apple Orange Banana Grillkorv Varmkorv Frukt Hej)
listitems = ""
fruits.each do |fruit|
listitems += "<li>#{fruit}</li>"
end
response = "<ul>#{listitems}</ul>"
return response
end
get("/hello") do
return "Hello!"
end
get("/hej") do
redirect to("/hello")
end