grunt-jasper
Advanced tools
Comparing version
{ | ||
"name": "grunt-jasper", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Grunt task to build and package jasper application", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/jasperjs/grunt-jasper", |
@@ -43,6 +43,6 @@ 'use strict'; | ||
this.escapeContent = function(content){ | ||
this.escapeContent = function (content) { | ||
var quotRegexp = /\'/g; | ||
var breaklineRegexp = /(?:\r\n|\r|\n)/g; | ||
var first = content.replace(/\\/g,'\\\\').replace(quotRegexp, '\\\'').replace(breaklineRegexp, ' '); | ||
var first = content.replace(/\\/g, '\\\\').replace(quotRegexp, '\\\'').replace(breaklineRegexp, ' '); | ||
return first; | ||
@@ -66,6 +66,6 @@ }; | ||
this.getCssTargets = function(cssConfig){ | ||
if(!Array.isArray(cssConfig)){ | ||
this.getCssTargets = function (cssConfig) { | ||
if (!Array.isArray(cssConfig)) { | ||
var result = []; | ||
for(var prop in cssConfig){ | ||
for (var prop in cssConfig) { | ||
result.push({ | ||
@@ -84,3 +84,3 @@ filename: prop, | ||
this.getAppStyles = function(grunt, cssConfig, appPath ){ | ||
this.getAppStyles = function (grunt, cssConfig, appPath) { | ||
var targets = this.getCssTargets(cssConfig); | ||
@@ -158,2 +158,14 @@ var result = []; | ||
this.splitStringBySpace = function (props) { | ||
if (typeof (props) === 'string') { | ||
return props.split(' ').map(function (item) { | ||
var i = item.trim(); | ||
return i ? i : null; | ||
}).filter(function (i) { | ||
return i; | ||
}); | ||
} | ||
return props; | ||
}; | ||
this.isAbsUrl = function (url) { | ||
@@ -168,7 +180,7 @@ var r = new RegExp('^(?:[a-z]+:)?//', 'i'); | ||
*/ | ||
this.excludeAbsScripts = function(scripts){ | ||
this.excludeAbsScripts = function (scripts) { | ||
var result = []; | ||
for(var i = scripts.length - 1; i >= 0; i--){ | ||
if(this.isAbsUrl(scripts[i])) { | ||
result.push(scripts.splice( i, 1)[0]); | ||
for (var i = scripts.length - 1; i >= 0; i--) { | ||
if (this.isAbsUrl(scripts[i])) { | ||
result.push(scripts.splice(i, 1)[0]); | ||
} | ||
@@ -175,0 +187,0 @@ } |
@@ -174,3 +174,3 @@ /* | ||
var registerDefinition = function(config, def){ | ||
var registerDefinition = function (config, def) { | ||
if (!def.name) { | ||
@@ -184,3 +184,11 @@ var tagName = utils.getParentFolderName(config); | ||
if (def.attributes) { | ||
if (def.properties || def.events) { | ||
if (def.properties) { | ||
def.properties = utils.splitStringBySpace(def.properties); | ||
} | ||
if (def.events) { | ||
def.events = utils.splitStringBySpace(def.events); | ||
} | ||
} | ||
else if (def.attributes) { | ||
def.attributes = utils.getJasperAttributes(def.attributes); | ||
@@ -190,3 +198,3 @@ } | ||
if (def.type.toUpperCase() === 'PAGE') { | ||
if(!def.area) | ||
if (!def.area) | ||
def.area = area.name; | ||
@@ -203,4 +211,4 @@ pages.push(def); | ||
if(def.type.toUpperCase() === 'TEMPLATE'){ | ||
if(!def.templateUrl){ | ||
if (def.type.toUpperCase() === 'TEMPLATE') { | ||
if (!def.templateUrl) { | ||
grunt.log.error('TemplateFile not defined in ' + def.__path); | ||
@@ -237,7 +245,7 @@ return; | ||
var def = grunt.file.readJSON(config); | ||
if(Array.isArray(def)){ | ||
def.forEach(function(d){ | ||
if (Array.isArray(def)) { | ||
def.forEach(function (d) { | ||
registerDefinition(config, d); | ||
}); | ||
}else { | ||
} else { | ||
registerDefinition(config, def); | ||
@@ -352,6 +360,6 @@ } | ||
src: target.files || [], | ||
dest: stylesMinDest+ target.filename, | ||
dest: stylesMinDest + target.filename, | ||
ext: '.min.css' | ||
}; | ||
if(i === cssTargets.length - 1){ | ||
if (i === cssTargets.length - 1) { | ||
fileConfig.src = fileConfig.src.concat(grunt.file.expand(options.appPath + '/**/*.css')); | ||
@@ -369,3 +377,3 @@ } | ||
if(runConcatMinify) { | ||
if (runConcatMinify) { | ||
//run concat minify, only if any area to minify | ||
@@ -405,3 +413,3 @@ grunt.config('uglify', uglifyConf); | ||
var areaMinScriptReferencePath = 'scripts/' + area.name + '.min.js'; | ||
if(options.fileVersion) { | ||
if (options.fileVersion) { | ||
// append version param for area script filename | ||
@@ -454,3 +462,3 @@ areaMinScriptReferencePath = utils.appendFileVersion(options.packageOutput + '/' + areaMinScriptReferencePath, areaMinScriptReferencePath); | ||
grunt.registerTask('jasperValuesConfig', 'Building client-side values configuration script (_values.js)', function () { | ||
if(!options.values) | ||
if (!options.values) | ||
return; | ||
@@ -479,3 +487,3 @@ | ||
grunt.registerTask('jasperPackageBase', 'Modify single page', function () { | ||
if(!options.package) | ||
if (!options.package) | ||
return; | ||
@@ -528,3 +536,3 @@ // concat base | ||
if (scripts[i]) { | ||
scriptsHtml += '\t<script src="' + options.baseHref + scripts[i] + '"></script>\r\n'; | ||
scriptsHtml += '\t<script src="' + options.baseHref + scripts[i] + '"></script>\r\n'; | ||
} | ||
@@ -555,3 +563,3 @@ } | ||
for (var i = 0; i < styles.length; i++) { | ||
stylesHtml += '\t<link rel="stylesheet" href="' + options.baseHref + styles[i] + '"/>\r\n'; | ||
stylesHtml += '\t<link rel="stylesheet" href="' + options.baseHref + styles[i] + '"/>\r\n'; | ||
} | ||
@@ -558,0 +566,0 @@ var stylesRegex = /<!-- STYLES -->([\s\S]*)<!-- \/STYLES -->/gim; |
@@ -143,3 +143,3 @@ 'use strict'; | ||
'jsp.template(\'#_page_homePage\',\'<home-page></home-page>\')', | ||
'jsp.component({"ctrl":spa.core.components.SiteHeader,"attributes":[{"name":"my-attr"},{"name":"on-click","type":"exp"}],"name":"siteHeader","templateUrl":"test/testApp/app/core/components/site-header/site-header.html"})', | ||
'jsp.component({"ctrl":spa.core.components.SiteHeader,"properties":["myAttr"],"events":["click"],"name":"siteHeader","templateUrl":"test/testApp/app/core/components/site-header/site-header.html"})', | ||
'jsp.component({"route":"/","ctrl":spa.core.pages.HomePage', | ||
@@ -146,0 +146,0 @@ 'jsp.decorator({"ctrl":spa.core.decorators.FocusOnDefault,"name":"focusOnDefault"})', |
@@ -108,3 +108,3 @@ 'use strict'; | ||
test.ok(configObject.core.scripts[1] === '//path/to/external/script.js', 'Core area must contains external script'); | ||
test.ok(configObject.core.scripts[2] === 'scripts/core.min.js?v=d478c114d47832eaf46d943a0723c621','Core area must contains area script'); | ||
test.ok(configObject.core.scripts[2] === 'scripts/core.min.js?v=d2b417555b0ed3464a48b17f5a977bce','Core area must contains area script'); | ||
@@ -114,3 +114,3 @@ test.strictEqual(configObject.boot.scripts, undefined, 'Scripts of bootstrapped area must be undefined') | ||
ensurePartsExistence(test, configObject.feature.dependencies, ['core']); | ||
ensurePartsExistence(test, configObject.core.scripts, ['scripts/core.min.js?v=d478c114d47832eaf46d943a0723c621']); | ||
ensurePartsExistence(test, configObject.core.scripts, ['scripts/core.min.js?v=d2b417555b0ed3464a48b17f5a977bce']); | ||
ensurePartsExistence(test, configObject.feature.scripts, ['scripts/feature.min.js?v=ca5b43d674186430395711bdd4d6ae04']); | ||
@@ -117,0 +117,0 @@ |
@@ -5,3 +5,4 @@ { | ||
"ctrl": "spa.core.components.SiteHeader", | ||
"attributes": "my-attr on-click:exp" | ||
"properties": "myAttr", | ||
"events": "click" | ||
} |
58599
0.99%1312
1.55%