-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.rb
47 lines (42 loc) · 1.38 KB
/
server.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
require 'rubygems'
require 'active_support/all'
require 'bundler/setup'
require 'sinatra'
require 'sk_api_schema'
require 'haml'
require 'sinatra/partial'
get '/' do
@schemas = SK::Api::Schema.read_all('v1.0')
@sorted_schemas = sort_schemas_by_category(@schemas)
haml :index
end
get '/table' do
@schemas = SK::Api::Schema.read_all('v1.0')
@sorted_schemas = sort_schemas_by_category(@schemas)
haml :table
end
get '/schemas' do
content_type :json
SK::Api::Schema.read_all('v1.0').to_json
end
get '/changelog' do
@content = File.read(params[:topic] + ".md")
haml :changelog
end
# TODO enhance the schema itself to support such a descition on object level
def sort_schemas_by_category(schemas)
sorted_schemas=[]
categories = {
documents: %w(document invoice credit_note order estimate payment_reminder recurring line_item divider_item sub_total_item),
contacts: %w(contact address),
templates: %w(pdf_template email_template text_template export_template),
system: %w(company user language sub auth_permission),
supportive: %w(task tag email comment attachment export payment product),
accounting: %w(account account_entry account_billing),
}
categories.each do |cat, obj_types|
sorted_schemas << cat
sorted_schemas << schemas.select{|obj| obj_types.include?(obj[:title]) }.sort{|a,b| a[:title].humanize <=> b[:title].humanize }
end
sorted_schemas
end