isFormValid: function() { return _.every(_.pluck(_.toArray(validationData), 'isValid'), _.identity); },
QLearningAgent.prototype.getAction = function(state) { // body... var actionValues = _.pluck(this._qValues.getActionValues(state), 'v'); return this.explorationFolicy.chooseAction(actionValues); };
/** * Exec one statement * * @param opts args * @param statement * @param cb * @ignore */ function _execOne(opts, statement, parentEvent, cb) { if(preReqNotFound(statement, opts, parentEvent)) { return cb(); } var obj, params, args; switch(statement.type) { case 'create' : create.exec(opts, statement, parentEvent, cb); break; case 'define' : params = _util.prepareParams(opts.context, opts.request.body, opts.request.routeParams, opts.request.params, opts.request.headers, opts.request.connection, {config: opts.config}); if(statement.hasOwnProperty('object')) { obj = jsonfill.fill(statement.object, params); } else if(statement.udf) { args = []; _.each(_.pluck(statement.args, 'value'), function(arg) { args.push(jsonfill.lookup(arg, opts.context)); }); try { obj = require('./udfs/standard.js')[statement.udf].apply(null, args); } catch(e) { console.log(e.stack || e); return cb(e); } } opts.context[statement.assign] = obj; opts.emitter.emit(statement.assign, obj) var ret = { body: obj, headers: {} }; cb(null, ret); break; case 'select' : select.exec(opts, statement, parentEvent, cb); break; case 'insert' : insert.exec(opts, statement, parentEvent, cb); break; case 'delete' : delet.exec(opts, statement, parentEvent, cb); break; case 'update' : update.exec(opts, statement, parentEvent, cb); break; case 'show' : show.exec(opts, statement, parentEvent, cb); break; case 'show routes' : showRoutes.exec(opts, statement, parentEvent, cb); break; case 'describe': describe.exec(opts, statement, parentEvent, cb); break; case 'describe route': describeRoute.exec(opts, statement, parentEvent, cb); break; case 'ref': obj = opts.context[statement.ref]; if(_.isNull(obj)) { cb('Unresolved reference in return'); } if(statement.hasOwnProperty('object')) { obj = jsonfill.fill(statement.object, params); } cb(null, { body: obj, headers: {} }); break; case 'if': ifelse.exec(opts, statement, parentEvent, cb); break; case 'try': trycatch.exec(opts, statement, parentEvent, cb); break; case 'throw': trycatch.throw(opts, statement, parentEvent, cb); break; case 'logic': logic.exec(opts, statement, parentEvent, cb); break; } }
'the url of the gif should be updated correctly': function (assetGraph) { assert.deepEqual(_.pluck(assetGraph.findAssets({isImage: true}), 'url').sort(), [ assetGraph.root + 'foo.setFormat=gif.gif' ]); }
getFieldAverage: function(benchmarks, propertyName){ var valuesArray = _.pluck(benchmarks, propertyName); return _.reduce(valuesArray, function(memo, num){ return memo + num; }, 0) / valuesArray.length; },
}).then(function (cookies) { _.pluck(cookies, 'name').should.not.include(newCookie.name); _.pluck(cookies, 'value').should.not.include(newCookie.value); }).nodeify(done);
.map((data) => _.pluck(data, 0))
function TwitterError(errors) { this.errors = errors; this.name = 'TwitterError'; this.message = _.pluck(errors, 'message').join(', '); this.codes = _.pluck(errors, 'code'); }
}).then(function(teams){ if(notValues) return teams; return _.pluck(teams, 'values'); }).catch(function(err){
CL.writeHTMLPage2 = function(adArray) { console.log("Writing HTML For " + adArray.length + " Ads."); var htmlPage = ''; htmlPage += '<!DOCTYPE html><html><head>'; htmlPage += '<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>'; htmlPage += '<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>'; htmlPage += '<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootswatch/3.2.0/united/bootstrap.min.css">'; htmlPage += '<style>'; htmlPage += '.back-to-top2{ position:fixed; top:2%; right:2%; }'; htmlPage += '</style>'; htmlPage += '</head><body><div class="container">'; htmlPage += 'Page created on: ' + CL.creationDate() + '<br><br><hr><br><br>'; htmlPage += CL.topMenu(adArray); var colOrder = [{ id: 'i', class: 'col-md-1 col-lg-1' }, { id: 'a', class: 'col-md-4 col-lg-4' }, { id: 'price', class: 'col-md-1 col-lg-1' }, { id: 'location', class: 'col-md-2 col-lg-2' }, { id: 'city', class: 'col-md-1 col-lg-1' }, { id: 'date', class: 'col-md-1 col-lg-1' }, { id: 'picture', class: 'col-md-1 col-lg-1' }, { id: 'map', class: 'col-md-1 col-lg-1' } ]; _.each(_.uniq(_.pluck(adArray, 'state')), function(state, index) { htmlPage += '<h1><a name=\'' + CL.linkify(state) + '\'>' + state + '</a></h1>'; _.each(_.uniq(_.pluck(_.where(adArray, { state: state }), 'city')), function(city, index) { htmlPage += '<h2>' + city + '</h2>'; // htmlPage += '<h2><a name=\'' + CL.linkify(city) + '\'>' + city + '</a></h2>'; //Loop over each ad that is in the current city _.each(_.where(adArray, { city: city }), function(ad, index) { htmlPage += '<div class=\'row\'>'; var i; if (_.isUndefined(ad.dataid) || _.isNull(ad.dataid) || ad.dataid.length === 0) { i = '<img alt=\'\' src=\'http://www.craigslist.org/images/peace-sm.jpg\'>'; } else { i = '<img alt=\'\' src=\'http://images.craigslist.org/' + ad.dataid.split(':')[1] + '_50x50c.jpg\'>'; } var href = ad.href.slice(0, 4) === 'http' ? ad.href : ad.domain + ad.href; var a = '<a href=\'' + href + '\'>' + ad.title + '</a>'; ad.a = a; ad.i = i; htmlPage += '<div class=\'' + colOrder[5].class + '\'>' + moment(ad[colOrder[5].id]).format('MMM Do') + '</div>'; htmlPage += '<div class=\'' + colOrder[0].class + '\'>' + ad[colOrder[0].id] + '</div>'; htmlPage += '<div class=\'' + colOrder[2].class + '\'>' + ad[colOrder[2].id] + '</div>'; htmlPage += '<div class=\'col-md-9 col-lg-9\'>'; htmlPage += '<div class=\'' + colOrder[1].class + '\'>' + ad[colOrder[1].id] + '</div>'; htmlPage += '<div class=\'' + colOrder[3].class + '\'>' + ad[colOrder[3].id] + '</div>'; htmlPage += '<div class=\'' + colOrder[4].class + '\'>' + ad[colOrder[4].id] + '</div>'; htmlPage += '<div class=\'' + colOrder[6].class + '\'>' + ad[colOrder[6].id] + '</div>'; htmlPage += '<div class=\'' + colOrder[7].class + '\'>' + ad[colOrder[7].id] + '</div>'; htmlPage += '</div>'; htmlPage += '</div>'; }); }); }); htmlPage += '<a href="#" class="back-to-top2">Back to Top</a>'; htmlPage += '</div></body></html>'; return htmlPage; };
return { name: domain[0], metrics: domain[1] }; }), 'name' ); }, requestMeasures () { const that = this; const url = window.baseUrl + '/api/resources'; const metrics = this.getMetrics(); const options = { resource: this.model.key(), metrics: _.pluck(metrics, 'key').join() }; return $.get(url, options).done(function (data) { const measuresList = data[0].msr || []; let measures = that.model.get('measures') || {}; measuresList.forEach(function (m) { const metric = _.findWhere(metrics, { key: m.key }); metric.value = m.frmt_val || m.data; measures[m.key] = m.frmt_val || m.data; measures[m.key + '_raw'] = m.val; }); measures = that.calcAdditionalMeasures(measures); that.model.set({ measures, measuresToDisplay: that.prepareMetrics(metrics) });
_.each(_.where(ast.stylesheet.rules, {type: 'rule'}), function (rule) { var decls = _.where(rule.declarations, {type: 'declaration'}); var declPairs = _.zip( _.pluck(decls, 'property'), _.pluck(decls, 'value') ); var declInfo = _.object(declPairs); var curAssertion, declString; _.each(rule.selectors, function (sel) { var selInfo = parseSelector(sel); if (!selInfo) { throw new Error("Can't understand selector: " + sel); } var curModule = _.findWhere(modules, {module: selInfo.module}); if (!curModule) { curModule = {module: selInfo.module, tests: []}; modules.push(curModule); } var curTest = _.findWhere(curModule.tests, {test: selInfo.test}); if (!curTest) { curTest = {test: selInfo.test, assertions: []}; curModule.tests.push(curTest); } if (selInfo.output) { curAssertion = _.findWhere( curTest.assertions, {description: selInfo.assert}); if (!curAssertion) { curAssertion = { description: selInfo.assert, assert: 'equal', }; curTest.assertions.push(curAssertion); } declString = _.map(declPairs, function (pair) { return pair[0] + ': ' + pair[1] + ';'; }).join(' '); if (selInfo.type === 'input') { curAssertion.returned = declString; } else { // if (selInfo.type == 'expect') { curAssertion.expected = declString; } if (curAssertion.returned && curAssertion.expected) { curAssertion.passed = curAssertion.returned === curAssertion.expected; } } else { curAssertion = { assert: selInfo.assert, description: (declInfo['-description'] || '""').slice(1, -1), passed: declInfo['-result'] === 'PASS', }; _.each(_.pairs(declInfo), function (pair) { if (_.contains(['-expected--', '-returned--'], pair[0].slice(0, 11))) { var attr = pair[0].slice(1, 9); var type = pair[0].slice(11); var val = pair[1]; curAssertion[attr] = type + ': ' + val; } }); curTest.assertions.push(curAssertion); } }); });
UnderdogModel.find({}).populate("parent").sort({"parent.viewcount": -1}).limit(20).exec(function (err, posts) { questionArr = _.pluck(posts, 'parentQuestionId'); createVoteHistoryPlot(questionArr[0]); });
.then(function(result) { expect(result.mainModuleId).toEqual('index'); expect(result.dependencies[result.dependencies.length - 1]).toBe(module); expect(_.pluck(Polyfill.mock.calls, 0)).toEqual([ { path: 'polyfills/prelude.js', id: 'polyfills/prelude.js', isPolyfill: true, dependencies: [] }, { path: 'polyfills/require.js', id: 'polyfills/require.js', isPolyfill: true, dependencies: ['polyfills/prelude.js'] }, { path: 'polyfills/polyfills.js', id: 'polyfills/polyfills.js', isPolyfill: true, dependencies: ['polyfills/prelude.js', 'polyfills/require.js'] }, { id: 'polyfills/console.js', isPolyfill: true, path: 'polyfills/console.js', dependencies: [ 'polyfills/prelude.js', 'polyfills/require.js', 'polyfills/polyfills.js' ], }, { id: 'polyfills/error-guard.js', isPolyfill: true, path: 'polyfills/error-guard.js', dependencies: [ 'polyfills/prelude.js', 'polyfills/require.js', 'polyfills/polyfills.js', 'polyfills/console.js' ], }, { id: 'polyfills/String.prototype.es6.js', isPolyfill: true, path: 'polyfills/String.prototype.es6.js', dependencies: [ 'polyfills/prelude.js', 'polyfills/require.js', 'polyfills/polyfills.js', 'polyfills/console.js', 'polyfills/error-guard.js' ], }, { id: 'polyfills/Array.prototype.es6.js', isPolyfill: true, path: 'polyfills/Array.prototype.es6.js', dependencies: [ 'polyfills/prelude.js', 'polyfills/require.js', 'polyfills/polyfills.js', 'polyfills/console.js', 'polyfills/error-guard.js', 'polyfills/String.prototype.es6.js', ], }, ]); });
var PatchLoadError = exports.PatchLoadError = function PatchLoadError(errorList) { this.name = 'PatchLoadError' this.errorList = errorList this.message = _.pluck(errorList, 0).join('\n') this.stack = (new Error()).stack }
}).then(function(games){ return _.pluck(games, 'values'); }).catch(function(err){
form.parse(req, function(err, fields, files) { res.writeHead(200, {'content-type': 'application/json; charset=UTF-8'}); var desc = _.pluck(parts, 'name'); var resp = { 'MultipartTestResponse' : { 'parts' : desc }}; res.end(JSON.stringify(resp)); });
}).then(function(users){ if(notValues) return users; return _.pluck(users, 'values'); }).catch(function(err){
this.getClients = function() { return _.pluck(clients, 'aid'); }
}).then(function(comps){ if(notValues) return comps; return _.pluck(comps, 'values'); }).catch(function(err){
case 'msgs': options.sort = { msgs: -1 }; } } const roomTypes = []; if (channelType !== 'private') { if (RocketChat.authz.hasPermission(Meteor.userId(), 'view-c-room')) { roomTypes.push({ type: 'c' }); } else if (RocketChat.authz.hasPermission(Meteor.userId(), 'view-joined-room')) { const roomIds = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('c', Meteor.userId()).fetch(), 'rid'); roomTypes.push({ type: 'c', ids: roomIds }); } } if (channelType !== 'public' && RocketChat.authz.hasPermission(Meteor.userId(), 'view-p-room')) { const user = Meteor.user(); const userPref = RocketChat.getUserPreference(user, 'mergeChannels') && RocketChat.getUserPreference(user, 'roomsListExhibitionMode') === 'category'; const globalPref = RocketChat.settings.get('UI_Merge_Channels_Groups'); const mergeChannels = userPref !== undefined ? userPref : globalPref; if (mergeChannels) { roomTypes.push({
}).then(function(moderators){ return _.extend({}, comp.values, { members: _.pluck(members, 'values'), moderators: _.pluck(moderators, 'values') }); });
}).then(function (draftOrder) { assert.equal(draftOrder.length, 60); draftResults = _.pluck(draftOrder, "originalTid"); userPick1 = draftResults.indexOf(g.userTid) + 1; userPick2 = draftResults.lastIndexOf(g.userTid) + 1; });
_.each(tempData[0], function (value, key) { barData[keys[i]][key] = helpers.nullPad(_.pluck(_.pluck(tempData, key), "amount"), showInt); });
LibSynphony.prototype.selectGPCWordNamesWithArrayCompare = function(aDesiredGPCs, aKnownGPCs, restrictToKnownGPCs, allowUpperCase, aSyllableLengths, aSelectedGroups, aPartsOfSpeech) { var gpcs = theOneLibSynphony.selectGPCWordsWithArrayCompare(aDesiredGPCs, aKnownGPCs, restrictToKnownGPCs, allowUpperCase, aSyllableLengths, aSelectedGroups, aPartsOfSpeech); return _.pluck(gpcs, 'Name'); };
exports.pushTokensForUser(userId, function(err, pushes){ if (err) return next(err); var tokens = _.pluck(pushes, 'token'); apn.sendPush(tokens, message, payload, next); });
countlyMetric.getData = function (segment, clean, join) { if(segment){ var dataProps = [ { name:segment, func:function (rangeArr, dataObj) { rangeArr = countlyCommon.decode(rangeArr); if(fetchValue && !clean) return fetchValue(rangeArr); else return rangeArr; } }]; //add metrics for(var i = 0; i < _metrics.length; i++){ dataProps.push({"name":_metrics[i]}); } var chartData = countlyCommon.extractTwoLevelData(_Db, this.getMeta(segment), this.clearObject, dataProps, _totalUsersObj); chartData.chartData = countlyCommon.mergeMetricsByName(chartData.chartData, segment); chartData.chartData.sort(function(a,b){return b[_metrics[0]]-a[_metrics[0]]}) var namesData = _.pluck(chartData.chartData, segment), otherData = {}; for(var i = 0; i < _metrics.length; i++){ otherData[_metrics[i]] = _.pluck(chartData.chartData, _metrics[i]); } if(join){ chartData.chartDP = {ticks:[]}; var chartDP = []; for(var i = 0; i < _metrics.length; i++){ chartDP.push({data:[], label:_metrics[i]}); chartDP[i]["data"][0] = [-1, null]; chartDP[i]["data"][namesData.length + 1] = [namesData.length, null]; } chartData.chartDP.ticks.push([-1, ""]); chartData.chartDP.ticks.push([namesData.length, ""]); for (var i = 0; i < namesData.length; i++) { for(var j = 0; j < _metrics.length; j++){ chartDP[j]["data"][i + 1] = [i, otherData[_metrics[i]]]; } chartData.chartDP.ticks.push([i, namesData[i]]); } chartData.chartDP.dp = chartDP; } else{ for(var j = 0; j < _metrics.length; j++){ var chartData2 = []; var sum = _.reduce(otherData[_metrics[j]], function (memo, num) { return memo + num; }, 0); for (var i = 0; i < namesData.length; i++) { var percent = (otherData[_metrics[j]][i] / sum) * 100; chartData2[i] = {data:[ [0, otherData[_metrics[j]][i]] ], label:namesData[i]}; } chartData["chartDP"+_metrics[j]] = {}; chartData["chartDP"+_metrics[j]].dp = chartData2; } } return chartData; } else{ //try to fetch higher level data without segments var chartData = [], dataProps = []; for(var i = 0; i < _metrics.length; i++){ chartData.push({ data:[], label:_metrics[i]}); dataProps.push({ name:_metrics[i] }); } return countlyCommon.extractChartData(this.getDb(), this.clearObject, chartData, dataProps); } };
function (cb) { error = validate(input, definition) || helper.checkUniqueIds(_.pluck(input, 'id')); cb(error); }, function (cb) {
module.exports = function( grunt ) { "use strict"; var _ = require( "underscore" ), cheerio = require( "cheerio" ), replaceCombinedCssReference = function( href, processedName ) { return href .replace( /^css/, "demos/css") .replace( /\.\.\/css/, "css" ) .replace( /jquery\.mobile\.css/, processedName + ".min.css" ); }, processDemos = function( content, srcPath ) { var processedName, $; content = content.replace( /^\s*<\?php include\(\s*['"]([^'"]+)['"].*$/gmi, function( match, includePath /*, offset, string */ ) { var newSrcPath = srcPath; // If we've already handled the nested includes use the version // that was copied to the dist folder // TODO use the config from copy:demos.nested.files if( includePath.match(/jqm\-(contents|navmenu|search)\.php/) ) { newSrcPath = "dist/" + newSrcPath; } return grunt.file.read( path.resolve( path.join( path.dirname( newSrcPath ), includePath ) ) ); } ); if ( content.substring( 0, 15 ).toLowerCase() === "<!doctype html>" || srcPath.match( /\.php$/ ) ) { processedName = grunt.config.process( name + "<%= versionSuffix %>" ); $ = cheerio.load( content ); $( "script" ).each( function() { var text, element = $( this ), src = element.attr( "src" ); if ( src ) { element.attr( "src", src .replace( /_assets\/js\/?$/, "_assets/js/index.js" ) .replace( /\.\.\/external\/jquery\/jquery.js$/, "js/jquery.js" ) .replace( /\.\.\/js\/?$/, "js/" + processedName + ".min.js" ) .replace( /external\/jquery\/jquery.js$/, "demos/js/jquery.min.js" ) .replace( /^js\/?$/, "demos/js/" + processedName + ".min.js" ) ); } else { text = element.text(); // References to stylesheets via grunticon need to be updated text = text.replace( /(grunticon\( \[([^\]]*))/, function( match, group ) { var index, offset = group.indexOf( "[" ), prefix = group.substring( 0, offset + 1 ); group = group.substring( offset + 1 ).split( "," ); for ( index in group ) { group[ index ] = "\"" + group[ index ] .trim() .replace( /(^['"])|(['"]$)/g, "" ) .replace( /\.\.\/css\//, "css/" ) .replace( /\.css$/, ".min.css" ) + "\""; } return prefix + " " + group.join( "," ) + " "; }); //element.html( text ); element[ 0 ].children[ 0 ].data = text; } }); $( "link[rel='stylesheet'][href]" ).each( function() { var element = $( this ); element.attr( "href", replaceCombinedCssReference( element.attr( "href" ), processedName ) // Demos that separately refer to the structure need to be // processed here .replace( /css\/structure\/jquery\.mobile\.structure\.css/gi, path.join( "css", "themes", "default", grunt.config.process( name + ".structure" + "<%= versionSuffix %>" ) + ".min.css" ) ) // References to the icons CSS file need to be processed here .replace( /css\/themes\/default\/jquery\.mobile\.icons\.css/, path.join( "css/themes/default", "jquery.mobile.icons.min.css" ) )); }); $( "a[href]" ).each( function() { var element = $( this ); element.attr( "href", element.attr( "href" ).replace( /\.php$/, ".html" ) ); }); content = $.html(); } return content; }, path = require( "path" ), httpPort = Math.floor( 9000 + Math.random()*1000 ), phpPort = Math.floor( 8000 + Math.random()*1000 ), name = "jquery.mobile", dist = "dist" + path.sep, copyrightYear = grunt.template.today( "UTC:yyyy" ), banner = { normal: [ "/*!", "* jQuery Mobile <%= version %>", "* <%if ( headHash ) {%>Git HEAD hash: <%= headHash %> <> <% } %>Date: " + grunt.template.today( "UTC:ddd mmm d yyyy HH:MM:ss Z" ), "* http://jquerymobile.com", "*", "* Copyright 2010, " + copyrightYear + " jQuery Foundation, Inc. and other" + " contributors", "* Released under the MIT license.", "* http://jquery.org/license", "*", "*/", "", "", "" ].join( grunt.util.linefeed ), minified: "/*! jQuery Mobile <%= version %> | <%if ( headShortHash ) {%>Git HEAD" + "hash: <%= headShortHash %> <> <% } %>" + grunt.template.today( "UTC:yyyy-mm-dd" ) + "T" + grunt.template.today( "UTC:HH:MM:ss" ) + "Z | (c) 2010, " + copyrightYear + " jQuery Foundation, Inc. | jquery.org/license */\n" }, dirs = { dist: dist, cdn: { google: path.join( dist, "cdn-google" ), jquery: path.join( dist, "cdn" ), git: path.join( dist, "git" ) }, tmp: path.join( dist, "tmp" ) }, files = { css: { structure: { src: "css/structure/jquery.mobile.structure.css", unminified: name + ".structure<%= versionSuffix %>.css" }, theme: { src: "css/themes/default/jquery.mobile.theme.css", unminified: name + ".theme<%= versionSuffix %>.css" }, bundle: { src: "css/themes/default/jquery.mobile.css", unminified: name + "<%= versionSuffix %>.css" }, inlinesvg: { src: "css/themes/default/jquery.mobile.inline-svg.css", unminified: name + ".inline-svg<%= versionSuffix %>.css" }, inlinepng: { src: "css/themes/default/jquery.mobile.inline-png.css", unminified: name + ".inline-png<%= versionSuffix %>.css" }, externalpng: { src: "css/themes/default/jquery.mobile.external-png.css", unminified: name + ".external-png<%= versionSuffix %>.css" }, icons: { src: "css/themes/default/jquery.mobile.icons.css", unminified: name + ".icons<%= versionSuffix %>.css" } }, getCSSFiles: function( destDir ) { destDir = destDir || "."; var list = []; _.values( files.css ).forEach( function( value ) { list.push({ src: value.src, dest: path.join( destDir, value.unminified ) }); }); return list; }, getMinifiedCSSFiles: function( destDir ) { destDir = destDir || "."; var list = []; _.values( files.css ).forEach( function( value ) { list.push({ src: path.join( destDir, value.unminified ), dest: path.join( destDir, value.minified ) }); }); return list; }, cdn: [ name + "<%= versionSuffix %>.js", name + "<%= versionSuffix %>.min.js", name + "<%= versionSuffix %>.min.map", "<%= files.css.structure.unminified %>", "<%= files.css.structure.minified %>", "<%= files.css.bundle.unminified %>", "<%= files.css.bundle.minified %>", "<%= files.css.inlinesvg.unminified %>", "<%= files.css.inlinesvg.minified %>", "<%= files.css.inlinepng.unminified %>", "<%= files.css.inlinepng.minified %>", "<%= files.css.externalpng.unminified %>", "<%= files.css.externalpng.minified %>", "<%= files.css.icons.unminified %>", "<%= files.css.icons.minified %>", "images/*.*", "images/icons-png/**" ], distZipContent: [ "<%= files.cdn %>", "<%= files.css.theme.unminified %>", "<%= files.css.theme.minified %>", "images/icons-svg/**", "demos/**" ], zipFileName: name + "<%= versionSuffix %>.zip", distZipOut: path.join( dist, name + "<%= versionSuffix %>.zip" ), imagesZipOut: path.join( dist, name + ".images<%= versionSuffix %>.zip" ), googleCDNZipOut: path.join( "<%= dirs.cdn.google %>","<%= files.zipFileName %>" ) }; // Add minified property to files.css.* _.forEach( files.css, function( o ) { o.minified = o.unminified.replace( /\.css$/, ".min.css" ); }); // Project configuration. grunt.config.init({ pkg: grunt.file.readJSON( "package.json" ), version: "<%= pkg.version %>", versionSuffix: "", headHash: "", headShortHash: "", dirs: dirs, files: files, jshint: { js: { options: { jshintrc: "js/.jshintrc" }, files: { src: [ "js/**/*.js", "!js/jquery.js", "!js/jquery.ui.widget.js", "!js/widgets/jquery.ui.tabs.js", "!js/jquery.ui.core.js" ] } }, grunt: { options: { jshintrc: ".jshintrc" }, files: { src: [ "Gruntfile.js" ] } } }, requirejs: { js: { options: { baseUrl: "js", optimize: "none", //Finds require() dependencies inside a require() or define call. findNestedDependencies: true, //If skipModuleInsertion is false, then files that do not use define() //to define modules will get a define() placeholder inserted for them. //Also, require.pause/resume calls will be inserted. //Set it to true to avoid this. This is useful if you are building code that //does not use require() in the built project or in the JS files, but you //still want to use the optimization tool from RequireJS to concatenate //modules together. skipModuleInsertion: true, mainConfigFile: "js/requirejs.config.js", include: [ "jquery.mobile" ], exclude: [ "jquery", "json", "json!../package.json" ], out: path.join( dist, name ) + "<%= versionSuffix %>.js", pragmasOnSave: { jqmBuildExclude: true }, //File paths are relative to the build file, or if running a commmand //line build, the current directory. wrap: { startFile: "build/wrap.start", endFile: "build/wrap.end" }, onBuildWrite: function (moduleName, path, contents) { return contents.replace(/__version__/g, grunt.config.process( "\"<%= version %>\"" )); } } } }, concat: { js: { options: { banner: banner.normal }, src: [ path.join( dist, name ) + "<%= versionSuffix %>.js" ], dest: path.join( dist, name ) + "<%= versionSuffix %>.js" }, demos: { src: [ "demos/_assets/js/*.js" ], dest: path.join( dist, "demos/_assets/js/index.js" ) } }, uglify: { all: { options: { banner: banner.minified, sourceMap: path.join( dist, name ) + "<%= versionSuffix %>.min.map", sourceMappingURL: name + "<%= versionSuffix %>.min.map", beautify: { ascii_only: true } }, files: { "dist/jquery.mobile<%= versionSuffix %>.min.js": path.join( dist, name ) + "<%= versionSuffix %>.js" } } }, cssbuild: { options: { banner: banner.normal, //Allow CSS optimizations. Allowed values: //- "standard": @import inlining, comment removal and line returns. //Removing line returns may have problems in IE, depending on the type //of CSS. //- "standard.keepLines": like "standard" but keeps line returns. //- "none": skip CSS optimizations. //- "standard.keepComments": keeps the file comments, but removes line //returns. (r.js 1.0.8+) //- "standard.keepComments.keepLines": keeps the file comments and line //returns. (r.js 1.0.8+) optimizeCss: "standard.keepComments.keepLines", //If optimizeCss is in use, a list of of files to ignore for the @import //inlining. The value of this option should be a string of comma separated //CSS file names to ignore (like 'a.css,b.css'. The file names should match //whatever strings are used in the @import calls. cssImportIgnore: null }, all: { files: files.getCSSFiles( dist ) } }, cssmin: { options: { banner: banner.minified, keepSpecialComments: 0 }, minify: { files: files.getMinifiedCSSFiles( dist ) } }, copy: { images: { expand: true, cwd: "css/themes/default/images", src: "**", dest: path.join( dist, "images/" ) }, "demos.nested-includes": { options: { // TODO duplicated in demos.firstpass processContent: function( content, srcPath ) { content = content.replace( /^\s*<\?php include\(\s*['"]([^'"]+)['"].*$/gmi, function( match, includePath /*, offset, string */ ) { var fileToInclude = path.resolve( path.join( path.dirname( srcPath ), includePath ) ); return grunt.file.read( fileToInclude ); } ); return content; } }, files: [ { expand: true, src: [ "demos/jqm-contents.php", "demos/jqm-navmenu.php", "demos/jqm-search.php" ], dest: dist } ] }, "demos.processed": { options: { processContent: function( content, srcPath ) { return processDemos( content, srcPath ); } }, files: [ { expand: true, src: [ "index.php", "demos/**/*.php", "demos/**/*.html", "!demos/navigation-php-redirect/**", "demos/navigation-php-redirect/index.php" ], dest: dist, ext: ".html" } ] }, "demos.php": { options: { processContent: function( content, srcPath ) { return processDemos( content, srcPath ); } }, files: [ { expand: true, src: [ "demos/navigation-php-redirect/*.php", "!demos/navigation-php-redirect/index.php", "demos/page-events/*.php", "!demos/page-events/index.php" ], dest: dist } ] }, "demos.backbone": { options: { processContent: function( content, srcPath ) { var $, processedName = grunt.config.process( name + "<%= versionSuffix %>" ); if ( /\.html$/.test( srcPath ) ) { $ = cheerio.load( content ); $( "link[rel='stylesheet'][href]" ).each( function() { var element = $( this ); element.attr( "href", replaceCombinedCssReference( element.attr( "href" ), processedName ) ); }); $( "script" ).each( function ( idx, element ) { var script = $( element ); if ( /requirejs\.config\.js$/.test( script.attr( "src" ) ) ) { // Get rid of the requirejs.config.js script tag since we're // using the built bundle script.remove(); } else if ( /require.js$/.test( script.attr( "src" ) ) ) { // Use the CDN version for requirejs script.attr( "src", "//cdn.jsdelivr.net/requirejs/" + grunt. template. process( "<%= pkg.devDependencies.requirejs %>" ) + "/require.min.js" ); } }); // write out newly created file contents content = $.html(); } else if ( /\.js$/.test( srcPath ) ) { // Redifines paths for compiled demos content = content.replace( /baseUrl:.*$/m, "baseUrl: \"../js\"," ); content = content.replace( /\.\.\/external\/jquery\//, "" ); content = content.replace( /jquery\.mobile/, processedName ); content = content.replace( /"backbone-requirejs-demos".*$/m, "\"backbone-requirejs-demos\": \"../backbone-requirejs/js\"" ); } return content; } }, files: [ { expand: true, src: [ "demos/backbone-requirejs/**/*", "!demos/backbone-requirejs/index.php" ], dest: dist } ] }, "demos.unprocessed": { files: [ { expand: true, cwd: "external/jquery", src: [ "jquery.js", "jquery.min.js", "jquery.min.map.js" ], dest: path.join( dist, "demos/js/" ) }, { expand: true, cwd: dist, src: [ "*.js", "*.map" ], dest: path.join( dist, "demos/js/" ) }, { expand: true, cwd: dist, src: [ "images/**" ].concat( _.pluck( files.getMinifiedCSSFiles(), "dest" ) ), dest: path.join( dist, "demos/css/themes/default/" ) }, { expand: true, src: [ "demos/**/*", "!**/*.php", "!**/*.html", "!demos/backbone-requirejs/js/*" ], dest: dist } ] }, sourcemap: { // Processes the sourceMap to fix // issue: https://github.com/mishoo/UglifyJS2/issues/47 options: { processContent: function( content /*, srcPath*/ ) { content = content.replace( /"dist\//g, "\"" ); return content; } }, files: [ { src: "<%= uglify.all.options.sourceMap %>", dest: "<%= uglify.all.options.sourceMap %>" } ] }, "jqueryCDN": { files: [{ expand: true, cwd: dist, src: "<%= files.cdn %>", dest: "<%= dirs.cdn.jquery %>/" }] }, "googleCDN": { options: { processContent: function( content, srcPath ) { if ( /\.min.js$|\.min.map$/.test( srcPath ) ) { // We need to rewrite the map info var re = new RegExp( grunt.template.process( "<%= versionSuffix %>" ), "g" ); content = content.replace( re, "" ); } return content; }, processContentExclude: [ "**/*.+(gif|png)" ] }, files: { // WARNING: This will be modified by the config:copy:noversion task cwd: dist, src: "<%= files.cdn %>", dest: "<%= dirs.tmp %>" } }, git: { options: { processContent: function( content, srcPath ) { if ( /\.min.js$|\.min.map$/.test( srcPath ) ) { // We need to rewrite the map info var re = new RegExp( grunt.template.process( name ), "g" ); content = content.replace( re, name + "-git" ); } return content; }, processContentExclude: [ "**/*.zip", "**/*.gif", "**/*.png" ] }, files: { // WARNING: This will be modified by the config:copy:git task cwd: dist, src: "<%= files.cdn %>", dest: "<%= dirs.cdn.git %>" } } }, "hash-manifest": { googleCDN: { options: { algo: "md5", cwd: "<%= dirs.tmp %>" }, src: [ "**/*" ], dest: "MANIFEST" } }, compress: { dist: { options: { archive: "<%= files.distZipOut %>" }, files: [ { expand: true, cwd: dist, src: "<%= files.distZipContent %>" } ] }, images: { options: { archive: "<%= files.imagesZipOut %>" }, files: [ { expand: true, cwd: dist, src: [ "images/**" ] } ] }, "googleCDN": { options: { archive: "<%= files.googleCDNZipOut %>" }, files: [ { expand: true, cwd: "<%= dirs.tmp %>", src: [ "**/*" ] } ] } }, php: { server: { options: { port: phpPort, baseUrl: "." } } }, casper: { options: { test: true, verbose : true, "log-level": "error", parallel: false }, "demos.src": { options: { args: [ "--port=" + phpPort ] }, src: [ "tests/casperjs/**/*.js" ] }, "demos.dist": { options: { args: [ "--port=" + phpPort , "--path=dist" ] }, src: [ "tests/casperjs/**/*.js" ] } }, connect: { server: { options: { port: httpPort, base: ".", middleware: function( connect, options ) { return [ // For requests to "[...]/js/" return the built jquery.mobile.js // as opposed to the php combined version function(req, res, next){ var bundle = grunt.config.process( "<%= requirejs.js.options.out %>" ); if (req.url === "/js/") { grunt.log.debug( req.url + " requested, serving: " + bundle ); res.end( grunt.file.read( bundle ) ); } else { next(); } }, // Serve static files. connect[ "static" ](options.base), // Make empty directories browsable. connect.directory(options.base) ]; } } } }, qunit_junit: { options: { dest: "build/test-results", namer: function (url) { var match = url.match(/tests\/([^\/]*)\/(.*)$/); return match[2].replace(/\//g, ".").replace(/\.html/, "" ).replace(/\?/, "-"); } } }, qunit: { options: { timeout: 30000, "--web-security": "no", coverage: { baseUrl: ".", src: [ "js/**/*.js", "!js/jquery.tag.inserter.js", "!js/requirejs.config.js" ], instrumentedFiles: "temp/", htmlReport: "_tests/reports/coverage", lcovReport: "_tests/reports/lcov", linesThresholdPct: 0 } }, http: { options: { urls: (function() { var allSuites, patterns, paths, testDirs = [ "unit", "integration", "css" ], suites = ( grunt.option( "suites" ) || process.env.SUITES || "" ) .split( "," ), types = ( grunt.option( "types" ) || process.env.TYPES || "" ) .split( "," ), versionedPaths = [], jQueries = ( grunt.option( "jqueries" ) || process.env.JQUERIES || "" ) .split( "," ), excludes = _.chain( suites ) .filter( function( suite ) { return ( /^!/.test( suite ) ); } ) .map( function( suite ) { return suite.substring( 1 ); } ) .value(); // Trim empties suites = _.without( suites, "" ); types = _.without( types, "" ); jQueries = _.without( jQueries, "" ); // So that unit suites runs before integration suites types = types.sort().reverse(); allSuites = _.chain( grunt.file.expand( { filter: "isDirectory", cwd: "tests" }, _.map( testDirs, function( dir ) { return dir + "/*"; }) )) .map( function( dir ) { return dir.split( "/" )[ 1 ]; } ) .difference( excludes ) .unique() .value(); // Remove negations from list of suites suites = _.filter( suites, function( suite ) { return ( !/^!/.test( suite ) ); }); if ( types.length ){ testDirs = []; types.forEach(function( type ) { testDirs.push( type ); }); } patterns = []; if ( !suites.length ) { suites = allSuites; } _.chain( suites ) .difference( excludes ) .forEach( function( suite ) { testDirs.forEach( function( dir ) { dir = "tests/" + dir; if ( suite.indexOf( "/" ) >= 0 ) { // If the suite is a path, then append it exactly patterns.push( dir + "/" + suite ); } else { // If not, append all patterns we care about patterns = patterns.concat([ dir + "/" + suite + "/index.html", dir + "/" + suite + "/*/index.html", dir + "/" + suite + "/**/*-tests.html" ]); } }); }); paths = grunt.file.expand( patterns ) .filter( function( testPath ) { if ( grunt.file.isDir( testPath ) ) { testPath = path.join( testPath, "index.html" ); } return grunt.file.exists( testPath ); }) .map( function( path ) { // Some of our tests (ie. navigation) don't like having the // index.html too much return path.replace( /\/index.html$/, "/" ); }); paths = grunt.util._.uniq( paths ); if ( jQueries.length ) { paths.forEach( function( path ) { versionedPaths = versionedPaths.concat( jQueries.map( function( jQVersion ) { return path + "?jquery=" + jQVersion; }) ); }); } if ( versionedPaths.length ) { paths = versionedPaths; } return paths.map( function( path ) { return "http://localhost:<%= connect.server.options.port %>/" + path; }); }()) } } }, coveralls: { options: { force: true }, all: { // LCOV coverage file relevant to every target src: "_tests/reports/lcov/lcov.info" } }, bowercopy: { options: { // Bower components folder will be removed afterwards clean: true, destPrefix: "external" }, tests: { files: { "qunit/qunit.js": "qunit/qunit/qunit.js", "qunit/qunit.css": "qunit/qunit/qunit.css", "qunit/LICENSE.txt": "qunit/LICENSE.txt", "jshint/jshint.js": "jshint/dist/jshint.js" } }, requirejs: { files: { "requirejs/require.js": "requirejs/require.js", "requirejs/plugins/text.js": "requirejs-text/text.js", "requirejs/plugins/json.js": "requirejs-plugins/src/json.js" } }, jquery: { files: { "jquery/": "jquery/dist/" } }, "jquery-ui": { options: { copyOptions: { process: function( content ) { var version = grunt .file .readJSON( "bower.json" ) .dependencies[ "jquery-ui" ]; if ( /#/.test( version ) ) { version = version.split( "#" )[ 1 ]; } return content.replace( /@VERSION/g, version ); } } }, files: { "jquery-ui/jquery.ui.core.js": "jquery-ui/ui/jquery.ui.core.js", "jquery-ui/jquery.ui.widget.js": "jquery-ui/ui/jquery.ui.widget.js", "jquery-ui/jquery.ui.tabs.js": "jquery-ui/ui/jquery.ui.tabs.js", "jquery-ui/MIT-LICENSE.txt": "jquery-ui/MIT-LICENSE.txt" } }, }, clean: { dist: [ dist ], git: [ path.join( dist, "git" ) ], tmp: [ "<%= dirs.tmp %>" ], testsOutput: [ "_tests" ], "googleCDN": [ "<%= dirs.cdn.google %>" ], "jqueryCDN": [ "<%= dirs.cdn.jquery %>" ] } }); // grunt plugins require( "load-grunt-tasks" )( grunt ); // load the project's default tasks grunt.loadTasks( "build/tasks"); grunt.registerTask( "release:init", function() { // Set the version suffix for releases grunt.config.set( "versionSuffix", "-<%= pkg.version%>" ); }); grunt.registerTask( "lint", [ "jshint" ] ); grunt.registerTask( "changelog", ["changelog:create"] ); grunt.registerTask( "js", [ "requirejs", "concat:js" ] ); grunt.registerTask( "js:release", [ "js", "uglify", "copy:sourcemap" ] ); grunt.registerTask( "css", [ "cssbuild" ] ); grunt.registerTask( "css:release", [ "css", "cssmin" ] ); grunt.registerTask( "demos", [ "concat:demos", "copy:images", "copy:demos.nested-includes", "copy:demos.processed", "copy:demos.php", "copy:demos.unprocessed", "copy:demos.backbone" ]); grunt.registerTask( "cdn", [ "release:init", "clean:jqueryCDN", "copy:jqueryCDN", "clean:tmp", "config:copy:googleCDN", "copy:googleCDN", "hash-manifest:googleCDN", "compress:googleCDN", "clean:tmp" ]); grunt.registerTask( "dist", [ "modules", "clean:dist", "config:fetchHeadHash", "js:release", "css:release", "demos", "compress:dist", "compress:images", "clean:tmp" ]); grunt.registerTask( "dist:release", [ "release:init", "dist", "cdn" ] ); grunt.registerTask( "dist:git", [ "dist", "clean:git", "config:copy:git:-git", "copy:git" ] ); grunt.registerTask( "updateDependencies", [ "bowercopy" ] ); grunt.registerTask( "test:demos:src", [ "php", "casper:demos.src" ] ); grunt.registerTask( "test:demos:dist", [ "casper:demos.dist" ] ); grunt.registerTask( "test", [ "clean:dist", "clean:testsOutput", "jshint", "config:fetchHeadHash", "js:release", "css:release", "demos", "connect", "qunit:http" ] ); grunt.registerTask( "crawl", [ "test:demos:src", "test:demos:dist" ] ); grunt.registerTask( "test:ci", [ "qunit_junit", "connect", "qunit:http" ] ); // Default grunt grunt.registerTask( "default", [ "dist" ] ); };
it('returns the tasks for a given user', function () { assert.deepEqual(_.pluck(users.get(0).rel('tasks'), 'id'), [2, 4]); assert.deepEqual(_.pluck(users.get(1).rel('tasks'), 'id'), [1, 3, 5]); assert.deepEqual(_.pluck(users.get(2).rel('tasks'), 'id'), []); });