-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
44 lines (34 loc) · 802 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
42
43
44
require 'sinatra'
require 'haml'
require 'better_errors'
Dir['./lib/**/*.rb'].each do |file|
require file
end
use BetterErrors::Middleware
BetterErrors.application_root = File.expand_path("..", __FILE__)
require File.dirname(__FILE__) + '/models/trad'
get '/' do
haml :edit
end
get '/trads' do
key = params[:k]
language = params[:l]
@trads = []
file = File.new(ENV['HOME'] + '/code/iadvize/inc/languages/fr/chatclient.inc.php', 'r')
while line = file.gets
if key.nil? or key.empty?
matches = /\$trad\['(.+)'\]\s*=\s*"(.+)";/.match line
else
matches = /\$trad\['(.*#{key}.*)'\]\s*=\s*"(.+)";/i.match line
end
if matches
trad = Trad.new
trad.key = matches[1]
trad.value = matches[2]
@trads << trad
end
end
file.close
content_type :json
@trads.to_json
end