-
Notifications
You must be signed in to change notification settings - Fork 0
/
homepage.rb
72 lines (63 loc) · 1.75 KB
/
homepage.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
require 'sinatra'
require 'yaml'
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'info_source'
require 'newrelic_rpm'
#require 'sinatra_more'
#TODO work out the problem with sinatra_more and use content_tag in helpers
if production?
ENV['GEM_PATH'] = "#{ENV['HOME']}/gems:/usr/lib/ruby/gems/1.8"
ENV['GEM_HOME'] = "#{ENV['HOME']}/gems"
require 'rubygems' || Gem.clear_paths
end
conf = YAML::load_file('config.yml')
configure do
set :github_conf, conf[:github]
set :linkedin_conf, conf[:linkedin]
set :wwr_conf, conf[:wwr]
set :gild_conf, conf[:gild]
end
#class Application < Sinatra::Base
# register SinatraMore::MarkupPlugin
#end
get '/' do
erb :index
end
get '/info/:info_source' do
is = info_source_const(params[:info_source]).new
is.data
end
INFO_SOURCES = [:github, :linkedin, :wwr, :gild, :bio]
helpers do
def info_source_const(info_source)
name = "#{info_source.to_s.capitalize}Info"
constant = Object
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
def info_boxes
r = '<ul id="roundabout">'
INFO_SOURCES.each do |is|
r += "<li id=\"#{is}\" class=\"info_box\">"
r += info_box(is)
r += '</li>'
end
r += '</ul>'
r
end
def info_box(info_source)
unless INFO_SOURCES.include? info_source
raise "Invalid info source given"
end
is = info_source_const(info_source).new
res = "<div class=\"info_box_header\">"
res += "<span class=\"title\">#{is.title}</span>"
if is.profile_url
res += "<span class=\"profile_link\">#{is.profile_link}</span>"
end
res += "</div>"
res += "<div class=\"info_box_body\">"
res += erb :"info_sources/#{info_source}"
res += "</div>"
res
end
end