Skip to content

Commit

Permalink
refactoring: bug fixing and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 9, 2016
1 parent a65f2c5 commit d951416
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 24 deletions.
17 changes: 10 additions & 7 deletions src/cli/cms/Page.js
Expand Up @@ -94,15 +94,18 @@ export default class Page {

var patAttrSource = new RegExp(' ([A-Za-z0-9\-\_]+)=["|\'].*?({{' + keys[i] + '}}).*?["|\']', 'g')
var patAttrSourceMatch = this.template.match(patAttrSource)
var patAttrSourceInside = null
var patAttrSourceCheck = null
var checkEscaped = null

if(typeof patAttrSourceMatch !== 'undefined' && patAttrSourceMatch !== null) {
var patAttrSourceInside = new RegExp('(\\S+)=["\']?((?:.(?!["\']?\\s+(?:\\S+)=|[>"\']))+.)["\']?({{' + keys[i] + '}}).*?["|\']', 'g')
if(patAttrSourceMatch != null) {
patAttrSourceInside = new RegExp('(\\S+)=["\']?((?:.(?!["\']?\\s+(?:\\S+)=|[>"\']))+.)["\']?({{' + keys[i] + '}}).*?["|\']', 'g')
Array.prototype.forEach.call(patAttrSourceMatch, (pat) => {
var patAttrSourceCheck = patAttrSourceInside.exec(pat)
if(typeof patAttrSourceCheck !== 'undefined' && patAttrSourceCheck !== null) {
patAttrSourceCheck = patAttrSourceInside.exec(pat)
if(patAttrSourceCheck != null) {
var checkEscaped = /["|'](.*?)["|']/
checkEscaped = checkEscaped.exec(patAttrSourceCheck[0])
if(typeof checkEscaped !== 'undefined' && checkEscaped !== null && checkEscaped.length > 0) {
if(checkEscaped != null && checkEscaped.length > 0) {
checkEscaped = escape(checkEscaped[1])
this.template = this.template.replace(
patAttrSourceCheck[0],
Expand Down Expand Up @@ -215,12 +218,12 @@ export default class Page {

// Pour chaque tag Abe, je mets en forme ce tag avec des data- supplémentaires
while (match = this.abePattern.exec(block)) {
this._insertAbeEach(match, key, this.eachBlockPattern.lastIndex - block.length, util)
this._insertAbeEach(match, key, this.eachBlockPattern.lastIndex - block.length)
}

// Pour chaque tag Abe attribut de HTML, je mets en forme ce tag avec des data- supplémentaires sur le tag html parent
while (match = this.abeAsAttributePattern.exec(block)) {
this._insertAbeEach(match, key, this.eachBlockPattern.lastIndex - block.length, util)
this._insertAbeEach(match, key, this.eachBlockPattern.lastIndex - block.length)
}
})

Expand Down
1 change: 1 addition & 0 deletions src/cli/cms/data/file.js
@@ -1,4 +1,5 @@
import path from 'path'
import mkdirp from 'mkdirp'
import fse from 'fs-extra'
import moment from 'moment'

Expand Down
14 changes: 8 additions & 6 deletions src/cli/cms/data/sql.js
Expand Up @@ -112,7 +112,7 @@ export function handleSqlRequest(str, jsonPage) {
}
reconstructSql += `from ${JSON.stringify(from)} `

var where
var where = null
if(request.where != null) {
where = request.where
}
Expand All @@ -122,7 +122,7 @@ export function handleSqlRequest(str, jsonPage) {
limit = request.limit[request.limit.length - 1].value
}

var orderby
var orderby = null
if(request.orderby != null && request.orderby.length > 0) {
orderby = {
column: request.orderby[0].expr.column,
Expand Down Expand Up @@ -338,13 +338,15 @@ export function getSourceType(str) {
export function executeWhereClause(files, wheres, maxLimit, columns, jsonPage){
var res = []
var limit = 0
var json = {}
var jsonValues = {}

for(let file of files) {
if(limit < maxLimit || maxLimit === -1) {
if(wheres != null) {
if(file.publish && !recurseWhere(wheres, file.publish, jsonPage)) {
var json = JSON.parse(JSON.stringify(file.publish))
var jsonValues = {}
json = JSON.parse(JSON.stringify(file.publish))
jsonValues = {}

if(columns != null && columns.length > 0 && columns[0] !== '*') {
Array.prototype.forEach.call(columns, (column) => {
Expand Down Expand Up @@ -379,8 +381,8 @@ export function executeWhereClause(files, wheres, maxLimit, columns, jsonPage){
*/
export function getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc) {
var regexIsVariable = /^{{(.*)}}$/
var value
var compare
var value = null
var compare = null

try {
var variableLeft = where.left.column
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cms/templates/handlebars/notEmpty.js
@@ -1,7 +1,7 @@

/**
*/
export default function notEmpty(variable) {
export default function notEmpty(variable, block) {
if (typeof variable !== 'undefined' && variable !== null && variable !== '') {
return block.fn(this)
}else {
Expand Down
6 changes: 4 additions & 2 deletions src/cli/cms/templates/handlebars/translate-front.js
@@ -1,8 +1,10 @@
import {coreUtils} from '../../../'

export default function translate(lang, str) {
var trad = Locales
var trad = coreUtils.locales.instance.i18n
if(typeof trad[lang] !== 'undefined' && trad[lang] !== null
&& typeof trad[lang][str] !== 'undefined' && trad[lang][str] !== null) {
return trad[lang][str]
}
return str
}
}
1 change: 0 additions & 1 deletion src/cli/cms/templates/handlebars/translate.js
Expand Up @@ -8,4 +8,3 @@ export default function translate(lang, str) {
}
return str
}

2 changes: 2 additions & 0 deletions src/cli/extend/abe-hooks.js
Expand Up @@ -40,6 +40,8 @@ class Hooks {
}

args[0] = Plugins.instance.hooks.apply(Plugins.instance, [fn].concat(args))
} else {
args = ['']
}

return args[0]
Expand Down
7 changes: 4 additions & 3 deletions src/cli/extend/abe-plugins.js
Expand Up @@ -153,14 +153,15 @@ class Plugins {
var args = [].slice.call(arguments)
var fn = args.shift()

if(typeof this._plugins !== 'undefined' && this._plugins !== null) {
if(this._plugins != null) {
Array.prototype.forEach.call(this._plugins, (plugin) => {
if(typeof plugin.hooks !== 'undefined' && plugin.hooks !== null
&& typeof plugin.hooks[fn] !== 'undefined' && plugin.hooks[fn] !== null) {
if(plugin.hooks != null&& plugin.hooks[fn] != null) {
args[0] = plugin.hooks[fn].apply(this, args)
}
})
}
} else {
args = ['']
}

return args[0]
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/get-list-hooks.js
@@ -1,13 +1,13 @@
import path from 'path'
import fse from 'fs-extra'
import Handlebars from 'handlebars'
import hooksDefault from '../../hooks/hooks'
import {
coreUtils,
Hooks
} from '../../cli'

var route = function(req, res, next) {
var html
var html = ''

Hooks.instance.trigger('beforeRoute', req, res, next)

Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/get-list-url.js
@@ -1,15 +1,15 @@
import path from 'path'
import fse from 'fs-extra'
import Handlebars from 'handlebars'
import {
coreUtils,
Hooks
} from '../../cli'

var route = function(router, req, res, next) {
Hooks.instance.trigger('beforeRoute', req, res, next)
var routes = router.stack
var urls = []
var html
var html = ''

Array.prototype.forEach.call(routes, function(route) {
urls.push({
Expand Down

0 comments on commit d951416

Please sign in to comment.