zhangdocs 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.bin/idoc.js +65 -0
  2. package/.github/FUNDING.yml +9 -0
  3. package/README.md +108 -0
  4. package/index.js +56 -0
  5. package/lib/build.js +126 -0
  6. package/lib/clean.js +43 -0
  7. package/lib/copy.js +215 -0
  8. package/lib/deploy.js +24 -0
  9. package/lib/file.js +148 -0
  10. package/lib/imgPath.js +20 -0
  11. package/lib/init.js +166 -0
  12. package/lib/menu_json.js +36 -0
  13. package/lib/menu_update.js +73 -0
  14. package/lib/nav.js +108 -0
  15. package/lib/pdf.js +66 -0
  16. package/lib/pk.json +13 -0
  17. package/lib/stylus.js +36 -0
  18. package/lib/theme.js +57 -0
  19. package/lib/toc.js +119 -0
  20. package/lib/watch.js +76 -0
  21. package/lib/whoami.js +23 -0
  22. package/package.json +41 -0
  23. package/theme/default/footer.ejs +3 -0
  24. package/theme/default/gitignore +22 -0
  25. package/theme/default/head.ejs +17 -0
  26. package/theme/default/header.ejs +34 -0
  27. package/theme/default/layout.ejs +16 -0
  28. package/theme/default/source/css/_partial/head_nav.styl +239 -0
  29. package/theme/default/source/css/_partial/highlight.styl +103 -0
  30. package/theme/default/source/css/_partial/markdown.styl +121 -0
  31. package/theme/default/source/css/_partial/reset.styl +101 -0
  32. package/theme/default/source/css/_partial/variables.styl +10 -0
  33. package/theme/default/source/css/main.styl +156 -0
  34. package/theme/default/source/img/forkgithub.png +0 -0
  35. package/theme/doc/footer.ejs +25 -0
  36. package/theme/doc/gitignore +22 -0
  37. package/theme/doc/head.ejs +17 -0
  38. package/theme/doc/header.ejs +34 -0
  39. package/theme/doc/layout.ejs +16 -0
  40. package/theme/doc/source/css/_partial/head_nav.styl +239 -0
  41. package/theme/doc/source/css/_partial/highlight.styl +103 -0
  42. package/theme/doc/source/css/_partial/markdown.styl +121 -0
  43. package/theme/doc/source/css/_partial/reset.styl +101 -0
  44. package/theme/doc/source/css/_partial/variables.styl +10 -0
  45. package/theme/doc/source/css/main.styl +164 -0
  46. package/theme/doc/source/img/forkgithub.png +0 -0
  47. package/theme/handbook/footer.ejs +3 -0
  48. package/theme/handbook/gitignore +22 -0
  49. package/theme/handbook/head.ejs +10 -0
  50. package/theme/handbook/header.ejs +14 -0
  51. package/theme/handbook/layout.ejs +15 -0
  52. package/theme/handbook/source/css/_partial/highlight.styl +103 -0
  53. package/theme/handbook/source/css/_partial/markdown.styl +120 -0
  54. package/theme/handbook/source/css/_partial/reset.styl +101 -0
  55. package/theme/handbook/source/css/_partial/variables.styl +9 -0
  56. package/theme/handbook/source/css/main.styl +175 -0
  57. package/theme/handbook/source/img/background.png +0 -0
  58. package/theme/handbook/source/img/forkgithub.png +0 -0
  59. package/theme/resume/footer.ejs +2 -0
  60. package/theme/resume/gitignore +22 -0
  61. package/theme/resume/head.ejs +16 -0
  62. package/theme/resume/layout.ejs +27 -0
  63. package/theme/resume/source/css/_partial/highlight.styl +103 -0
  64. package/theme/resume/source/css/_partial/markdown.styl +137 -0
  65. package/theme/resume/source/css/_partial/reset.styl +101 -0
  66. package/theme/resume/source/css/_partial/variables.styl +10 -0
  67. package/theme/resume/source/css/main.styl +50 -0
  68. package/theme/resume/source/js/jquery.2.1.4.min.js +5 -0
  69. package/theme/resume/source/js/pdfmake.js +17 -0
  70. package/theme/resume/source/js/vfs_fonts.js +1 -0
package/lib/file.js ADDED
@@ -0,0 +1,148 @@
1
+ var fs = require('fs');
2
+ var path = require('path');
3
+ var _ejs = require('ejs');
4
+ var _ = require('underscore');
5
+
6
+ var file = module.exports = {
7
+ mkdirs:mkdirs,
8
+ exists:exists,
9
+ read:read,
10
+ write:write,
11
+ ejs:ejs,
12
+ isDir:isDir,
13
+ isFile:isFile,
14
+ readMDSync:readMDSync,
15
+ readMDJSONSync:readMDJSONSync,
16
+ mkdirsSync:mkdirsSync,
17
+ currentDir:currentDir,
18
+ currentFile:currentFile,
19
+ relativePath:relativePath
20
+ };
21
+ //判断是否存在这个方法
22
+ if(!String.repeat ){
23
+ //创建 repeat 方法: 重复复制字符串
24
+ String.prototype.repeat = function(num){
25
+ return new Array(isNaN(num)? 1 : ++num).join(this);
26
+ //创建元素值为空、个数为重复次数+1的数组,用字符串自身做为分隔符连接起来,返回连接后的值。
27
+ }
28
+ }
29
+ // 返回相对路径
30
+ // from 文件绝对路径
31
+ // to 指定到目录的相对目录
32
+ function relativePath(from,to){
33
+ return path.relative(from,to).replace(/\\/g,'/').replace(/\.\.$/g,'');
34
+ }
35
+
36
+ // 波浪号的绝对路径
37
+ function tildePath (string) {
38
+ if (string.substr(0,1) === '~')
39
+ string = process.env.HOME + string.substr(1);
40
+ return path.resolve(string)
41
+ }
42
+
43
+ // 同步循环创建所有目录 resolvePath
44
+ function mkdirsSync(dirpath, mode) {
45
+ if(fs.existsSync(dirpath)){
46
+ return true;
47
+ }else{
48
+ if(mkdirsSync(path.dirname(dirpath), mode)){
49
+ fs.mkdirSync(dirpath, mode);
50
+ return true;
51
+ }
52
+ }
53
+ };
54
+ // 异步循环创建所有目录
55
+ function mkdirs(dirpath, mode, callback) {
56
+ //Call the standard fs.mkdir
57
+ fs.mkdir(dirpath, mode, function(error) {
58
+ //When it fail in this way, do the custom steps
59
+ if (error && error.errno === 34) {
60
+ //Create all the parents recursively
61
+ !exists(path.dirname(dirpath))&&mkdirs(path.dirname(dirpath), mode, callback);
62
+ //And then the directory
63
+ !exists(dirpath)&&mkdirs(dirpath, mode, callback);
64
+ }
65
+ //Manually run the callback since we used our own callback to do all these
66
+ !error&&callback && callback(error);
67
+ });
68
+ };
69
+ //读取文件内容,路径不存在返回空
70
+ function read(filepath) {
71
+ return fs.readFileSync(filepath, 'utf8');
72
+ };
73
+
74
+ //返回 MD 所有路径的 Array
75
+ function readMDSync(filepath, ret){
76
+ var ret = ret || [],
77
+ files = fs.readdirSync(filepath);
78
+ for (var i = 0; i < files.length; i++) {
79
+ if(isDir(filepath + files[i])) readMDSync(filepath+files[i] + '/', ret);
80
+ else if(/\.(md)$/.test(files[i])) {
81
+ ret.push(filepath + files[i]);
82
+ }
83
+ }
84
+ return ret;
85
+ }
86
+
87
+ //返回 MD JSON,路径拆分
88
+ function readMDJSONSync(filepath){
89
+ var arr = [],_json,files = fs.readdirSync(filepath);
90
+ for (var i = 0; i < files.length; i++) {
91
+ if(isDir(filepath+files[i])) {
92
+ _json = {};
93
+ _json[files[i]]=readMDJSONSync(filepath+files[i]+'/');
94
+ arr.push(_json)
95
+ }else if(/\.(md)$/.test(files[i])){
96
+ arr.push(files[i])
97
+ }
98
+ };
99
+ return arr;
100
+ }
101
+
102
+ //写文件
103
+ function write(filepath, content) {
104
+ mkdirsSync(path.dirname(filepath));
105
+ return fs.writeFileSync(filepath, content);
106
+ };
107
+
108
+ //模板输出 HTML 代码
109
+ function ejs(_path,data){
110
+
111
+ return _ejs.compile(file.read(_path), {filename: _path})(data);
112
+ return _ejs.render(file.read(_path),_.extend({filename: _path},data) );
113
+ }
114
+
115
+ //检查指定路径的文件或者目录是否存在
116
+ function exists(_path){
117
+ return fs.existsSync(_path);
118
+ }
119
+
120
+ //判断是不是文件
121
+ function isFile(_path){
122
+ return exists(_path) && fs.statSync(_path).isFile();
123
+ }
124
+
125
+ //判断是不是目录
126
+ function isDir(_path){
127
+ return exists(_path) && fs.statSync(_path).isDirectory();
128
+ }
129
+
130
+ //获取路径下面的所有dir
131
+ function currentDir(_path){
132
+ if(!exists(_path)) return [];
133
+ return _.filter(fs.readdirSync(_path),function(dirname){
134
+ return isDir(_path+dirname);
135
+ })
136
+ }
137
+ //获取路径下面的所有file
138
+ function currentFile(_path){
139
+ if(!exists(_path)) return [];
140
+ return _.filter(fs.readdirSync(_path),function(dirname){
141
+ return isFile(_path+dirname);
142
+ })
143
+ }
144
+
145
+ //获取目录下所有md文件的相对路径
146
+ function getMdPaths(_path){
147
+
148
+ }
package/lib/imgPath.js ADDED
@@ -0,0 +1,20 @@
1
+ var cheerio = require('cheerio');
2
+ var file = require("./file");
3
+ var log = console.log;
4
+
5
+ module.exports = imgPath
6
+
7
+ function imgPath(str,_path){
8
+
9
+ var $ = cheerio.load(str),
10
+ imgsrc = '';
11
+
12
+ $('img').each(function(i, e) {
13
+ imgsrc = $(e).attr('src');
14
+ if(!/^(http:\/\/|https:\/\/)/.test(imgsrc))
15
+ $(e).attr('src',file.relativePath(_path,process.cwd()) + imgsrc );
16
+ });
17
+
18
+ // 返回HTML
19
+ return $.html();
20
+ }
package/lib/init.js ADDED
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env node
2
+ var fs = require('fs');
3
+ var path = require('path');
4
+ var inquirer = require('inquirer');
5
+ var semver = require('semver');
6
+ var _ = require('underscore');
7
+ var color = require('colors-cli')
8
+ var copy = require('./copy');
9
+ var file = require('./file');
10
+ var theme = require('./theme');
11
+ var menu_json = require('./menu_json');
12
+ var log = console.log;
13
+
14
+ var template = path.dirname(__dirname);
15
+ var default_package = {}
16
+ /**
17
+ * 这里执行 init 任务
18
+ */
19
+ function runTask(commander){
20
+ if(commander.Create) file.mkdirsSync(commander.Create,0777);
21
+ inquirer.prompt([
22
+ {
23
+ type: 'input',
24
+ name: 'name',
25
+ message: 'Package name',
26
+ validate: function(input) {
27
+ //检测只准输入小写字母,数字,横线或者英文句号
28
+ if (/^[A-z][A-z0-9\-\.]*$/.test(input)) {
29
+ return true;
30
+ }
31
+ return 'Must be only lowercase letters, numbers, dashes or dots, and start with lowercase letter.';
32
+ }
33
+ },{
34
+ type: 'input',
35
+ name: 'version',
36
+ message: 'Version',
37
+ default: '1.0.0',
38
+ validate: function(input){
39
+ //分析版本是否正确或者null
40
+ if (!semver.valid(input)) {
41
+ return 'Must be a valid semantic version (semver.org).';
42
+ }
43
+ return true;
44
+ }
45
+ },{
46
+ message: 'Description',
47
+ name: 'description'
48
+ },{
49
+ type: "input",
50
+ name: 'keywords',
51
+ message: 'keywords'
52
+ },{
53
+ type: "list",
54
+ name: 'licenses',
55
+ message: 'Licenses',
56
+ default: ["MIT"],
57
+ choices: ["MIT", "Apache", "GPL", "Artistic", "BSD", "Affero", "LGPL", "EPL", "LGPL", "MPL"]
58
+ },{
59
+ type: "list",
60
+ name: "idoctheme",
61
+ message: "Choose a theme.",
62
+ choices: theme.themeList()
63
+ },{
64
+ message: 'Author',
65
+ name: 'author',
66
+ //获取我的git上的名字和邮箱
67
+ default: require('./whoami')
68
+ }
69
+ ]).then(function(answers){
70
+ if(typeof(answers) === "string") answers = JSON.parse(answers);
71
+
72
+ var pk = require('./pk.json');
73
+ var todir = ''
74
+ //关键词、关键字
75
+ answers.keywords = answers.keywords.split(',');
76
+ answers.idoc = {}
77
+ // console.log("该行代码所在的目录::",__dirname);
78
+ // console.log("返回一个路径的目录名称::",path.dirname(__dirname));
79
+ // console.log("命令传进来的目录::",commander.Create);
80
+ // console.log("当前目录名字::",path.basename(process.cwd()));
81
+ // console.log("当前目录::",process.cwd());
82
+ //指定生成的目录位置
83
+ if(commander.Create){
84
+ todir = commander.Create;
85
+ }else{
86
+ //记录当前目录位置
87
+ todir = process.cwd();
88
+ }
89
+
90
+ // 处理指定目录路径
91
+ if(!/\/$/.test(todir)) todir = todir + '/';
92
+
93
+ // 记录皮肤名字
94
+ if(answers.idoctheme){
95
+ answers.idoc.theme = answers.idoctheme;
96
+ delete answers.idoctheme;
97
+ }
98
+
99
+ //需要生成的md文件路径
100
+ if(commander.init){
101
+ var mdurl = path.normalize(todir + '/md');
102
+ // 判断md 目录存在不生成目录
103
+ if( !file.exists(mdurl) ) file.mkdirsSync(mdurl,0777);
104
+
105
+ if(commander.args.length>0){
106
+ // 判断是否指定某个目录里面 md 拷贝到当前项目目录下
107
+ commander.args.forEach(function(item,idx){
108
+ copy(path.resolve(item),todir+'md/',{
109
+ filter:function(_file){
110
+ if(/\.(md)$/.test(_file)) return true;
111
+ else false;
112
+ }
113
+ },function(err,_file){
114
+ if(err) return console.log(err);
115
+ // console.log("复制成功!:",_file);
116
+ })
117
+ })
118
+ }
119
+
120
+ //移动根目录的md文件到md目录中,并解决冲突
121
+ _.filter(file.currentFile(todir),function(_filename){
122
+ if(/README\.(md)$/.test(_filename))return false;
123
+ return /\.(md)$/.test(_filename)
124
+ }).forEach(function(_fname){
125
+ var pt = todir+'md/'+_fname;
126
+ var _nname = "";
127
+ if(file.exists(pt)) _nname = path.basename(pt, '.md') + parseInt(Math.random()*1000000) + '.md';
128
+ else _nname = _fname;
129
+
130
+ //复制到指定目录更改名字
131
+ fs.renameSync(todir+_fname,todir+'md/'+_nname);
132
+ })
133
+
134
+ //递归获取 md 下面所有的md文件 返回json
135
+ answers.idoc.md = menu_json(todir + 'md/');
136
+ }
137
+
138
+ //package.json合并输出
139
+ default_package = _.extend(pk,answers);
140
+
141
+ // 生成目录
142
+ file.write(todir + 'package.json',JSON.stringify(default_package, null, 4));
143
+
144
+ // 皮肤路径
145
+ var themeurl = template + '/theme/' + default_package.idoc.theme;
146
+
147
+ // 初始化到指定目录或者当前目录
148
+ var todir = default_package.idoc.todir?default_package.idoc.todir:__dirname;
149
+
150
+ log()
151
+ log(color.green('Initialization is successful! Please run "idoc build" command!'));
152
+ log()
153
+
154
+ })
155
+ return;
156
+ }
157
+
158
+ function init(commander){
159
+ if(fs.existsSync(template + '/theme/default/')){
160
+ runTask(commander);
161
+ }else{
162
+ log(color.red("Initialization failed!"));
163
+ }
164
+ }
165
+
166
+ module.exports = init;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 获取某文件夹下的所有 `md` 文件的一个 json 数据
3
+ */
4
+
5
+ var _ = require('underscore');
6
+ var file = require('./file');
7
+
8
+ module.exports = menu_json
9
+
10
+
11
+ function menu_json(_path){
12
+ //_path = todir + 'md/'
13
+ //递归获取 md 下面所有的md文件
14
+ var files,mdArr = file.readMDJSONSync(_path);
15
+
16
+ //获取当前目录下的所有 md 文件
17
+ files = file.currentFile(_path).map(function(elem, index) {
18
+ if(/\.(md)$/.test(elem)) return elem;
19
+ });
20
+ // 去掉不存在的空或者 null | undefined 的元素
21
+ files = _.compact(files);
22
+
23
+ //如果当前目录下没有文件(非文件夹)自动生成 index.md (目录里面的除外)
24
+ //md 根目录必须有一个 md文件
25
+ if(mdArr.length <= 0 || files.length === 0){
26
+ file.write(_path + 'index.md','# idoc');
27
+ //添加到数组的第一个位置
28
+ mdArr.unshift('index.md');
29
+ }else{
30
+ // 将数组中的 md 移动到第一的位置 为默认生成index.html
31
+ mdArr = _.without(mdArr,files[0]);
32
+ mdArr.unshift(files[0]);
33
+ }
34
+
35
+ return mdArr;
36
+ }
@@ -0,0 +1,73 @@
1
+ var path = require("path");
2
+ var menu_json = require('./menu_json');
3
+ var file = require('./file');
4
+
5
+
6
+ Array.prototype.remove = function(val) {
7
+ var index = this.indexOf(val);
8
+ if (index > -1) {
9
+ this.splice(index, 1);
10
+ }
11
+ };
12
+
13
+ /**
14
+ * [moveElement 合并两个数组以及JSON,保留老的数组中元素的位置]
15
+ * @param {[array]} _old [老的数组]
16
+ * @param {[array]} _new [新的数组]
17
+ * @return {[array]} [返回合并后的数组]
18
+ */
19
+ function moveElement(_old,_new){
20
+ var _o_a = _old, _n_a = _new;
21
+
22
+ for (var i = 0; i < _new.length; i++) {
23
+ var idx = _old.indexOf(_new[i]),
24
+ item = _new[i];
25
+
26
+ if(typeof(item) === 'string'){
27
+ if(idx === -1) _o_a.push(item);
28
+ }else{
29
+ var key = Object.keys(item)[0];
30
+ idx = null;
31
+ for (var a = 0; a < _old.length; a++) {
32
+ if(typeof(_old[a]) === 'object' && key === Object.keys(_old[a])[0]) idx = a;
33
+ };
34
+ if(idx){
35
+ item[key] = moveElement(_old[idx][key],item[key])
36
+ }else{
37
+ _o_a.push(item);
38
+ }
39
+ }
40
+ };
41
+
42
+ for (var i = 0; i < _old.length; i++) {
43
+ var idx = _new.indexOf(_old[i]),
44
+ item = _old[i];
45
+
46
+ if(typeof(item) === 'string'){
47
+ if(idx === -1) _o_a.remove(item)
48
+ }else{
49
+ var key = Object.keys(item)[0];
50
+ idx = null;
51
+ for (var a = 0; a < _new.length; a++) {
52
+ if(typeof(_new[a]) === 'object' && key === Object.keys(_new[a])[0]) idx = a;
53
+ };
54
+ if(!idx) _o_a.remove(item);
55
+ }
56
+ };
57
+ return _o_a
58
+ }
59
+
60
+ module.exports = function(){
61
+ var pkg = require(path.resolve('package.json'));
62
+ var mddata = pkg.idoc.md;
63
+
64
+ // 初始化菜单
65
+ if(pkg&&pkg.idoc&&pkg.idoc.md){
66
+ //递归获取 md 下面所有的md文件 返回json
67
+ var mdjson = menu_json(process.cwd() + '/md/');
68
+
69
+ pkg.idoc.md = moveElement(mddata,mdjson);
70
+ // 生成目录
71
+ file.write(process.cwd() + '/package.json',JSON.stringify(pkg, null, 4));
72
+ }
73
+ };
package/lib/nav.js ADDED
@@ -0,0 +1,108 @@
1
+ // 导航生成
2
+ var path = require('path')
3
+ var file = require('./file')
4
+ var log = console.log;
5
+
6
+ module.exports = nav;
7
+
8
+
9
+ /**
10
+ * arr 导航json
11
+ * current 当前页面的路径
12
+ * _url 所有url Array
13
+ * _sub 是否在回调的第一次,如果是为空
14
+ * floor 导航菜单是否为第一层
15
+ */
16
+
17
+ var indexname = '';
18
+ var floornum = 0;
19
+ function nav(arr, current, _url, floor, _sub){
20
+ var html = '<ul>',url ='';
21
+ for (var i = 0; i < arr.length; i++) {
22
+
23
+ var s = _sub ? _sub+'/'+arr[i]:arr[i];
24
+
25
+ if(current.replace(process.cwd()+'/md/','') === s){
26
+ html+='<li class="active">';
27
+ }else{
28
+ html+='<li>';
29
+ }
30
+
31
+ if(typeof arr[i] === 'object'){
32
+ for (var a in arr[i]) {
33
+ html+='<a href="#"><span></span>'+ a +'</a>';
34
+ html+=nav(arr[i][a],current,_url,floor, (_sub? _sub + '/' + a:a));
35
+ };
36
+ }else{
37
+
38
+ // 获取首页 markdown 的文件名
39
+ if(i ===0 && !_sub) indexname = arr[i];
40
+ // 返回相对路径
41
+ url = pathto(_url,
42
+ (_sub ? _sub+'/'+ arr[i] : arr[i]),
43
+ current,indexname,floor);
44
+
45
+ html+='<a href="'+ url +'">'+ arr[i].replace(/\.md/,'') +'</a>';
46
+ }
47
+ html+='</li>';
48
+ };
49
+ html += '</ul>';
50
+ return html;
51
+ }
52
+
53
+ // 导航菜单跳转的 path
54
+ // urlarr 所有url Array
55
+ // basename url元素
56
+ // current 当前页面的路径
57
+ // index 首页name
58
+ // floor 导航菜单目录层级
59
+ function pathto(urlarr,basename,current,index,floor){
60
+ // console.log("pathto:",'\n',urlarr,'\n',basename,'\n当前:',current,'\n首页:',index);
61
+ // console.log("basename::",basename);
62
+ var url = '',temp='';
63
+ for (var i = 0; i < urlarr.length; i++) {
64
+ if(urlarr[i].indexOf('md/'+basename) > -1) url = urlarr[i];
65
+ };
66
+ // 传进来的 url 处理
67
+ url = url.replace(process.cwd()+'/md',process.cwd() + '/html').replace(/\.md/,'.html');
68
+
69
+ // 当前md 的 url 处理
70
+ current = current.replace(process.cwd()+'/md',process.cwd() + '/html').replace(/\.md/,'.html');
71
+
72
+ // 跳转首页相对地址 特殊处理
73
+ var _index = index;
74
+
75
+ index = index.replace(/\.md/,'.html');
76
+ if(url==='') url = 'index.html'
77
+ if(_index === basename){
78
+ url = url.replace(process.cwd()+'/html/','').replace(index,'index.html')
79
+ }else{
80
+ url = url.replace(process.cwd()+'/','')
81
+ }
82
+
83
+ // 获取相对路径
84
+ temp = file.relativePath(current ,process.cwd());
85
+
86
+ // 首页跳转到其他页面的特殊处理
87
+ if(floor === 0) temp = "";
88
+
89
+ temp += url;
90
+ return temp;
91
+ }
92
+
93
+
94
+ // // 返回当前文件的url
95
+ // function pathto(urlarr,basename,index){
96
+ // var url = '';
97
+ // for (var i = 0; i < urlarr.length; i++) {
98
+ // if(urlarr[i].indexOf(basename) > -1) url = urlarr[i];
99
+ // };
100
+
101
+ // // 首页判断
102
+ // if(index === 0){
103
+ // url = '/index.html';
104
+ // }else{
105
+ // url = url.replace(process.cwd()+'/md','/html').replace(/\.md/,'.html');
106
+ // }
107
+ // return url;
108
+ // }
package/lib/pdf.js ADDED
@@ -0,0 +1,66 @@
1
+ // var phantom = require('phantom')
2
+ var fs = require('fs')
3
+
4
+ module.exports = pdf;
5
+
6
+ function pdf(commander){
7
+ var wkhtmltopdf = require('wkhtmltopdf');
8
+
9
+ // URL
10
+ // HTML
11
+ var ht = wkhtmltopdf('<h1>Test</h1><p>Hello world</p>')
12
+
13
+ // wkhtmltopdf(file.contents.toString(enc), options);
14
+
15
+ console.log(ht);
16
+
17
+
18
+ // var html5pdf = require("html5-to-pdf");
19
+ // var fs = require("fs");
20
+ // html5pdf({
21
+ // "cssPath" : process.cwd() + '/static/css/main.css'
22
+ // }).from(process.cwd() + '/index.html').to(process.cwd() + '/index.pdf', function () {
23
+ // console.log("Done")
24
+ // });
25
+
26
+
27
+
28
+
29
+ // var pdf = require('phantomjs-pdf');
30
+
31
+ // var options = {
32
+ // "html" : process.cwd() + '/index.html',
33
+ // "css" : process.cwd() + '/static/css/main.css',
34
+ // }
35
+
36
+ // pdf.convert(options, function(result) {
37
+
38
+ // /* Using a buffer and callback */
39
+ // result.toBuffer(function(returnedBuffer) {});
40
+
41
+ // /* Using a readable stream */
42
+ // var stream = result.toStream();
43
+
44
+ // /* Using the temp file path */
45
+ // var tmpPath = result.getTmpPath();
46
+
47
+ // /* Using the file writer and callback */
48
+ // result.toFile(process.cwd() + '/index.pdf', function() {});
49
+ // });
50
+
51
+
52
+
53
+
54
+
55
+ // require("jsreport").render({
56
+ // template: {
57
+ // content: "<h1>Hello world from </h1>",
58
+ // recipe: "html"
59
+ // },
60
+ // data: { name: "jsreport" }
61
+ // }).then(function(out) {
62
+ // //pipes plain text with Hello world from jsreport
63
+ // out.stream.pipe(out);
64
+ // });
65
+
66
+ }
package/lib/pk.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "examples",
3
+ "version": "0.0.1",
4
+ "description": "---",
5
+ "keywords": [],
6
+ "homepage": "http://JSLite.io",
7
+ "author": "JSLite.io <wowohoo@qq.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": ""
11
+ },
12
+ "licenses": "ISC"
13
+ }
package/lib/stylus.js ADDED
@@ -0,0 +1,36 @@
1
+ var fs = require('fs');
2
+ var file = require('./file');
3
+ var _stylus = require('stylus');
4
+ var path = require('path')
5
+ var log = console.log;
6
+ var autoprefixer = require('autoprefixer-stylus');
7
+ var browserslist = ['Android 2.3', 'Android >= 4', 'Chrome >= 20', 'Firefox >= 24', 'Explorer >= 8', 'iOS >= 6', 'Opera >= 12', 'Safari >= 6'];
8
+
9
+ module.exports = stylus
10
+
11
+ function stylus(_path,cb){
12
+
13
+ var files = file.currentFile(_path)
14
+
15
+ for (var i = 0; i < files.length; i++) {
16
+
17
+ var _fileurl = _path + files[i],
18
+ _extname = path.extname(_fileurl),
19
+ _filename = path.basename(_fileurl, '.styl');
20
+
21
+ if(_extname === '.styl'){
22
+
23
+ if(!file.exists(_fileurl)) return cb&&cb("no such file or directory '" + _fileurl +"'");
24
+
25
+ _stylus(file.read(_fileurl))
26
+ .set('filename',_fileurl)
27
+ .set('compress',true)
28
+ .use(autoprefixer())
29
+ .render(function(err, css){
30
+ cb&&cb(err,css,_filename,_extname);
31
+ });
32
+ }
33
+
34
+ };
35
+
36
+ }