0.0.4 • Published 9 years ago

gulp-angular-json v0.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

gulp-angular-json

Create angular components from json

Installation

$ npm install gulp-ng-json --save-dev

Usage

Create constants from json

Create a json like this

// app.constant.json
{
	"name": "Demo",
    "version": "0.0.1",
    "description": "gulp-ng-json demo"
}

Create gulp task like this

var gulp = require('gulp')
	, ngjson = require('gulp-ng-json')
	, concat = require('gulp-concat');

gulp.task('test', function () {
  gulp.src('**/*.json')
  .pipe(ngjson.constant())
  .pipe(concat('app.js'))
  .pipe(gulp.dest('.'));
});

And app.js will be generated like this

(function() {
    'use strict'

    angular.module('app')
        .constant('APP', Constant());

    function Constant() {
        return {
          "name": "Demo",
          "version": "0.0.1",
          "description": "gulp-ng-json demo"
		}
    }

})();

Create modules from json

Create a json like this

// app.module.json
{
    "name": "app",
    "dependencies": [
        "app.templates"
    ]
}

Create gulp task like this

var gulp = require('gulp')
	, ngjson = require('gulp-ng-json')
	, concat = require('gulp-concat');

gulp.task('test', function () {
  gulp.src('**/*.json')
  .pipe(ngjson.module())
  .pipe(concat('app.js'))
  .pipe(gulp.dest('.'));
});

And app.js will be generated like this

(function() {
    'use strict'

    angular.module('app', [
        'app.templates'
    ]);

})();

Options

Constants

You can specify the name of the constant and the module name where the constant is included.

{
    "$constant": {
        "$name": "APPDEMO",
        "$module": "app"
    }
}

By default they are converted json extension "* .constant.json", but you can pass the regular expression used.

var options = {matcher: /[\w-]+.constant.json$/g};
ngjson.constant(options);
Other options
OptionDescriptionValue
matcherFilename to be soughtregex
nominatorDefine the constant namefunction
parserJson converter to objectfunction
automoduleSearch module.json to set the module that constant will be includedboolean
templateTemplate file path that will be used to create a constantstring

Modules

var options = {matcher: /[\w-]+.module.json$/g};
ngjson.module(options);

As well as constant, the modules can be informed with specific options

OptionDescriptionValue
matcherFilename to be soughtregex
templateTemplate file path that will be used to create a constantstring