-
Notifications
You must be signed in to change notification settings - Fork 5
/
application.rb
89 lines (69 loc) · 1.73 KB
/
application.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'rubygems'
require 'sinatra'
require './lib/no_www'
set :app_file, __FILE__
get '/' do
erb :calculator
end
get '/triangle/?' do
redirect '/', 301
end
get '/about' do
erb :about
end
get '/download' do
erb :download
end
get '/downloads/:file' do
redirect "https://s3-eu-west-1.amazonaws.com/cossincalc/offline/#{params[:file]}"
end
not_found do
erb :'errors/not_found'
end
error do
erb :'errors/unkown'
end
configure :production do
use NoWWW
end
helpers do
include Rack::Utils
alias_method :h, :escape_html
def spotlight(html)
@header_spotlight = html
end
def navigation_item(text, url, attributes = {})
attributes.merge!(:href => url)
attributes[:class] = merge_html_class(attributes[:class], 'active') if current_page?(url)
"<li><a#{html_attributes attributes}><span>#{text}</span></a></li>"
end
def html_attributes(attributes)
attributes.map { |name, value| %{ #{name}="#{h value}"} }.join
end
def merge_html_class(*classes)
classes.compact * ' '
end
def current_page?(url)
request.path_info == url
end
def include_stylesheet(path, attributes = {})
@html_head ||= ''
attributes.merge!(:rel => 'stylesheet', :href => "/stylesheets/#{path}.css", :type => "text/css")
@html_head << %{<link#{html_attributes attributes} />}
end
def include_javascript(*paths)
@javascripts ||= ''
@javascripts += paths.map { |p| ", '/scripts/#{p}.js'" }.join
end
def erb_partial(template)
erb(:"_#{template}", :layout => false)
end
def append_footer(html)
@page_footer ||= ''
@page_footer << html
end
def page_meta(title, description)
@page_title = "CosSinCalc · #{title}"
@meta_description = description
end
end