forked from maccman/stylo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
61 lines (48 loc) · 1.55 KB
/
app.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
require 'rubygems'
require 'bundler'
require 'pathname'
require 'sinatra/json'
require 'sinatra/reloader'
Bundler.require
require 'sprockets/commonjs'
require 'stylus/tilt'
require 'stylus/import_processor'
module AssetHelpers
def asset_path(source)
'/assets/' + settings.sprockets.find_asset(source).digest_path
end
end
class App < Sinatra::Base
set :root, Pathname(File.expand_path('../', __FILE__))
set :raise_errors, true
set :show_exceptions, true
set :sprockets, Sprockets::Environment.new(root)
set :precompile, [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
configure do
sprockets.append_path(root.join('assets', 'javascripts'))
sprockets.append_path(root.join('assets', 'stylesheets'))
sprockets.append_path(root.join('assets', 'images'))
sprockets.append_path(root.join('vendor', 'assets', 'javascripts'))
sprockets.append_path(root.join('vendor', 'assets', 'stylesheets'))
sprockets.register_engine '.styl', Tilt::StylusTemplate
sprockets.register_preprocessor 'text/css', Stylus::ImportProcessor
Stylus.paths.concat sprockets.paths
sprockets.context_class.instance_eval do
include AssetHelpers
end
end
helpers Sinatra::JSON
helpers do
include AssetHelpers
def url(path)
base = "#{request.scheme}://#{request.env['HTTP_HOST']}"
base + path
end
end
# use Rack::Auth::Basic, "Protected Area" do |username, password|
# (username == 'dragon' && password == 'tamer')
# end
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end
end