| language: node_js | ||
| node_js: | ||
| - "0.11" | ||
| - "0.10" | ||
| before_script: | ||
| - npm install -g gulp | ||
| script: gulp |
+21
-4
| var gulp = require('gulp'); | ||
| var del = require('del'); | ||
| var gutil = require('gulp-util'); | ||
| var mocha = require('gulp-mocha'); | ||
| var runSequence = require('run-sequence'); | ||
| var coffee = require('gulp-coffee'); | ||
| gulp.task('clean', function (cb) { | ||
| del([ | ||
| 'lib/**' | ||
| ], cb); | ||
| }); | ||
| gulp.task('coffee', function() { | ||
| gulp.src('./src/**/*.coffee') | ||
| return gulp.src('./src/**/*.coffee') | ||
| .pipe(coffee({bare: true}).on('error', gutil.log)) | ||
@@ -14,3 +23,3 @@ .pipe(gulp.dest('./lib/')) | ||
| gulp.task('copy-templates', function(){ | ||
| gulp.src('./src/**/*.hbs') | ||
| return gulp.src('./src/**/*.hbs') | ||
| .pipe(gulp.dest('./lib/')); | ||
@@ -20,7 +29,7 @@ }); | ||
| gulp.task('test', function(){ | ||
| gulp.src('./test/index.js') | ||
| gulp.src('./test/*spec.js') | ||
| .pipe(mocha( | ||
| { | ||
| require: ['chai', 'chai-as-promised'], | ||
| reporter: 'nyan', | ||
| reporter: 'spec', | ||
| growl: true | ||
@@ -31,2 +40,10 @@ } | ||
| gulp.task('build', function(callback) { | ||
| runSequence('clean', | ||
| ['copy-templates', 'coffee'], | ||
| 'test', | ||
| callback); | ||
| }); | ||
| gulp.task('default', ['build']); | ||
+15
-32
@@ -6,46 +6,29 @@ var Handlebars; | ||
| module.exports.process = function(data, gen) { | ||
| var dataParsed, e, helper, obj, partial, result, template, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; | ||
| var dataParsed, obj, options, result, template, _i, _len; | ||
| if (gen.handleRender && typeof gen.handleRender === 'function') { | ||
| if (gen.helpers && gen.helpers instanceof Array) { | ||
| _ref = gen.helpers; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| helper = _ref[_i]; | ||
| if (helper.name && helper.fn && typeof helper.fn === 'function') { | ||
| Handlebars.registerHelper(helper.name, helper.fn); | ||
| } else { | ||
| console.error("helpers not are in incorrect format"); | ||
| } | ||
| } | ||
| } | ||
| if (gen.partials) { | ||
| _ref1 = gen.partials; | ||
| for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
| partial = _ref1[_j]; | ||
| if (partial.name && partial.str) { | ||
| Handlebars.registerPartial(partial.name, partial.str); | ||
| } | ||
| } | ||
| } | ||
| if (typeof gen.parser === 'function') { | ||
| try { | ||
| dataParsed = gen.parser(data); | ||
| } catch (_error) { | ||
| e = _error; | ||
| console.log("Parser error", e); | ||
| } | ||
| dataParsed = gen.parser(data); | ||
| } else { | ||
| dataParsed = data; | ||
| } | ||
| template = Handlebars.compile(gen.template); | ||
| if (typeof gen.template !== "function") { | ||
| template = Handlebars.compile(gen.template); | ||
| } else { | ||
| template = gen.template; | ||
| } | ||
| options = { | ||
| helpers: gen.helpers, | ||
| partials: gen.partials | ||
| }; | ||
| if (Array.isArray(dataParsed)) { | ||
| result = []; | ||
| for (_k = 0, _len2 = dataParsed.length; _k < _len2; _k++) { | ||
| obj = dataParsed[_k]; | ||
| for (_i = 0, _len = dataParsed.length; _i < _len; _i++) { | ||
| obj = dataParsed[_i]; | ||
| if (obj.name && obj.model) { | ||
| result.push({ | ||
| name: obj.name, | ||
| content: template(obj.model) | ||
| content: template(obj.model, options) | ||
| }); | ||
| } else { | ||
| throw new Error("Data element doesn't have name or model please"); | ||
| throw new Error("Data element doesn't have name or model"); | ||
| } | ||
@@ -52,0 +35,0 @@ } |
+5
-3
| { | ||
| "name": "data2code", | ||
| "version": "0.0.2", | ||
| "version": "0.0.3", | ||
| "description": "Codegenerator for data", | ||
@@ -10,9 +10,11 @@ "main": "lib/data2code.js", | ||
| "devDependencies": { | ||
| "gulp": "3.8.7", | ||
| "gulp": "3.8.10", | ||
| "gulp-coffee": "2.2.0", | ||
| "gulp-mocha" : "1.0.0", | ||
| "chai": "~1.9.1", | ||
| "del": "^1.1.1", | ||
| "mocha": "~1.20.1", | ||
| "raml-parser": "0.8.7", | ||
| "gulp-util": "3.0.1" | ||
| "gulp-util": "3.0.1", | ||
| "run-sequence": "^1.0.2" | ||
| }, | ||
@@ -19,0 +21,0 @@ "scripts": { |
+2
-0
| # data to code generator | ||
| [](https://travis-ci.org/gextech/data2code) | ||
@@ -3,0 +5,0 @@ * This module generate code from a javascript Object |
| Handlebars = require("handlebars") | ||
| module.exports.process = (data , gen) -> | ||
| if gen.handleRender and typeof gen.handleRender is 'function' | ||
| if gen.helpers and gen.helpers instanceof Array | ||
| for helper in gen.helpers | ||
| if helper.name and helper.fn and typeof helper.fn is 'function' | ||
| Handlebars.registerHelper(helper.name, helper.fn) | ||
| else | ||
| console.error "helpers not are in incorrect format" | ||
| if gen.partials | ||
| for partial in gen.partials | ||
| if partial.name and partial.str | ||
| Handlebars.registerPartial(partial.name, partial.str) | ||
| if typeof gen.parser is 'function' | ||
| try | ||
| dataParsed = gen.parser(data) | ||
| catch e | ||
| console.log "Parser error" , e | ||
| else | ||
| dataParsed = data | ||
| template = Handlebars.compile(gen.template) | ||
| if Array.isArray dataParsed | ||
| result = [] | ||
| for obj in dataParsed | ||
| if obj.name and obj.model | ||
| result.push {name: obj.name, content: template(obj.model)} | ||
| else | ||
| throw new Error("Data element doesn't have name or model") | ||
| gen.handleRender(result) | ||
| else | ||
| throw new Error("Digest data is not and Array") | ||
| else | ||
| throw new Error("generator.handleRender not defined") | ||
| 'use strict'; | ||
| var raml = require('raml-parser'), expect = require('chai').expect; | ||
| var data2Code = require('..'); | ||
| describe('data2code basic test', function () { | ||
| var handleRender = function (done, expectedResult, result) { | ||
| try { | ||
| result[0].content.should.equal(expectedResult); | ||
| result[0].name.should.equal("test.test"); | ||
| done(); | ||
| } catch (x) { | ||
| done(x); | ||
| } | ||
| }; | ||
| var sampleData = [{ name: "test.test", model: {title: "Compra venta de gatitos"}}]; | ||
| it('should generate something', function (done) { | ||
| var simpleGen = {}; | ||
| simpleGen.template = '{{title}}'; | ||
| simpleGen.handleRender = handleRender.bind(undefined, done, "Compra venta de gatitos"); | ||
| data2Code.process(sampleData, simpleGen); | ||
| }); | ||
| it('testing parser', function (done) { | ||
| var simpleGen = {}; | ||
| simpleGen.template = '{{title}}'; | ||
| simpleGen.parser = function (data) { | ||
| return sampleData | ||
| }; | ||
| simpleGen.handleRender = handleRender.bind(undefined, done, "Compra venta de gatitos"); | ||
| data2Code.process({}, simpleGen); | ||
| }); | ||
| it('testing parser when returning Arrasy', function (done) { | ||
| var simpleGen = {}; | ||
| simpleGen.template = '{{title}}'; | ||
| simpleGen.parser = function (data) { | ||
| return [{ name: "test.test", model: {title:data[0].model.title + " finos"}}] | ||
| }; | ||
| simpleGen.handleRender = function(data){ | ||
| data[0].content.should.equal("Compra venta de gatitos finos"); | ||
| data[0].name.should.equal("test.test"); | ||
| done() | ||
| }; | ||
| data2Code.process(sampleData, simpleGen); | ||
| }); | ||
| it('testing helpers', function (done) { | ||
| var simpleGen = {}; | ||
| simpleGen.template = '{{msg title}}'; | ||
| simpleGen.helpers = [ | ||
| {name: 'msg', | ||
| fn: function (msg) { | ||
| return 'Renta, ' + msg | ||
| } | ||
| } | ||
| ]; | ||
| simpleGen.handleRender = handleRender.bind(undefined, done, "Renta, Compra venta de gatitos"); | ||
| data2Code.process(sampleData, simpleGen); | ||
| }); | ||
| it('testing partials', function (done) { | ||
| var simpleGen = {}; | ||
| simpleGen.template = '{{>header}}'; | ||
| simpleGen.partials = [ | ||
| {name: 'header', str: 'Testing partial'} | ||
| ]; | ||
| simpleGen.handleRender = handleRender.bind(undefined, done, "Testing partial"); | ||
| data2Code.process(sampleData, simpleGen); | ||
| }); | ||
| }); |
| 'use strict'; | ||
| var Mocha = require('mocha'); | ||
| var chai = require('chai'); | ||
| var mocha = new Mocha(); | ||
| mocha.addFile(__dirname + '/data2Code-spec'); | ||
| chai.should(); | ||
| mocha.run(); |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Cat", | ||
| "description": "A cat from Atoms catalog", | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "description": "The unique identifier for a cat", | ||
| "type": "integer" | ||
| }, | ||
| "name": { | ||
| "description": "Name of the cat", | ||
| "type": "string" | ||
| }, | ||
| "ownerName":{ | ||
| "description": "Name of the owner", | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": ["id", "name"] | ||
| } |
Sorry, the diff of this file is not supported yet
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Cats", | ||
| "description": "A cats collection", | ||
| "type": "array", | ||
| "items": { "$ref": "#/cat" } | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Error", | ||
| "description": "A server error", | ||
| "type": "object", | ||
| "properties": { | ||
| "error": { | ||
| "description": "The unique identifier for a cat", | ||
| "properties": { | ||
| "code": {"type": "string"}, | ||
| "messages": {"type": "string"}, | ||
| "status": {"type": "integer"} | ||
| }, | ||
| "required": ["code", "messages", "status"] | ||
| } | ||
| } | ||
| } | ||
| package {{extra.package}} | ||
| {{debug}} | ||
| class {{displayName}} implements Serializable { | ||
| {{#methods}} | ||
| {{method}} | ||
| {{#if responses}} | ||
| {{#each responses}} | ||
| {{#if this.body}} | ||
| {{@key}} | ||
| {{#each this.body}} | ||
| {{#if this.schema}} | ||
| {{#parseSchema this.schema}} | ||
| {{#each properties}} | ||
| {{@key}} {{this.type}} | ||
| {{/each}} | ||
| {{/parseSchema}} | ||
| {{/if}} | ||
| {{/each}} | ||
| {{/if}} | ||
| {{/each}} | ||
| {{/if}} | ||
| {{/methods}} | ||
| } |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
55
3.77%0
-100%4537
-60.27%9
28.57%6
-53.85%77
-60.91%