This repository has been archived by the owner on Jan 15, 2022. It is now read-only.
/
site.rb
66 lines (55 loc) · 1.64 KB
/
site.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
#!/usr/bin/env ruby
require 'bundler/setup'
require 'erb'
require 'haml'
require 'json'
require 'pony'
require 'rubygems'
require 'sinatra'
require 'sinatra/bundles'
require 'sinatra/content_for2'
stylesheet_bundle(:all, 'main')
enable(:compress_bundles) # => false (compress CSS and Javascript using packr and rainpress)
enable(:cache_bundles) # => false (set caching headers)
get '/' do
@page_title = 'Some Cool Site'
@override_css = true
haml 'index'.to_sym
end
# TODO: clean this up:
get '/', :agent => /iPhone/ do
@page_title = 'Some Cool Site - iPhone version'
@override_css = true
@meta = '<meta name="viewport" content="width = 320" />'
@iphone = true
erb 'index'.to_sym
end
error 404 do
haml :error, :layout => false
end
helpers do
GIT_REVISION = %x[git reflog -n1 | awk \'{print $1}\'].gsub( /\.\.\./, '' )
def cache_server
rand(2) + 1
end
def stylesheet_tag( path )
return "" unless path
path = path.match('^/stylesheets/') ? path : '/stylesheets/' + path
path = path.match('\.css$') ? path : path + '.css'
uri = :development ? path : "http://cache#{cache_server}.jm3.net#{path}"
"<link type=\"text/css\" href=\"#{uri}?#{GIT_REVISION.chomp}\" rel=\"stylesheet\" media=\"all\" />"
end
def img( uri )
return "" unless uri
"<img src=\"#{img_path(uri)}\" />"
end
def img_path( uri )
return "" unless uri
uri = uri.match('^/images/') ? uri : '/images/' + uri
:development ? uri : "http://cache#{cache_server}.jm3.net#{uri}"
end
# return backup if primary is blank /via Ryan Matsumura
def default(primary, secondary)
primary.strip.size > 0 ? primary : secondary
end
end