-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cakefile
151 lines (115 loc) · 3.75 KB
/
Cakefile
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
fs = require 'fs'
crypto = require 'crypto'
showdown = require 'showdown'
showdown.table = require './extensions/table.js'
flour = require 'flour'
get = (f) -> fs.readFileSync(f).toString()
put = (f, str) -> fs.writeFileSync(f, str)
converter = new showdown.converter extensions: [showdown.table]
docs =
get: (f) -> get "docs/#{f}.md"
text: (f) -> (docs.get f).replace /{{(\w+?)\.md}}/g, (m, f) -> docs.text f
html: (f) -> converter.makeHtml docs.text f
api_sections = (header) ->
html = API.map((id) ->
"""<section class="section-#{id}">#{docs.html id}</section>"""
).join "\n"
section = []
html = html.replace /<h(\d)\s*id="(\w+)">(.+)<\/h\1>/g, (match, weight, id, title) ->
section[weight-1] = title.replace(/[^\w\@]/g, '').toLowerCase()
id = section.slice(0, weight).join '-'
header parseInt(weight, 10), id, title
html = html.replace /⤳.*$/gm, (m) -> "<span>#{m}</span>"
return html
md5hash = (fileName) ->
contents = get fileName
return crypto.createHash('md5').update(contents).digest('hex')
# Config
# ===========
VERSION = require('./package.json').version;
API = [
'rye'
'data'
'query'
'collection'
'manipulation'
'style'
'event-emitter'
'dom-event-emitter'
'events'
'touch-events'
'request'
'util'
]
SAMPLES = [
'custom-dom-event-emitter'
'touch-events'
]
# Builds
# ===========
task 'build:docs', ->
menu = ''
content = api_sections (weight, id, title) ->
classAttr = ' class="module" ' if '@' in title
link = """<a href="##{id}"#{[classAttr]}>#{title}</a>"""
menu += "#{['', ' '][weight-1]}- #{link}\n" if weight <= 2
return """<h#{weight} id="#{id}">#{title}</h#{weight}>"""
menu = converter.makeHtml menu
output = (get 'template/index.html')
.replace('{{manifesto}}', docs.html 'manifesto')
.replace('{{cssHash}}', md5hash 'styles/main.css')
.replace('{{jsHash}}', md5hash 'scripts/main.js')
.replace('{{content}}', content)
.replace('{{menu}}', menu)
.replace(/{{version}}/g, VERSION)
put 'index.html', output
task 'build:readme', ->
content = ''
api_sections (weight, id, title) ->
if weight is 1
content += "\n### #{title}\n"
else
content += "- [`#{title}`](http://ryejs.com##{id})\n"
output = (get 'template/README.md')
.replace('{{about}}', docs.get 'about')
.replace('{{browsers}}', docs.get 'browsers')
.replace('{{content}}', content)
.replace(/{{version}}/g, VERSION)
put 'README.md', output
task 'build:samples', ->
menu = """
- [Documentation](../)
- [Samples](#)
""" + "\n"
content = SAMPLES.map((id) ->
html = get "samples/#{id}.html"
html = html.replace /<h1[^>]*>(.+)<\/h1>/, (match, title) ->
menu += " - [#{title}](##{id})\n"
"""<h1 id="#{id}">#{title}</h1>"""
"""<section class="section-#{id}">#{html}</section>"""
).join "\n"
menu = converter.makeHtml menu
output = (get 'template/samples.html')
.replace('{{content}}', content)
.replace('{{menu}}', menu)
.replace(/{{version}}/g, VERSION)
put 'samples/index.html', output
task 'build:less', ->
compile 'styles/base.less', 'styles/main.css'
# Build and watch
# ===========
task 'build', ->
invoke 'build:less'
invoke 'build:docs'
invoke 'build:readme'
invoke 'build:samples'
task 'watch', ->
invoke 'build'
watch 'styles/', -> invoke 'build:less'
watch [
'docs/'
'template/'
], ->
invoke 'build:docs'
invoke 'build:readme'
watch 'samples/', -> invoke 'build:samples'