forked from defunkt/mustache-sinatra-example
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
101 lines (79 loc) · 2.33 KB
/
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
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
require 'sinatra/base'
require 'mustache/sinatra'
require 'cgi'
$: << "./"
class App < Sinatra::Base
register Mustache::Sinatra
require 'views/layout'
require 'views/document'
require 'views/listing'
require 'views/flist'
require 'views/fieldedit'
require 'mysql2'
def initialize
super
@db=Mysql2::Client.new(:host => ENV['DATABASE_HOST'], :username => 'root',
:password => ENV['MYSQL_DATABASE_PASSWORD'], :database => 'schema_documentation')
end
set :mustache, {
:views => 'views/',
:templates => 'templates/'
}
get '/' do
@title = "Mustache + Sinatra = Wonder"
mustache :index
end
get '/other' do
mustache :other
end
get '/reports/undocumented/tables/mmi' do
param={"table_schema"=>"mmi1"}
Views::Listing::have(
Views::Listing::data(@db, param) )
mustache :listing
end
post '/reports/undocumented/fields/*.*.*' do
schema=params[:splat][0]
table=params[:splat][1]
column=params[:splat][2]
key=CGI.escape("#{schema}.#{table}.#{column}")
backlink=CGI.escape("#{schema}.#{table}")
[email protected](schema)
[email protected](table)
[email protected](column)
[email protected](params[:notes])
[email protected](params[:status])
[email protected](params[:editable].to_s)
record = { "schema" => schema, "table" => table, "column" =>
column, "notes" => notes, "status" => status, "backlink" =>
backlink, "editable" => editable, "key" => key }
Views::Fieldedit::update(@db, record)
redirect "/reports/undocumented/fields/#{key}"
end
get '/reports/undocumented/fields/*.*.*' do
schema=params[:splat][0]
table=params[:splat][1]
column=params[:splat][2]
key=CGI.escape("#{schema}.#{table}.#{column}")
backlink=CGI.escape("#{schema}.#{table}")
data=Views::Fieldedit::row(@db, params)
data["backlink"]=backlink
Views::Fieldedit::have ( data )
mustache :fieldedit
end
get %r{/reports/undocumented/fields/([\w\s]+)\.([\w\s]+)} do
data=Views::Flist::rows(@db, params)
Views::Flist::have ( data )
mustache :flist
end
get '/document*' do
row = @db.query(
"select * from to_document" )
Views::Document::have ( row )
mustache :document
end
get '/nolayout' do
content_type 'text/plain'
mustache :nolayout, :layout => false
end
end