-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.coffee
120 lines (113 loc) · 3.26 KB
/
generate.coffee
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
110
111
112
113
114
115
116
117
118
119
120
yaml = require 'js-yaml'
Handlebars = require 'handlebars'
fs = require 'fs'
path = require 'path'
sheet = {}
groups = []
languages = {}
if process.argv.length > 2
generate_single_item = true
item = process.argv[2]
if item.startsWith 'src/'
item = item.substr 4
if item.endsWith '.yaml'
item = item.substr 0, item.length-5
list = [ {title: item, items: [item]} ]
else
list = yaml.safeLoad fs.readFileSync 'list.yaml', 'utf-8'
for group in list
items = []
groups.push title: group.title, items: items
for item in group.items
content = yaml.safeLoad fs.readFileSync "src/#{item}.yaml", 'utf-8'
key = path.basename item
items.push key
sheet[key] = content
for lang of content
continue if lang[0] is '_'
languages[lang] = 1
languages = Object.keys(languages).sort (a, b) ->
a = a.toLowerCase()
b = b.toLowerCase()
if a < b
return -1
if a > b
return 1
return 0
getSheetContent = (item, language, options) ->
cell_class = []
if language is '_title'
content.body = sheet[item]._title
content.note = sheet[item]._note
else
content = sheet[item][language]
if not content
content = body: 'Need to fill'
cell_class.push 'no_information'
else if not content.body
content.body = 'Not applicable\nto this language'
cell_class.push 'not_applicable'
if content.note
cell_class.push 'item_note'
content.cell_class = cell_class.join ' '
options.fn content
formatCode = (text, options) ->
result = ''
in_command = false
command = ''
for ch in text or ''
if in_command
if /\w+/.test ch
command += ch
else
if ch is '{'
result += "<span class='cmd_#{command}'>"
else if ch is '}'
result += '</span>'
else if ch is '\\'
result += '\\'
in_command = false
else
if ch is '\\'
in_command = true
command = ''
else if ch is '\n'
result += '<br>'
else if ch is ' '
result += ' '
else if ch is '&'
result += '&'
else if ch is '<'
result += '<'
else if ch is '>'
result += '>'
else
result += ch
new Handlebars.SafeString result
if generate_single_item
console.log "<div class='langsheet'>"
console.log ""
for language in languages
getSheetContent groups[0].items[0], language, fn: (content) ->
body = formatCode(content.body).string
type = 'info'
if content.cell_class.indexOf('not_applicable')>=0
type = 'warning'
console.log "<div class='panel panel-#{type}'>"
console.log " <div class='panel-heading'>#{language}</div>"
console.log " <div class='panel-body'>"
console.log " #{body}"
console.log " </div>"
if content.note
console.log " <div class='panel-footer'>"
console.log " #{content.note}"
console.log " </div>"
console.log "</div>"
console.log ""
console.log "</div>"
else
Handlebars.registerHelper 'getSheetContent', getSheetContent
Handlebars.registerHelper 'format', formatCode
template = require './template.handlebars'
genearated = template languages: languages, table_columns: languages.length+1, groups: groups
fs.writeFileSync './docs/index.html', genearated, 'utf-8'