grunt-model-settings

Grunt plugin for loading and merge settings from grunt config file

grunt-model-settings

Grunt plugin for build models rules functions from json/yaml files

It can be used for named rules declarations of statuses, types and another unreadable or preset model attributes.

isWeekend:
  includeAny:                           Model.isWeekend = function () {
    dayOfWeekName:           ->             return (/^sat|^sun/i).test(this.dayOfWeekName);
      - '^sat'                          }
      - '^sun'

localSettings: {
    js: {
        options: {
            prefix: 'Model.prototype'
        },
        src:  [
            '*.{yaml,yml,json}'
        ],
        dest: 'build.js'
    }
};

Type: String Default value: ''

Namespace of your properties. Example: Model.prototype = { isWeekend: function () {...} };


Sample project structure

npm install grunt-model-settings --save-dev

You can use single or many declarations per file. Example with logic at comments:

isWeekend:              # rule method name 
  includeAny:           # list type (includeAny or excludeAny) 
    dayOfWeekName:    # attribute name 
      - '^sat'          # attribute values as RegExp partial 
      - '^sun'
    dayOfWeek: '6'    
    - isSunday          # another method call 
isSunday:
  includeAny:
    dayOfWeek: 7

see Usage Example

grunt modelSettings
Model.prototype = {
    isWeekendfunction () {
        return ((/^sat|^sun/i).test(this.attributes.dayOfWeekName) || (/6/i).test(this.attributes.dayOfWeek) || this.isSunday());
    },
    isSundayfunction () {
        return ((/7/i).test(this.attributes.dayOfWeek));
    }
};



grunt.initConfig({
    concatProperties: {
        myApp: {
            options: {
                prefix:           'Model.prototype'
                singleDefinition: true,
                rulePrefix:       'function () {\n return ',
                rulePostfix:      ';\n}',
                functionsScope:   'this',
                attributesScope:  'this.attributes'
            },
 
            src:  [
                '*.{yaml,yml,json}'
            ],
            dest: 'build.js'
        }
    }
};

Type: Boolean Default value: true

if true rules will be concated to object:

Model.prototype = {
    isWeekendfunction () {...},
    isSunday:  function () {...}
};

if false rules will be defined as functions:

Model.prototype.isWeekendfunction () {...};
Model.prototype.isSunday:  function () {...};

Set this attribute to false using grunt-concat-properties

Type: String Default value: function () {\n return

String before rule body:
isSunday: function () { return ((/7/i).test(this.attributes.dayOfWeek)); }

Type: String Default value: ;\n}

String after rule body:
isSunday: function () { return ((/7/i).test(this.attributes.dayOfWeek)); }

Type: String Default value: this

String before method call:
isWeekend: function () { return this.isSunday(); }

Type: String Default value: this.attributes

String before attribute call:
isSunday: function () { return ((/7/i).test(this.attributes.dayOfWeek)); }



Use some like grunt-jsbeautifier to keep indentation at concated files