Skip to content

Commit

Permalink
基于客户端模板生成模拟数据,完善测试用例,重构文件和目录结构,引入 Jison 生成模板解析器
Browse files Browse the repository at this point in the history
  • Loading branch information
nuysoft committed Aug 8, 2013
1 parent 8518a6b commit 32cb49f
Show file tree
Hide file tree
Showing 41 changed files with 9,870 additions and 1,712 deletions.
92 changes: 76 additions & 16 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,107 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', 'package.json', 'src/**/*.js', 'test/**/*.js'], //
files: ['Gruntfile.js', 'package.json', 'src/**/*.js', 'test/**/*.js',
'!**/*-prefix.js', '!**/*-suffix.js', '!src/tpl/parser.js', '!src/tpl/parser/parser.js'
], //
options: {
jshintrc: '.jshintrc'
}
},
qunit: {
files: ['test/**/*.html']
files: ['test/mock.html', 'test/mock-*.html',
'test/mock4tpl.html', 'test/mock4tpl-*.html',
'test/**/*.html'
]
},
nodeunit: {
all: ['test/mock-node.js','test/mock4tpl-node.js']
all: ['test/*-node.js' /*, 'test/mock4xtemplate-node.js'*/ ]
},
watch: {
dev: {
files: ['<%= jshint.files %>', 'test/**/*.*'],
tasks: ['jshint', 'nodeunit']
tasks: ['jshint', 'nodeunit', 'concat' /*, 'qunit'*/ ]
},
build: {
files: ['<%= jshint.files %>', 'test/**/*.*'],
tasks: ['jshint', 'nodeunit']
tasks: ['jshint', 'nodeunit', 'concat' /*, 'qunit'*/ ]
}
},
concat: {
options: {
separator: '\n\n',
process: function(src, filepath) {
var banner = '// ' + filepath + '\n';
// var rbrowser = /\/\/ BEGIN\(BROWSER\)\n([.\s]*)\n\/\/ END\(BROWSER\)/mg
var BEGEIN = '// BEGIN(BROWSER)',
END = '// END(BROWSER)';
var indexOfBEGEIN = src.indexOf(BEGEIN),
indexOfEND = src.indexOf(END);
if (indexOfBEGEIN != -1 && indexOfEND != -1) {
return banner + src.slice(indexOfBEGEIN + BEGEIN.length, indexOfEND)
}
return banner + src
}
},
mock: {
src: ['src/mock-prefix.js',
'src/util.js', 'src/random.js', 'src/mock.js', 'src/mockjax.js', 'src/expose.js',
'src/mock-suffix.js'
],
dest: 'dist/mock.js'
},
parser: {
options: {
process: function(src) {
return src
}
},
src: ['src/tpl/parser/parser-prefix.js',
'src/tpl/parser/parser.js', 'src/tpl/parser/ast.js',
'src/tpl/parser/parser-suffix.js'
],
dest: 'src/tpl/parser.js'
},
mock4tpl: {
src: ['src/tpl/mock4tpl-prefix.js',
'src/tpl/parser.js', 'src/tpl/mock4tpl.js', 'src/tpl/expose.js',
'src/tpl/mock4tpl-suffix.js'
],
dest: 'dist/mock4tpl.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
src: {
mock: {
expand: true,
cwd: 'src/',
cwd: 'dist/',
src: ['**/*.js', '!**/*-min.js'],
dest: 'build/',
dest: 'dist/',
ext: '-min.js'
}
},
exec: {
parser: {
command: './node_modules/.bin/jison -m js src/tpl/parser/parser.yy src/tpl/parser/parser.l'
},
move: {
command: 'mv parser.js src/tpl/parser/'
}
}
});
})

grunt.loadNpmTasks('grunt-contrib-jshint')
grunt.loadNpmTasks('grunt-contrib-qunit')
grunt.loadNpmTasks('grunt-contrib-watch')
grunt.loadNpmTasks('grunt-contrib-nodeunit')
grunt.loadNpmTasks('grunt-contrib-uglify')
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-exec')

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('default', ['jshint', 'nodeunit', 'concat', 'qunit', 'uglify', 'watch:dev'])
grunt.registerTask('build', ['jshint', 'nodeunit', 'concat', 'qunit', 'uglify'])
grunt.registerTask('parser', ['exec'])

grunt.registerTask('default', ['jshint', 'nodeunit', 'watch:dev']);
grunt.registerTask('build', ['jshint', 'nodeunit', 'uglify']);
};
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@
1. 60% 基于客户端模板生成模拟数据。
1. 增加测试用例 [test/mock4tpl-node.js](https://github.com/nuysoft/Mock/blob/master/test/mock4tpl-node.js),参考自 <http://handlebarsjs.com/>

### 2013.8.7
1. 75% 基于客户端模板生成模拟数据。
1. 完善测试用例 [test/mock4tpl-node.js](https://github.com/nuysoft/Mock/blob/master/test/mock4tpl-node.js)
1. 重构文件和目录结构,把代码模块化。
1. 参考 Handlebars.js,引入 Jison 生成模板解析器。

## 规划
1. √ 暴露产生随机元数据的接口。
1. 重构项目结构,设计更好用的 API。
1. 60% 基于客户端模板生成模拟数据。
1. 75% 基于客户端模板生成模拟数据。
1. 50% 提供随机图片生成服务。
1. 30% 提供自定义模板数据的保存和访问服务。
1. 提供真正的随即数。
Expand Down
2 changes: 1 addition & 1 deletion demo/mock.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<script src="../node_modules/jquery/tmp/jquery.js"></script>
<script src="../node_modules/codemirror/lib/codemirror.js"></script>
<script src="../node_modules/codemirror/mode/javascript/javascript.js"></script>
<script src="../src/mock.js"></script>
<script src="../dist/mock.js"></script>
<script type="text/javascript">
$(function(){
$('.content').css('opacity', 1)
Expand Down
4 changes: 2 additions & 2 deletions demo/mock4tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
<script src="../node_modules/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="../node_modules/codemirror/mode/coffeescript/coffeescript.js"></script>

<script src="../src/mock.js"></script>
<script src="../src/mock4tpl.js"></script>
<script src="../dist/mock.js"></script>
<script src="../dist/mock4tpl.js"></script>
<script src="../node_modules/handlebars/dist/handlebars.js"></script>

<script type="text/javascript">
Expand Down
2 changes: 2 additions & 0 deletions dist/mock-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 32cb49f

Please sign in to comment.