Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb committed Mar 17, 2017
1 parent b863b9d commit 5fe374e
Show file tree
Hide file tree
Showing 35 changed files with 315 additions and 381 deletions.
26 changes: 12 additions & 14 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(grunt) {
grunt.initConfig({

// Metadata for tests
pkg : grunt.file.readJSON('package.json'),
pkg: grunt.file.readJSON('package.json'),
config: grunt.file.readJSON('test/fixtures/data/config.json'),
site: grunt.file.readYAML('test/fixtures/data/_site.yml'),

Expand All @@ -30,7 +30,6 @@ module.exports = function(grunt) {
]
},


/**
* Run mocha tests.
*/
Expand All @@ -43,7 +42,6 @@ module.exports = function(grunt) {
}
},


/**
* Assemble examples/tests
*/
Expand All @@ -55,8 +53,8 @@ module.exports = function(grunt) {
layout: 'default.hbs',
flatten: true,
data: {
global1: "globalData1",
global2: "globalData2"
global1: 'globalData1',
global2: 'globalData2'
}
},
// Should render pages with `layout: false` or `layout: none` defined
Expand Down Expand Up @@ -279,10 +277,10 @@ module.exports = function(grunt) {
// Pages collections
pages_array: {
options: {
layout: "post.hbs",
layout: 'post.hbs',
site: {
title: "A Blog",
author: "Jon Schlinkert"
title: 'A Blog',
author: 'Jon Schlinkert'
},
pages: '<%= config.pages.one %>'
},
Expand Down Expand Up @@ -339,10 +337,10 @@ module.exports = function(grunt) {
noyfmdata: {
options: {
data: {
one: "1-one",
two: "2-two",
three: "3-three",
global1: "override global1 data via task option"
one: '1-one',
two: '2-two',
three: '3-three',
global1: 'override global1 data via task option'
}
},
files: {
Expand All @@ -360,9 +358,9 @@ module.exports = function(grunt) {
}
},

// Example config data for "pages_array" and "pages_object" targets
// Example config data for 'pages_array' and 'pages_object' targets
component: {
one: "alert"
one: 'alert'
},

/**
Expand Down
24 changes: 11 additions & 13 deletions lib/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/

var path = require('path');
var _ = require('lodash');

var _ = require('lodash');

/**
* Assemble
Expand All @@ -17,13 +16,13 @@ var _ = require('lodash');
var Assemble = function() {

var engineUtils = require('./engine');
var collection = require('./collection');
var plugins = require('./plugins');
var utils = require('./utils');
var collection = require('./collection');
var plugins = require('./plugins');
var utils = require('./utils');

var steps = [];

var init = function(task, grunt){
var init = function(task, grunt) {

this.grunt = grunt;
this.task = task;
Expand All @@ -49,12 +48,11 @@ var Assemble = function() {
this.options.collections = _.union(['tags', 'categories', { name: 'pages' }], this.options.collections);
this.options.collections = collection.normalize(this.options.collections);


// if there is a pages property and it's an array, turn it into an object
if(this.options.pages && Array.isArray(this.options.pages)) {
if (this.options.pages && Array.isArray(this.options.pages)) {
var pages = {};
_.forEach(this.options.pages, function(page) {
if(page.filename && page.filename.length > 0) {
if (page.filename && page.filename.length > 0) {
pages[page.filename] = page;
}
});
Expand Down Expand Up @@ -84,8 +82,8 @@ var Assemble = function() {
this.grunt.verbose.writeln('Assembling');
var self = this;
this.grunt.verbose.writeln('Steps: ' + steps.length);
if(steps.length === 0) {
if(callback) {
if (steps.length === 0) {
if (callback) {
callback(null, true);
}
return true;
Expand All @@ -94,12 +92,12 @@ var Assemble = function() {
var step = 0, totalSteps = steps.length;
steps[step++](self, function next(assemble) {
assemble.grunt.verbose.writeln('\nStep ' + step + ' assembled.');
if(step < totalSteps) {
if (step < totalSteps) {
assemble.grunt.verbose.writeln('Calling step ' + (step + 1));
steps[step++](self, next);
} else {
assemble.grunt.verbose.writeln('Build completed. Returning');
if(callback) {
if (callback) {
callback(null, true);
}
return true;
Expand Down
44 changes: 21 additions & 23 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ var utils = require('./utils');

var collection = module.exports = {};


collection.update = function(col, page, context) {
'use strict';

if(!context[col.name]) {
if (!context[col.name]) {
return col;
}

var singularName = col.inflection || inflection.singularize(col.name);
var pageCol = context[col.name] || [];
if(utils.toString.call(pageCol) !== '[object Array]') {
if (utils.toString.call(pageCol) !== '[object Array]') {
pageCol = [pageCol];
}

Expand All @@ -34,7 +33,7 @@ collection.update = function(col, page, context) {
return item[singularName] === pageItem;
});

if(i === -1) {
if (i === -1) {
var obj = {};
obj[singularName] = pageItem;
obj.pages = [page];
Expand All @@ -46,10 +45,10 @@ collection.update = function(col, page, context) {
return col;
};

function compare (a, b) {
function compare(a, b) {

if(a && b) {
if(a < b) {
if (a && b) {
if (a < b) {
return -1;
} else if (a > b) {
return 1;
Expand All @@ -58,11 +57,11 @@ function compare (a, b) {
}
} else {
// pages without {sortby} field will at the end of collection
if (!a && !b) {
return 0;
if (!a && !b) {
return 0;
}
if (!a) {
return 1;
if (!a) {
return 1;
}
return -1;
}
Expand All @@ -77,14 +76,14 @@ collection.sort = function(col) {
var sortby = _.contains(itemMap, (col.sortby || '')) ? '' : col.sortby;
var sortorder = _.contains(descMap, (col.sortorder || 'ASC').toLowerCase()) ? 'DESC' : 'ASC';

if(sortby === '') {
if (sortby === '') {

// sort items by the actual item
col.items.sort(function(a, b) {
return compare(a[col.inflection], b[col.inflection]);
});

if(sortorder !== 'ASC') {
if (sortorder !== 'ASC') {
col.items.reverse();
}

Expand All @@ -97,19 +96,19 @@ collection.sort = function(col) {
return compare(a.data[sortby], b.data[sortby]);
});

if(sortorder !== 'ASC') {
if (sortorder !== 'ASC') {
item.pages.reverse();
}

});

// now sort the items by the first page in each item
col.items.sort(function(a, b) {
if(a.pages.length > 0 && b.pages.length > 0) {
if(a.pages[0].data[sortby] && b.pages[0].data[sortby]) {
if(a.pages[0].data[sortby] < b.pages[0].data[sortby]) {
if (a.pages.length > 0 && b.pages.length > 0) {
if (a.pages[0].data[sortby] && b.pages[0].data[sortby]) {
if (a.pages[0].data[sortby] < b.pages[0].data[sortby]) {
return -1;
} else if(a.pages[0].data[sortby] > b.pages[0].data[sortby]) {
} else if (a.pages[0].data[sortby] > b.pages[0].data[sortby]) {
return 1;
} else {
return 0;
Expand All @@ -120,7 +119,7 @@ collection.sort = function(col) {
}
});

if(sortorder !== 'ASC') {
if (sortorder !== 'ASC') {
col.items.reverse();
}

Expand All @@ -130,7 +129,6 @@ collection.sort = function(col) {

};


/**
* Takes in a list of collection definitions and normalizes
* them to a be all objects with smart defaults
Expand All @@ -143,8 +141,8 @@ collection.normalize = function(collections) {
var rtn = {};
collections.forEach(function(item) {

if(typeof item === 'string') {
if(rtn[item]) {
if (typeof item === 'string') {
if (rtn[item]) {
item = rtn[item];
} else {
item = {
Expand All @@ -159,7 +157,7 @@ collection.normalize = function(collections) {
item.items = [];
}

if(item.name === 'pages') {
if (item.name === 'pages') {
item.inflection = '_page';
item.sortby = (item.sortby || '') === '' ? 'name' : item.sortby;
item.items = [{
Expand Down
29 changes: 12 additions & 17 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
*/
'use strict';


var grunt = require('grunt');
var grunt = require('grunt');
var helpers = require('./helpers');


var EngineFactory = function() {

var engineName = '';


var tryRequireEngine = function(eng, obj) {
try {
obj.engine = require('assemble-' + eng);
} catch(e) {
} catch (e) {
try {
obj.engine = require(eng);
} catch(err) {
} catch (err) {
grunt.log.writeln('Error loading engine: ' + eng);
grunt.log.writeln(err);
grunt.log.writeln('Run `npm install assemble-' + eng + '` to use ' + eng);
Expand All @@ -33,26 +29,25 @@ var EngineFactory = function() {
var load = function(eng) {
engineName = eng;
tryRequireEngine(eng, this);
if(!this.engine) {
if (!this.engine) {
return false;
}

// set some defaults
this.startDelimiter = this.engine.startDelimiter || '{{';
this.endDelimiter = this.engine.endDelimiter || '}}';

var search = this.startDelimiter + "\\s*body\\s*" + this.endDelimiter;
var search = this.startDelimiter + '\\s*body\\s*' + this.endDelimiter;
this.bodyRegex = new RegExp(search, 'i');
return this;
};


var init = function(options, params) {
if(typeof this.engine.init === 'function') {
if (typeof this.engine.init === 'function') {
this.engine.init(options, params);
}
if(options && typeof options.helpers !== 'undefined') {
if(!Array.isArray(options.helpers)){
if (options && typeof options.helpers !== 'undefined') {
if (!Array.isArray(options.helpers)) {
options.helpers = [options.helpers];
}
var engineInstance = this.engine[engineName] || this.engine;
Expand All @@ -63,15 +58,15 @@ var EngineFactory = function() {
};

var compile = function(src, options, callback) {
if(typeof this.engine.compile !== 'function') {
if (typeof this.engine.compile !== 'function') {
grunt.log.writeln(engineName, 'does not support compile.');
callback(engineName + ' does not support compile.', null);
}
this.engine.compile(src, options, callback);
};

var render = function(tmpl, options, callback) {
if(typeof this.engine.render !== 'function') {
if (typeof this.engine.render !== 'function') {
grunt.log.writeln(engineName, 'does not support render.');
callback(engineName + ' does not support render.', null);
}
Expand All @@ -80,13 +75,13 @@ var EngineFactory = function() {

// Helpers, filters etc. depending on template engine
var registerFunctions = function(helperFunctions) {
if(typeof this.engine.registerFunctions === 'function') {
if (typeof this.engine.registerFunctions === 'function') {
this.engine.registerFunctions(helperFunctions);
}
};

var registerPartial = function(filename, content) {
if(typeof this.engine.registerPartial === 'function') {
if (typeof this.engine.registerPartial === 'function') {
this.engine.registerPartial(filename, content);
}
};
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module.exports.register = function(patterns, currentEngine, engineInstance, opti
var fn = null;
try {
fn = require(path.resolve(filepath));
if(typeof fn !== 'undefined') {
if (typeof fn !== 'undefined') {
if (typeof fn === 'object' && Object.keys(fn).length >= 1) {
if(typeof fn.register !== 'undefined') {
if (typeof fn.register !== 'undefined') {
fn.register(engineInstance, options, params);
} else {
currentEngine.registerFunctions(fn, options, params);
Expand Down
Loading

0 comments on commit 5fe374e

Please sign in to comment.