Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现 Task.JS 规范接口,支持从Mod中调用 #10

Merged
merged 3 commits into from
Sep 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* eol=lf
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,42 @@

ispriter -c config.example.json

### 从 [Mod](https://github.com/modulejs/modjs) 中调用

// Modfile
module.exports = {
plugins: {
sprite: "ispriter"
},
tasks: {
sprite: {
page1: {
"input": "./../test/css/", // input cssRoot
"output": "./../test/sprite_output/css/" // output cssRoot
},
page2: {
// 涉及对象类型参数需配置在options中
options: {
"algorithm": "growingpacker",//optional 目前只有 growingpacker
"input": {
"cssRoot": "./css/", //required
"format": "png"//optional, 只支持输出PNG格式, 如果是其他格式, 也是以PNG格式输出, 仅仅把后缀改为其他后缀
},
"output": {
"cssRoot": "./sprite_output/css/",//required
"imageRoot": "../images/",//optional 相对于 cssRoot 的路径, 默认 "./image/", 最终会变成合并后的的图片路径写在css文件中
"maxSize": 60,//optional 图片容量的最大大小, 单位 KB, 默认 0
"margin": 5,//optional 合成之后, 图片间的空隙, 默认 0
"prefix": "sprite_",//optional
"format": "png",//optional 输出的图片格式
"combine": false//optional 为true时将所有图片合并为一张, 同时所有css文件合并为一个文件
}
}
}
}
}
}

Example
=======

Expand Down
9 changes: 8 additions & 1 deletion src/ispriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,9 @@ var onMergeStart = function(){
this.start = +new Date;
}

var onMergeFinish = function(){
var onMergeFinish = function(done){
console.log('>>all done. time use:', +new Date - this.start, 'ms');
done && done();
}

/**
Expand Down Expand Up @@ -703,3 +704,9 @@ exports.merge = function(configFile){
}
});
}

// Task.JS Specification API https://github.com/taskjs/spec
exports.run = function(options, done){
exports.merge(options);
onMergeFinish = onMergeFinish.bind(this, done);
}
25 changes: 25 additions & 0 deletions test/Modfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
plugins: {
sprite: "../"
},
tasks: {
sprite: {
options: {
"algorithm": "growingpacker",//optional 目前只有 growingpacker
"input": {
"cssRoot": "./css/", //required
"format": "png"//optional, 只支持输出PNG格式, 如果是其他格式, 也是以PNG格式输出, 仅仅把后缀改为其他后缀
},
"output": {
"cssRoot": "./sprite_output/css/",//required
"imageRoot": "../images/",//optional 相对于 cssRoot 的路径, 默认 "./image/", 最终会变成合并后的的图片路径写在css文件中
"maxSize": 60,//optional 图片容量的最大大小, 单位 KB, 默认 0
"margin": 5,//optional 合成之后, 图片间的空隙, 默认 0
"prefix": "sprite_",//optional
"format": "png",//optional 输出的图片格式
"combine": false//optional 为true时将所有图片合并为一张, 同时所有css文件合并为一个文件
}
}
}
}
}