-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
42 lines (33 loc) · 997 Bytes
/
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
require 'rubygems'
require 'sinatra/base'
module AppHelpers
SOURCE_FOLDER = 'app/coffee'
PATH = File.join(File.expand_path(File.dirname(__FILE__)), SOURCE_FOLDER)
def javascript_include_tag(*sources)
sources.map do |source|
unless source.include?('*')
script_template(source)
else
Dir[File.join(PATH, "#{source}.coffee")].map do |filename|
script_template(filename)
end
end
end.flatten.join
end
def script_template(filename)
filename = "/#{filename}.coffee" unless filename.include?(".coffee")
filename.gsub!(PATH, '')
"<script type='text/javascript' src='/js#{filename}'></script>"
end
def stylesheet_include_tag(filename)
"<link rel='stylesheet' type='text/css' href='/css/#{filename}.css'></link>"
end
end
class App < Sinatra::Base
helpers AppHelpers
set :root, File.dirname(__FILE__) + '/app'
set :public_folder, File.dirname(__FILE__) + '/public'
get '/' do
erb :index
end
end