-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_webserver.rb
executable file
·75 lines (62 loc) · 1.96 KB
/
local_webserver.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
73
74
75
#!/usr/bin/env ruby
# ruby local_webserver.rb
require 'rubygems'
require 'bundler/setup'
require 'sinatra/base'
require 'vegas'
require 'uglifier'
class MyApp < Sinatra::Base
helpers do
def get_file_content(file_name)
File.read(file_name)
end
def enviroment
if ENV.include?('ENVIROMENT')
return ENV['ENVIROMENT']
end
return 'development'
end
def production?
if enviroment == 'production'
return true
else
return false
end
end
def get_compressed_html
args = [
["-jar", "tools/htmlcompressor-1.5.1.jar"],
["html/BoldFace.html"]
]
command = "java #{args.flatten.join(' ')}"
output = `#{command}`
output.gsub!('"', "'")
end
end
get '/' do
content_type Rack::Mime.mime_type('.html'), :charset => 'utf-8'
get_file_content('BoldFaceStandalone.html')
end
get '/agirorn/BoldFace/master/build/BoldFace.html' do
content_type Rack::Mime.mime_type('.html'), :charset => 'utf-8'
get_file_content('html/BoldFace.html')
end
get '/agirorn/BoldFace/master/build/BoldFace.js' do
content_type Rack::Mime.mime_type('.js'), :charset => 'utf-8'
text = get_file_content('js/BoldFace.js')
html = get_compressed_html
new_html = 'BoldFace.html = ' + '"' + html + '";'
text.gsub!("BoldFace.html = '<div></div>';", new_html)
production? ? Uglifier.compile(text) : text
end
get '/agirorn/BoldFace/master/build/BoldFace.css' do
content_type Rack::Mime.mime_type('.css'), :charset => 'utf-8'
get_file_content('css/BoldFace.css')
end
get '/agirorn/BoldFace/master/build/googleWebFonts.js' do
content_type Rack::Mime.mime_type('.js'), :charset => 'utf-8'
text = production? ? get_file_content('js/googleWebFonts.js') : get_file_content('js/googleWebFonts_SMALL.js')
production? ? Uglifier.compile(text) : text
end
end
Vegas::Runner.new(MyApp, 'my_app', {:port => 9000})