-
Notifications
You must be signed in to change notification settings - Fork 2
/
Grunt-customtasks-reports.js
151 lines (74 loc) · 3.45 KB
/
Grunt-customtasks-reports.js
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
// ================================================================================
// Custom tasks -- reports
// ================================================================================
function defineCustomTasksReports(grunt) {
"use strict";
const path = require('path');
const LWjson2html = require("./src/data-conversion/LWjson2html"),
LWjson2htmlCards = require("./src/data-conversion/LWjson2htmlCards"),
LWjson2htmlSlides = require("./src/data-conversion/LWjson2htmlSlides"),
LWjson2odg = require("./src/data-conversion/LWjson2odg");
grunt.registerMultiTask('json2htmlList','Converts JSON to HTML',function(){
var html = grunt.file.read('templates/report.html');
for(var i = 0; i < this.files.length; i++){
var src = this.files[i].src;
for(var h = 0; h < src.length; h++){
var f = src[h];
var json = JSON.parse(grunt.file.read(f));
var tableString = LWjson2html(json);
var basename = path.basename(f,'.json');
var dest = path.join(this.files[i].dest,basename+'.html');
var report = html.replace('${wordListName}',basename);
grunt.file.write(dest, report.replace('${table}',tableString));
grunt.verbose.write(`Created ${dest}`);
}
}
});
grunt.registerMultiTask('json2htmlCardList','Converts JSON to HTML',function(){
var html = grunt.file.read('templates/cardlist-report.html');
for(var i = 0; i < this.files.length; i++){
var src = this.files[i].src;
for(var h = 0; h < src.length; h++){
var f = src[h];
var json = JSON.parse(grunt.file.read(f));
var cardsString = LWjson2htmlCards(json);
var basename = path.basename(f,'.json');
var dest = path.join(this.files[i].dest,basename+'.html');
var report = html.replace('${wordListName}',basename);
grunt.file.write(dest, report.replace('${cards}',cardsString));
grunt.verbose.write(`Created ${dest}`);
}
}
});
grunt.registerMultiTask('json2htmlSpelling','Converts JSON to a HTML presentation with spelling demo',function(){
var html = grunt.file.read('templates/learning-to-spell.html');
for(var i = 0; i < this.files.length; i++){
var src = this.files[i].src;
for(var h = 0; h < src.length; h++){
var f = src[h];
var json = JSON.parse(grunt.file.read(f));
var slides = LWjson2htmlSlides(json);
var dest = path.join(this.files[i].dest,path.basename(f,'.json')+'-spelling.html');
grunt.file.write(dest, html.replace('${slides}',slides));
grunt.verbose.write(`Created ${dest}`);
}
}
});
grunt.registerMultiTask('json2odg','Converts JSON to a LO Draw file',function(){
var drawText = grunt.file.read('templates/animals_pictures_and_words.fodg');
for(var i = 0; i < this.files.length; i++){
var src = this.files[i].src;
for(var h = 0; h < src.length; h++){
var f = src[h];
var json = JSON.parse(grunt.file.read(f));
var drawText = LWjson2odg(json,drawText);
var fname = path.basename(f,'.json')+'.fodg';
var dest = path.join(this.files[i].dest,fname);
drawText = drawText.replace('.filename.',fname);
grunt.file.write(dest, drawText);
grunt.verbose.write(`Created LibreOffice Draw document: ${dest}`);
}
}
});
};
module.exports = defineCustomTasksReports;