🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

data2code

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data2code

Codegenerator for data

Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
8
-61.9%
Maintainers
1
Weekly downloads
 
Created
Source

data to code generator

Build Status

  • This module generate code from a javascript Object
  • It uses Handlebars templates
  • It's primary use is to make code from raml-js-parser

Defining a Generator

Usually a generator it's responsible for certain path of the javascript object.

A generator is a simple object with the following properties:

  • Required properties:
    • template -> Handlebars template.
    • parser(data) -> Function it receives RAML parsed data, returns parsed data The parser must return and array of object each object must have name and content properties

Sample:

[ { name: "test.test", 
    model: {
      title:data.title + " finos"
      }
  }
]
  • Optional properties:
    • handleRender([str]) -> This function handles the render results, usually writes to disk.
    • helpers -> Handlebars helpers.
    • partials -> Handlebars partials.

##Usage

var data2Code = require('data2Code');
var raml = require('raml-parser');

var simpleGen = {};
simpleGen.template = '{{title}}';
simpleGen.parser = function(){

}
var handleRender = function (result) {
  console.log(result);
}
Or to use multiple templates
var simpleGen = {}
simpleGen.templates = [{tmpl: "{title}", parser: function }]

raml.loadFile('myAPI.raml').then( function(data){
  data2Code.process(data, simpleGen);   
  data2Code.process(data, anotherGen);
}, function(error) {
  console.log('Error parsing: ' + error);
});

FAQs

Package last updated on 02 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts