Skip to content

Commit

Permalink
back to normal
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 9, 2016
1 parent a8bb1b9 commit 85a8aa1
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -75,7 +75,7 @@
"prompt": "^1.0.0",
"qs": "^6.0.1",
"request": "^2.69.0",
"watch": "^0.19.2",
"watch": "^1.0.1",
"xss": "^0.2.10"
},
"devDependencies": {
Expand Down
22 changes: 10 additions & 12 deletions src/cli/cms/Page.js
Expand Up @@ -3,7 +3,6 @@ import path from 'path'
import fse from 'fs-extra'

import {
cmsEditor,
abeEngine,
cmsData,
cmsTemplates,
Expand Down Expand Up @@ -95,14 +94,15 @@ export default class Page {
var patAttrSource = new RegExp(' ([A-Za-z0-9\-\_]+)=["|\'].*?({{' + keys[i] + '}}).*?["|\']', 'g')
var patAttrSourceMatch = this.template.match(patAttrSource)

if(typeof patAttrSourceMatch !== 'undefined' && patAttrSourceMatch !== null) {
var patAttrSourceInside = new RegExp('(\\S+)=["\']?((?:.(?!["\']?\\s+(?:\\S+)=|[>"\']))+.)["\']?({{' + keys[i] + '}}).*?["|\']', 'g')
if(patAttrSourceMatch != null) {
let checkEscapedRegex = /["|'](.*?)["|']/
let 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) {
var checkEscaped = /["|'](.*?)["|']/
checkEscaped = checkEscaped.exec(patAttrSourceCheck[0])
if(typeof checkEscaped !== 'undefined' && checkEscaped !== null && checkEscaped.length > 0) {
let patAttrSourceCheck = patAttrSourceInside.exec(pat)
if(patAttrSourceCheck != null) {

let checkEscaped = checkEscapedRegex.exec(patAttrSourceCheck[0])
if(checkEscaped != null && checkEscaped.length > 0) {
checkEscaped = escape(checkEscaped[1])
this.template = this.template.replace(
patAttrSourceCheck[0],
Expand Down Expand Up @@ -196,7 +196,6 @@ export default class Page {
Array.prototype.forEach.call(blocks, (block) => {
var key = block.match(/#each (.*)\}\}/)
key = key[1]
let util = new cmsEditor.form()
var match

if(!this._onlyHTML) {
Expand All @@ -215,12 +214,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 Expand Up @@ -266,7 +265,6 @@ export default class Page {

/**
* add <abe> tag around html tag
* @param {String} text html string
*/
_removeHidden() {
this.template = this.template.replace(/(\{\{abe.*visible=[\'|\"]false.*\}\})/g, '')
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
2 changes: 1 addition & 1 deletion src/cli/cms/templates/handlebars/translate-front.js
Expand Up @@ -5,4 +5,4 @@ export default function translate(lang, str) {
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/helpers/abe-locale.js 100755 → 100644
Expand Up @@ -4,7 +4,7 @@ import clc from 'cli-color'
import path from 'path'

import {
config
config
} from '../../cli'

var result = {}
Expand All @@ -17,4 +17,4 @@ Array.prototype.forEach.call(files, (file) => {
result = extend(true, result, json)
})

export default result
export default result
15 changes: 7 additions & 8 deletions src/server/helpers/page.js
Expand Up @@ -42,28 +42,27 @@ var page = function (req, res, next) {

let meta = config.meta.name

var template = ''
if(typeof json[meta] !== 'undefined' && json[meta] !== null && json[meta] !== ''
&& json[meta].template !== 'undefined' && json[meta].template !== null && json[meta].template !== '') {
template = json[meta].template
var templateId = ''
if(json[meta] && json[meta].template) {
templateId = json[meta].template
}else {
template = req.params[0]
templateId = req.params[0]
}
var text = cmsTemplates.template.getTemplate(template)
var text = cmsTemplates.template.getTemplate(templateId)

if (!editor) {

cmsData.source.getDataList(path.dirname(linkPath), text, json)
.then(() => {
var page = new Page(template, text, json, html)
var page = new Page(templateId, text, json, html)
res.set('Content-Type', 'text/html')
res.send(page.html)
}).catch(function(e) {
console.error(e)
})
}else {
text = cmsData.source.removeDataList(text)
var page = new Page(template, text, json, html)
var page = new Page(templateId, text, json, html)
res.set('Content-Type', 'text/html')
res.send(page.html)
}
Expand Down
15 changes: 1 addition & 14 deletions src/server/middlewares/website.js
@@ -1,26 +1,13 @@
import path from 'path'
import express from 'express'
import fse from 'fs-extra'
import mkdirp from 'mkdirp'
import {minify} from 'html-minifier'
import extend from 'extend'
import * as abe from '../../cli'
import xss from 'xss'
import pkg from '../../../package'

import {
coreUtils,
cmsData,
config,
Page,
abeProcess,
Hooks,
Plugins,
Handlebars
Hooks
} from '../../cli'

import locale from '../helpers/abe-locale'

var middleware = function(req, res, next) {
if (req.originalUrl.indexOf('/abe/') > -1 || req.originalUrl.indexOf('/plugin/') > -1) {
return next()
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 85a8aa1

Please sign in to comment.