forked from max-mapper/ftang
-
Notifications
You must be signed in to change notification settings - Fork 1
/
environment.rb
43 lines (34 loc) · 859 Bytes
/
environment.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
use Rack::Session::Cookie
MUSIC_DIR = "music"
NOT_A_SONG = /.jpe?g|.png|.gif|.DS_Store/i
configure do
set :views, "#{File.dirname(__FILE__)}/views"
set :sessions, true
LOGGER = Logger.new("log/sinatra.log")
end
helpers do
def logger; LOGGER; end
def base_dir;"public/#{MUSIC_DIR}";end
def partial(page, options={})
haml page, options.merge!(:layout => false)
end
def reset_session
env['rack.session'] = {}
end
def get_cover(artist, album)
Pow("#{base_dir}/#{artist}/#{album}").files.each do |file|
if file.extension =~ /jpe?g|png/i
return "/#{MUSIC_DIR}/#{artist}/#{album}/#{file.name}"
end
end
nil
end
def capture(*args)
args.each_with_index do |arg, i|
instance_variable_set("@#{arg}".to_sym, params[:captures][i])
end
end
end
not_found do
haml :"404"
end