-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlprc.js
112 lines (95 loc) · 3.02 KB
/
lprc.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
module.exports = function (Folder, args) {
if (args.file.length === 0) {
args.file = ["project.md"];
}
if (!Folder.prototype.local) {
Folder.prototype.local = {};
}
require('litpro-jshint')(Folder, args);
Folder.prototype.local.gm = require('gm');
var pug = require('pug');
Folder.sync("pug" , function (code, args) {
options = args.join(",").trim();
if (options) {
options = JSON.parse(options);
} else {
options = {'pretty':true};
}
return pug.render(code, options);
});
var md = require('markdown-it')({
html:true,
linkify:true
});
Folder.prototype.local.md = md;
Folder.sync( "md", function (code, args) {
return md.render(code);
});
var cheerio = require('cheerio');
Folder.prototype.local.cheerio = cheerio;
Folder.sync( "cheerio" , function(code, args) {
var selector = args.shift();
var method = args.shift();
var n = args.length;
var $ = cheerio.load(code);
var el$ = $(selector);
el$[method].apply(el$, args);
return $.html();
});
Folder.sync( "replace" , function(code, args) {
var selector, replacement;
var n = args.length;
var $ = cheerio.load(code);
for (i = 0; i < n; i += 2) {
selector = args[i];
replacement = args[i+1];
$(selector).html(replacement);
}
return $.html();
});
Folder.sync("append", function (input, args) {
var $ = cheerio.load(args[0]);
$(args[1]).append(input);
return $.html();
});
Folder.sync("title", function (input, args) {
var $ = cheerio.load(input);
var title = $("article h2").text();
if (title) {
$("title").text("A&I "+ title);
}
return $.html();
});
Folder.sync("current", function (input, args) {
var $ = cheerio.load(input);
var links = $("[href='" + args[0] + "']");
links.addClass("current");
return $.html();
});
var postcss = require('postcss');
Folder.commands.postcss = function (input, args, name) {
var doc = this;
var pc = doc.plugins.postcss;
var cmds = [];
if ( (typeof input !== "string") || (input === '') ) {
doc.gcd.emit("text ready:" + name, input);
return;
}
args.forEach(function (el) {
if (typeof pc[el] === "function" ) {
cmds.push(pc[el]);
}
});
postcss(cmds).process(input).then(function (result) {
result.warnings().forEach(function (warn) {
doc.log(warn.toString());
});
doc.gcd.emit("text ready:" + name, result.css);
}).catch(function (error) {
doc.log(error.toString());
});
};
Folder.plugins.postcss = {
autoprefixer : require('autoprefixer')
};
};