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'
Usage Example
localSettings: js: options: prefix: 'Model.prototype' src: '*.{yaml,yml,json}' dest: 'build.js' ;
options.prefix
Type: String
Default value: ''
Namespace of your properties. Example: Model.prototype = { isWeekend: function () {...} };
How to start
Installation
npm install grunt-model-settings --save-dev
1 Create the file(s) with rules definitions.
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
2 Add modelSettings section to your Grunfile
see Usage Example
3 Run task
grunt modelSettings
Result:
Modelprototype = { return /^sat|^sun/i || /6/i || this; } { return /7/i; };
___ ### Advantage configuring
grunt
options.singleDefinition
Type: Boolean
Default value: true
if true rules will be concated to object:
Modelprototype = {...} {...};
if false rules will be defined as functions:
ModelprototypeisWeekend: {...};ModelprototypeisSunday: {...};
Set this attribute to false using grunt-concat-properties
options.rulePrefix
Type: String
Default value: function () {\n return
String before rule body:
isSunday: function () { return ((/7/i).test(this.attributes.dayOfWeek)); }
options.rulePostfix
Type: String
Default value: ;\n}
String after rule body:
isSunday: function () { return ((/7/i).test(this.attributes.dayOfWeek)); }
options.functionsScope
Type: String
Default value: this
String before method call:
isWeekend: function () { return this.isSunday(); }
options.attributesScope
Type: String
Default value: this.attributes
String before attribute call:
isSunday: function () { return ((/7/i).test(this.attributes.dayOfWeek)); }
___ #### Recommendations Use some like grunt-jsbeautifier to keep indentation at concated files