0.0.6 • Published 10 years ago
class-sheet v0.0.6
class-sheet
Under construction.
A package that generates image from class-sheet data.
Example
As a server with express.js:
var classSheet = require('class-sheet');
router.get('/:course_data', function (req, res, next) {
// stream and pipe to res, send image/png result as the response
classSheet.imageStream(req.params.course_data, res);
});As an independent tool:
var classSheet = require('class-sheet');
// output the base64 result
console.log(classSheet.image(course_data));Data format
A JSON string, i.e.:
course_data = '{\
"courses":\
[\
{"name":"人工智能","day":0,"section":"2-4"},\
{"name":"数据通信与计算机网络","day":2,"section":"11-12"},\
{"name":"数据通信与计算机网络","day":0,"section":"6-8"},\
{"name":"操作系统","day":1,"section":"8-9"},\
{"name":"游戏开发基础","day":2,"section":"2-4"},\
{"name":"概率论与数理统计","day":2,"section":"6-8"},\
{"name":"第一哲学沉思集","day":3,"section":"11-12"},\
{"name":"中文信息处理","day":3,"section":"3-4"},\
{"name":"计算机图形学","day":4,"section":"2-4"},\
{"name":"操作系统","day":3,"section":"6-8"},\
{"name":"概率论与数理统计","day":4,"section":"6-7"}\
]\
}'Then calling classSheet.image with course_data will get the image below (as base64 data):

Notice you can get the JSON string by calling JSON.stringify(course_object_data).
Another example:

Usage
Install
From NPM:
$ npm install class-sheet
From git repo:
- install node-canvas: https://github.com/Automattic/node-canvas/wiki
$ git clone git@github.com:quietshu/class-sheet.git$ npm install
Test
Code style:
$ npm test (current only xo.js)
Options
courses- courses data
- default:
[] - example:
[{"name":"Modern Art","day":2,"section":"1-3"}, {"name":"Computer Graphics","day":"4","section":"9-10","text-color":"red"}]
lines- horizontal lines
- default:
[] - example:
[5, 10]will drop lines under section 5 and section 10
custom-line-color- default:
'red'
- default:
day-content- default:
['一', '二', '三', '四', '五']
- default:
width- default:
320
- default:
height- default:
640
- default:
line-color- default:
'#ccc'
- default:
text-color- default:
'#000'
- default:
font-size- default:
12
- default:
info-text-color- default:
'#555'
- default:
info-font-size- default:
10
- default:
background-color- default:
'#f5f5f5'
- default:
header-height- default:
40
- default:
header-line-color- default:
'#000'
- default:
header-text-color- default:
'#000'
- default:
header-font-size- default:
15
- default:
sidebar-width- default:
30
- default:
sidebar-line-color- default:
'#000'
- default:
sidebar-text-color- default:
'#000'
- default:
sidebar-font-size- default:
12
- default:
days- default:
5
- default:
sections- default:
14
- default:
course-background-color- default:
'#fff'
- default:
Acknowledgements
- node-canvas
License
MIT.
<3