-
Notifications
You must be signed in to change notification settings - Fork 2
/
knapsack.rb
56 lines (48 loc) · 984 Bytes
/
knapsack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'rubygems'
require 'open-uri'
require 'base64'
require 'vendor/hpricot-0.6/lib/hpricot.rb'
require 'vendor/sinatra/lib/sinatra.rb' unless defined?(Sinatra)
require 'models/resource'
require 'models/page'
require 'models/stylesheet'
get '/' do
if params[:url]
url = params[:url]
url = "http://#{url}" unless url.match("://")
@data = Resource.fetch_and_convert(url)
erb :result
else
erb :index
end
end
error do
request.env['sinatra.error'].to_s
end
use_in_file_templates!
__END__
@@ index
<html>
<head>
<title>Knapsack</title>
</head>
<body>
<h1>Knapsack</h1>
<p>
Enter the URL you want to store offline:
<form action="/" method="GET">
<input type="text" name="url" />
<input type="submit" value="Pack it" />
</form>
</p>
</body>
</html>
@@ result
<html>
<head>
<title>Loading...</title>
</head>
<body>
<script>location.href = "<%= @data %>";</script>
</body>
</html>