-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.rb
More file actions
executable file
·70 lines (57 loc) · 1.52 KB
/
app.rb
File metadata and controls
executable file
·70 lines (57 loc) · 1.52 KB
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
require 'bundler'
Bundler.require
require 'json'
require 'cfpropertylist'
require 'active_support/core_ext/array/conversions'
require './lib/powder'
module AssetHelpers
def asset_path(source)
"/assets/" + settings.sprockets.find_asset(source).digest_path
end
end
class App < Sinatra::Base
set :root, File.expand_path('../', __FILE__)
set :sprockets, Sprockets::Environment.new(root)
set :precompile, [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
set :assets_prefix, 'assets'
set :assets_path, File.join(root, 'public', assets_prefix)
configure do
sprockets.append_path(File.join(root, 'assets', 'stylesheets'))
sprockets.append_path(File.join(root, 'assets', 'javascripts'))
sprockets.append_path(File.join(root, 'assets', 'images'))
sprockets.context_class.instance_eval do
include AssetHelpers
end
end
helpers do
include AssetHelpers
end
["/", "/resorts/?", "/settings/?"].each do |path|
get path do
@states = Powder.states.to_json
@resorts = Powder.resorts.to_json
erb :index
end
end
get '/resorts.*' do
case params[:splat].first
when 'json'
Powder.resorts.to_json
when 'plist'
Powder.resorts.to_plist
when 'xml'
Powder.resorts.to_xml(:root => :resorts)
else
''
end
end
get '/resorts/json' do
Powder.resorts.to_json
end
get '/resorts/plist' do
Powder.resorts.to_plist
end
get '/resorts/xml' do
Powder.resorts.to_xml(:root => :resorts)
end
end