-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcakefile
109 lines (96 loc) · 3.54 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
VERSION = '1.2'
r = require './lib/r.js'
fs = require 'fs'
task 'minify', minify = (callback) ->
console.log "minifying..."
options = {
baseUrl: "./js"
name: "main"
out: "build/script.js"
include: "../lib/require"
paths: {
'lib': '../lib',
'html': '../html',
text: '../lib/text',
cs: '../lib/cs',
'coffee-script': '../lib/coffee-script',
'backbone': '../lib/backbone',
'jquery': '../lib/jquery',
'underscore': '../lib/lodash'
},
shim: {
'lib/bootstrap.min.js': ['jquery'],
}
}
r.optimize options, ->
cssOptions = {
cssIn: "css/style.css"
out: "build/style.css"
optimizeCss: "standard"
}
r.optimize cssOptions, -> callback?()
task 'merge', merge = (free = false) ->
console.log "merging..."
raw = fs.readFileSync('index-raw.html').toString()
bootstrapCss = fs.readFileSync('css/bootstrap.min.css').toString()
localCss = fs.readFileSync('build/style.css').toString()
script = fs.readFileSync('build/script.js').toString()
storeUrl = if free then \
"http://www.teacherspayteachers.com/Product/Student-Report-Writer-basic-Report-writing-made-easy-1481711" \
else "http://www.teacherspayteachers.com/Product/Student-Report-Writer-full-Report-writing-made-easy-1481716"
script = script.replace "STORE_URL", storeUrl
out = raw.replace /<style><\/style>/, "<style>#{bootstrapCss}#{localCss}</style>"
parts = out.split "<script></script>"
out = parts[0] + "<script>" + script + "</script>" + parts[1]
fs.writeFileSync "build/report-writer#{if free then '-free' else ''}-#{VERSION}.html", out, encoding: 'UTF8'
fs.writeFileSync "build/report-writer#{if free then '-free' else ''}.html", out, encoding: 'UTF8'
task 'build', build = (callback) ->
parse()
minify ->
merge()
callback?()
task 'build-free', buildfree = (callback) ->
parse true
minify ->
merge true
callback?()
task 'build-all', ->
buildfree -> build()
task 'parse', parse = (free = false) ->
console.log "parsing..."
textContent = (rawText) ->
if rawText.indexOf('--') > -1
return rawText.substring(0, rawText.indexOf '--').trim()
return rawText.trim()
isExcluded = (text) -> if not free then false else text.indexOf("--ex") > -1
isIncluded = (text) -> if not free then true else text.indexOf("--in") > -1
raw = fs.readFileSync('raw-data.txt').toString().replace(/’/g, "'").split "\r\n"
json = []
lastCategory = undefined
for row in raw when row.length > 0
if row.match /^\d+\./
# we're looking at a category
numbers = row.split "."
current = json
done = false
for number in numbers when not done and parseInt(number) > 0
# traverse down the existing parents
if current[parseInt(number) - 1]?
parent = current[parseInt(number) - 1]
current = parent.content
else
# we found an index that doesn't exist yet, that's where this category goes
rawText = numbers[numbers.length - 1]
lastCategory = current[parseInt(number) - 1] =
text: textContent rawText
content: []
excluded: 0
mayHaveChildren: isIncluded(rawText) or ((parent?.mayHaveChildren ? true) and not isExcluded rawText)
done = true
else if isIncluded(row) or (lastCategory.mayHaveChildren and not isExcluded row)
lastCategory.content.push text: textContent row
else
lastCategory.excluded++
fs.writeFileSync 'data/texts.json', JSON.stringify json, encoding: 'UTF8'
task 'parse-free', ->
parse true