mirror of https://github.com/E-Almqvist/hsf
parent
0f013a6558
commit
fb64476b31
@ -0,0 +1,36 @@ |
||||
#!/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 |
@ -0,0 +1,3 @@ |
||||
<h1> Hej jag är en hemsida </h1> |
||||
<p>Texta hiodfhsdiof hiosdhf iosdhfiosdhiof</p> |
||||
<h2>$TITLE</h2> |
Loading…
Reference in new issue