-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.rb
More file actions
executable file
·109 lines (89 loc) · 2.82 KB
/
server.rb
File metadata and controls
executable file
·109 lines (89 loc) · 2.82 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
require 'bundler/setup'
require 'sinatra'
require 'erb'
require 'sass'
require 'coffee-script'
require_relative 'lib/all'
require_relative 'lib/routes'
configure(:development) do |c|
require 'sinatra/reloader'
c.also_reload('lib/*.rb')
end
def group_name(group)
ROUTES[group.to_sym][0]
end
def test_name(group, test)
ROUTES[group.to_sym][1][test.to_sym]
end
before do
@title = "HTML5 Capability Tests"
@subtitle = ""
@show_back_link = false
@javascripts = %w{
/jquery/jquery-1.5.2.js
/jquery/jquery.json-2.2.js
/jquery/jquery.timers.js
/jquery/glMatrix-0.9.5.min.js
/javascripts/common.js
}
@stylesheets = []
@iphone = false
@additional_head_data = ""
instance_eval do
def page_title
@subtitle != "" ? "#{@title} :: #{@subtitle[1..-2]}" : @title
end
end
end
get '/', :agent => /(.*)/ do
@iphone = true if /iPhone/.match params[:agent].first
@test_groups = ROUTES
erb :"erb/index"
end
get '/tests/:group/:test', :agent => /(.*)/ do |group, test|
require_relative("controllers/#{group}_controller")
@controller = Object.const_get("#{group.camelcase}Controller").new(params)
@iphone = true if /iPhone/.match params[:agent].first
@title, @subtitle = test_name(group, test), "(#{group_name(group)})"
@show_back_link = true
@stylesheets << "/stylesheets/#{group}.css"
@javascripts << "/javascripts/#{group}/#{test}.js"
# TODO: How to instance eval methods by name?
@controller.send test if @controller.respond_to? test.to_sym
@controller.instance_variables.each do |var|
self.instance_variable_set(var, @controller.instance_variable_get(var))
end
erb :"erb/#{group}/#{test}"
end
post '/tests/:group/:test', :agent => /(.*)/ do |group, test|
require_relative("controllers/#{group}_controller")
@controller = Object.const_get("#{group.camelcase}Controller").new(params)
@iphone = true if /iPhone/.match params[:agent].first
@title, @subtitle = test_name(group, test), "(#{group_name(group)})"
@show_back_link = true
@stylesheets << "/stylesheets/#{group}.css"
@javascripts << "/javascripts/#{group}/#{test}.js"
# TODO: How to instance eval methods by name?
@controller.send test if @controller.respond_to? test.to_sym
@controller.instance_variables.each do |var|
self.instance_variable_set(var, @controller.instance_variable_get(var))
end
erb :"erb/#{group}/#{test}"
end
get '/stylesheets/:file.css' do |file|
scss :"scss/#{file}"
end
get '/javascripts/:file.js' do |file|
coffee :"coffee-script/#{file}"
end
get '/javascripts/:group/:test.js' do |group, test|
coffee :"coffee-script/#{group}/#{test}"
end
get '/javascripts_static/:file.js' do |file|
coffee :"coffee-script/#{file}"
end
get '/javascripts_static/:group/:test.js' do |group, test|
coffee :"coffee-script/#{group}/#{test}"
end