-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjijel_web.rb
60 lines (50 loc) · 948 Bytes
/
jijel_web.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
require 'rubygems'
require 'sinatra'
require 'haml'
require 'git'
class JijelWeb < Sinatra::Application
enable :sessions
set :haml, :format => :html5
set :environment, :development
before do
redirect '/repo' unless has_repo?
end
get '/' do
redirect '/sites'
end
get '/repo' do
haml :root
end
post '/repo' do
dir = params[:repo]
begin
FileUtils.rm_rf 'tmp'
git = Git.clone dir, "tmp/#{dir.split('/').last}"
raise if git.nil?
session[:repo] = "tmp/#{dir.split('/').last}"
redirect '/'
rescue Exception => e
puts e
@dne = true
haml :root
end
#if FileHelper.dir_exists? dir
# session[:root_dir] = dir
# redirect '/sites'
#else
# @dne = true
# haml :root
#end
end
get '/settings' do
haml :settings
end
post '/search' do
search_text = params[:search_text]
puts search_text
haml :search_results
end
def has_repo?
session[:repo] or request.url.include? 'repo'
end
end