Skip to content

Commit

Permalink
Merged branch master into master
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Sep 26, 2016
2 parents f2e23a9 + a1133e0 commit eb10101
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 82 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "6"
env:
- NODE_ENV=PROD
install:
- npm install
script:
- npm run lint
- npm run test
6 changes: 3 additions & 3 deletions src/cli/controllers/Save.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ export function save(url, tplPath, json = null, text = '', type = '', previousSa
json = Hooks.instance.trigger('afterGetDataListOnSave', json)
for(var prop in json){
if(typeof json[prop] === 'object' && Array.isArray(json[prop]) && json[prop].length === 1){
var valuesAreEmplty = true
var valuesAreEmpty = true
json[prop].forEach(function (element) {
for(var p in element) {
if(element[p] !== '') valuesAreEmplty = false
if(element[p] !== '') valuesAreEmpty = false
}
})
if(valuesAreEmplty) delete json[prop]
if(valuesAreEmpty) delete json[prop]
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/cli/handlebars/abe/printInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function printInput () {
var commonParams = `id="${params.key}"
data-id="${params.key}"
value="${params.value}"
maxlength="${params.maxLength}"
maxlength="${params['max-length']}"
reload="${params.reload}"
tabIndex="${params.order}"
data-required="${params.required}"
Expand All @@ -46,7 +46,7 @@ export default function printInput () {
if(typeof params.source !== 'undefined' && params.source !== null) {
commonParams = `id="${params.key}"
data-id="${params.key}"
data-maxlength="${params.maxLength}"
data-maxlength="${params['max-length']}"
reload="${params.reload}"
tabIndex="${params.order}"
data-required="${params.required}"
Expand All @@ -57,8 +57,8 @@ export default function printInput () {

var multiple = ''
var disabled = ''
if(typeof params.maxLength === 'undefined' || params.maxLength === null || params.maxLength === ''
|| (params.maxLength > 1 && params.source.length > 0)) {
if(typeof params['max-length'] === 'undefined' || params['max-length'] === null || params['max-length'] === ''
|| (params['max-length'] > 1 && params.source.length > 0)) {
multiple = 'multiple'
}
if(params.source.length <= 0) {
Expand Down Expand Up @@ -100,7 +100,7 @@ export default function printInput () {
}else if (params.type.indexOf('rich') >= 0){
commonParams = `id="${params.key}"
data-id="${params.key}"
maxlength="${params.maxLength}"
maxlength="${params['max-length']}"
reload="${params.reload}"
tabIndex="${params.order}"
data-required="${params.required}"
Expand Down
1 change: 1 addition & 0 deletions src/cli/helpers/abe-get-select-template-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var findRequestColumns = function(templatesList) {
resolve(whereKeys)
})
})
reject()
})

return p
Expand Down
121 changes: 56 additions & 65 deletions src/cli/helpers/abe-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,34 @@ export default class Utils {
* @param {String} type textarea | text | meta | link | image | ...
* @param {String} key unique ID, no space allowed
* @param {String} desc input description
* @param {Int} maxLength maximum characteres allowed inside input
* @param {Int} max-length maximum characteres allowed inside input
* @param {String} tab tab name
* @param {String} jsonValue
* @return {Void}
*/
add(obj) {
var defaultValues = {
type: 'text',
key: '',
autocomplete: null,
block:'',
desc: '',
maxLength: null,
tab: 'default',
placeholder: '',
value: '',
source: null,
display: null,
reload: false,
editable: true,
key: '',
"max-length": null,
order: 0,
placeholder: '',
prefill: false,
"prefill-quantity": null,
reload: false,
required: false,
editable: true,
visible: true,
block: ''
source: null,
tab: 'default',
type: 'text',
value: '',
visible: true
}

obj = extend(true, defaultValues, obj)
obj.tab = (typeof obj.tab !== 'undefined' && obj.tab !== null && obj.tab !== '') ? obj.tab : 'default'

obj.reload = (typeof obj.reload !== 'undefined' && obj.reload !== null && obj.reload === 'true') ? true : false,
obj.key = obj.key.replace(/\./, '-')

if(obj.key.indexOf('[') < 0 && obj.key.indexOf('.') > -1) {
Expand Down Expand Up @@ -312,18 +312,18 @@ export default class Utils {
.then((data) => {
jsonPage[sourceAttr][obj.key] = data
if (!obj.editable) {
if (obj.maxLength) {
jsonPage[obj.key] = data.slice(0, obj.maxLength)
if (obj["max-length"]) {
jsonPage[obj.key] = data.slice(0, obj["max-length"])
}else {
jsonPage[obj.key] = data
}
} else if (obj.prefill) {
if (obj.prefillQuantity && obj.maxLength) {
jsonPage[obj.key] = data.slice(0, (obj.prefillQuantity > obj.maxLength) ? obj.maxLength : obj.prefillQuantity)
}else if (obj.prefillQuantity) {
jsonPage[obj.key] = data.slice(0, obj.prefillQuantity)
}else if (obj.maxLength) {
jsonPage[obj.key] = data.slice(0, obj.maxLength)
if (obj["prefill-quantity"] && obj["max-length"]) {
jsonPage[obj.key] = data.slice(0, (obj["prefill-quantity"] > obj["max-length"]) ? obj["max-length"] : obj["prefill-quantity"])
}else if (obj["prefill-quantity"]) {
jsonPage[obj.key] = data.slice(0, obj["prefill-quantity"])
}else if (obj["max-length"]) {
jsonPage[obj.key] = data.slice(0, obj["max-length"])
}else {
jsonPage[obj.key] = data
}
Expand Down Expand Up @@ -537,60 +537,51 @@ export default class Utils {
return str
}

/**
* Get All attributes from a Abe tag
* @return {Object} parsed attributes
*/
static getAllAttributes(str, json) {
str = Hooks.instance.trigger('beforeAbeAttributes', str, json)

var defaultValues = {
type: 'text',
prefill: false,
prefillQuantity: null,
key: '',
desc: '',
maxLength: null,
tab: 'default',
value: '',
source: null,
//This regex analyzes all attributes of a Abe tag
var re = /\b([a-z][a-z0-9\-]*)\s*=\s*("([^"]+)"|'([^']+)'|(\S+))/ig

var attrs = {
autocomplete: null,
desc: '',
display: null,
reload: false,
editable: true,
key: '',
"max-length": null,
"min-length": 0,
order: 0,
prefill: false,
"prefill-quantity": null,
reload: false,
required: false,
editable: true,
source: null,
tab: 'default',
type: 'text',
value: '',
visible: true
}

var source = getAttr(str, 'source')
var key = getAttr(str, 'key')

var obj = {
type: getAttr(str, 'type')
,key: key
,prefill: getAttr(str, 'prefill')
,prefillQuantity: getAttr(str, 'prefill-quantity')
,desc: getAttr(str, 'desc')
,autocomplete: getAttr(str, 'autocomplete')
,maxLength: getAttr(str, 'max-length')
,value: json[key]
,tab: getAttr(str, 'tab')
,sourceString: (typeof source !== 'undefined' && source !== null && source !== '') ? source : null
,source: (typeof source !== 'undefined' && source !== null && source !== '')
? ((typeof json[config.source.name] !== 'undefined' && json[config.source.name] !== null && json[config.source.name] !== '')
? json[config.source.name][key] : null) : null
,display: getAttr(str, 'display')
,reload: getAttr(str, 'reload')
,order: getAttr(str, 'order')
,required: getAttr(str, 'required')
,visible: getAttr(str, 'visible')
,editable: getAttr(str, 'editable')

for (var match; match = re.exec(str); ){
attrs[match[1]] = match[3] || match[4] || match[5];
}
obj = extend(true, defaultValues, obj)

obj.editable = (typeof obj.editable === 'undefined' || obj.editable === null || obj.editable === '' || obj.editable === 'false') ? false : true
obj.prefill = (typeof obj.prefill !== 'undefined' && obj.prefill !== null && obj.prefill === 'true') ? true : false
obj.prefillQuantity = (typeof obj.prefillQuantity !== 'undefined' && obj.prefillQuantity !== null && obj.prefillQuantity !== '') ? obj.prefillQuantity : false
attrs.sourceString = attrs.source
attrs.source = (typeof source !== 'undefined' && source !== null && source !== '')?
((typeof json[config.source.name] !== 'undefined' && json[config.source.name] !== null && json[config.source.name] !== '')?
json[config.source.name][key] :
null
) :
null
attrs.editable = (typeof attrs.editable === 'undefined' || attrs.editable === null || attrs.editable === '' || attrs.editable === 'false') ? false : true

obj = Hooks.instance.trigger('afterAbeAttributes', obj, str, json)
attrs = Hooks.instance.trigger('afterAbeAttributes', attrs, str, json)

return obj
return attrs
}
}
5 changes: 0 additions & 5 deletions src/cli/helpers/regex-helper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {cli} from '../'

export function getAttr (str, attr) {
// var rex = new RegExp(attr + '=["\']([^\'"]+)')
var rex = new RegExp(attr + '=["|\']([\\S\\s]*?)["|\']( +[a-zA-Z0-9-]*?=|}})')
// var rex = new RegExp(attr + '=["|\']([\\S\\s]*?)["|\']( [a-zA-Z0-9-]*?=|}})')
var res = rex.exec(str)
res = (typeof res !== null && res !== null && res.length > 1) ? res[1] : ''
return res
Expand Down Expand Up @@ -182,9 +180,6 @@ export function getEnclosingTags(text, match, tag) {
* @return {Object} RegExp
*/
export function escapeTextToRegex(str, params) {
// str = str.replace(/\((?![\s\S]*\()/g, '\\(')
// str = str.replace(/\)(?![\s\S]*\))/g, '\\)')
// str = str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
str = str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
return new RegExp(str, params)
}
6 changes: 6 additions & 0 deletions src/cli/models/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Manager {
}

init() {
this._whereKeys = []
var p = new Promise((resolve, reject) => {
this._loadTime = new TimeMesure('Loading Manager')
const pathTemplate = path.join(config.root, config.templates.url)
Expand All @@ -61,6 +62,11 @@ class Manager {
this._whereKeys = whereKeys
this.updateList()
resolve()
},
() => {
// No where keys found
this.updateList()
resolve()
})
.catch((e) => {
console.log('Manager._init', e)
Expand Down
10 changes: 6 additions & 4 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ describe('Request', function() {
* Sql.getAllAttributes
*
*/
it('Util.getAllAttributes()', function() {
it('Util.getAllAttributes()', function(done) {
this.timeout(4000)
var Util = require('../src/cli').Util
var attributes = Util.getAllAttributes("{{abe type='data' key='top_things_slider_highlight' desc='Automatic slider' source=\"select * from ../\" editable=\"false\"}}", {})
chai.assert.equal(attributes.sourceString, 'select * from ../', 'sourceString is ok');
var attributes = Util.getAllAttributes("{{abe type='data' key='top_things_slider_highlight' desc='Automatic slider' source='select * from ../' editable='false'}}", {})

chai.assert.equal(attributes.sourceString, 'select * from ../', 'sourceString is ok')
});

/**
Expand Down Expand Up @@ -172,4 +174,4 @@ describe('Request', function() {
)
);
});
});
});

0 comments on commit eb10101

Please sign in to comment.