Skip to content

Commit

Permalink
remove fakeContent
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Sep 16, 2016
1 parent d4aa712 commit 8aa0542
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 54 deletions.
31 changes: 22 additions & 9 deletions src/cli/process/publish-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ if(typeof pConfig.ABE_PATH === 'undefined' || pConfig.ABE_PATH === null) {

console.log(clc.green('start publish all') + ' path ' + pConfig.ABE_PATH)

function publishNext(published, cb, i = 0) {
function msToTime(duration) {
var milliseconds = parseInt((duration%1000)/100)
, seconds = parseInt((duration/1000)%60)
, minutes = parseInt((duration/(1000*60))%60)
, hours = parseInt((duration/(1000*60*60))%24);

hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;

return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}

function publishNext(published, tt, cb, i = 0) {
var currentDateStart = new Date()
var pub = published.shift()
if(typeof pub !== 'undefined' && pub !== null) {
Expand All @@ -42,12 +55,12 @@ function publishNext(published, cb, i = 0) {
pConfig.TYPE,
true)
.then(() => {
var d = (new Date().getTime() - currentDateStart.getTime()) / 1000
var total = (Math.round((new Date().getTime() - dateStart.getTime()) / 1000 / 60 * 100)) / 100
var d = new Date(new Date().getTime() - currentDateStart.getTime())
var total = new Date(new Date().getTime() - dateStart.getTime())
// logsPub += i + ' [' + d + 'sec] > start publishing ' + pub.path .replace(config.root, '') + ' < ' + jsonPath
console.log(i + ' - (' + clc.green(d + 's') + ' / ' + total + 'm)')
console.log(clc.bgWhite(clc.black(pub.path.replace(config.root, '')))
+ ' < ' + clc.bgWhite(clc.black(jsonPath.replace(config.root, '')))
console.log(clc.green(i) + '/' + tt + ' - (' + clc.green(msToTime(d)) + '/' + msToTime(total) + ')')
console.log(clc.bgWhite(clc.black(pub.path.replace(config.root, '').replace(config.publish.url, '')))
+ ' < ' + clc.bgWhite(clc.black(jsonPath.replace(config.root, '').replace(config.data.url, '')))
+ ' (' + clc.cyan(json.abe_meta.template) + ')')
resolve()
}).catch(function(e) {
Expand All @@ -65,10 +78,10 @@ function publishNext(published, cb, i = 0) {
}

p.then(function () {
publishNext(published, cb, i++)
publishNext(published, tt, cb, i++)
})
.catch(function () {
publishNext(published, cb, i++)
publishNext(published, tt, cb, i++)
console.log('error', clc.red(e))
})
}else {
Expand Down Expand Up @@ -125,7 +138,7 @@ if(typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null) {

console.log('Found ' + clc.green(published.length) + ' to republish')
dateStart = new Date()
publishNext(published, function (i) {
publishNext(published, published.length, function (i) {
console.log('total ' + clc.green(i) + ' files')

// Promise.all(promises)
Expand Down
61 changes: 18 additions & 43 deletions src/server/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
,Plugins
} from '../../cli'

function add(obj, json, text, fakeContent, util) {
function add(obj, json, text, util) {
var value = obj.value

if(obj.key.indexOf('[') > -1) {
Expand All @@ -36,38 +36,14 @@ function add(obj, json, text, fakeContent, util) {
if(typeof json[key][index] === 'undefined' || json[key][index] === null) json[key][index] = {}
json[key][index][prop] = value
}
}else {
if((typeof value === 'undefined' || value === null || value === '') && fakeContent) {
if(typeof obj.source === 'undefined' || obj.source === null) {
value = util.lorem(obj.type)
}else {
if (typeof obj.source === 'object') {
value = []
var i = 0
Array.prototype.forEach.call(obj.source, (item) => {
if(typeof obj.maxLength === 'undefined' || obj.maxLength === null || obj.maxLength === '' || i < obj.maxLength) {
value.push(item)
}
i++
})
json[obj.key] = value
}else {
value = obj.source
}
}
json[obj.key] = value
}
}

if(fakeContent) {
value = util.lorem(obj.type)
}
util.add(obj)

return value
}

function addToForm(match, text, json, fakeContent, util, arrayBlock, keyArray = null, i = 0) {
function addToForm(match, text, json, util, arrayBlock, keyArray = null, i = 0) {
var v = `{{${match}}}`,
obj = Util.getAllAttributes(v, json)

Expand All @@ -79,30 +55,30 @@ function addToForm(match, text, json, fakeContent, util, arrayBlock, keyArray =
obj.realKey = realKey
obj.key = keyArray + "[" + i + "]." + realKey
obj.desc = obj.desc + " " + i,
insertAbeEach(obj, text, json, fakeContent, util, arrayBlock)
insertAbeEach(obj, text, json, util, arrayBlock)

}else if(util.dontHaveKey(obj.key)) {
obj.value = json[obj.key]
json[obj.key] = add(obj, json, text, fakeContent, util)
json[obj.key] = add(obj, json, text, util)
}

}else if(util.dontHaveKey(obj.key) && util.isSingleAbe(v, text)) {
var realKey = obj.key.replace(/\./g, '-')
obj.value = json[realKey]
json[obj.key] = add(obj, json, text, fakeContent, util)
json[obj.key] = add(obj, json, text, util)
}
}

function matchAttrAbe(text, json, fakeContent, util, arrayBlock) {
function matchAttrAbe(text, json, util, arrayBlock) {
var patt = /abe [^{{}}]+?(?=\}})/g,
match
// While regexp match HandlebarsJS template item => keepgoing
while (match = patt.exec(text)) {
addToForm(match[0], text, json, fakeContent, util, arrayBlock, null, null)
addToForm(match[0], text, json, util, arrayBlock, null, null)
}
}

function insertAbeEach (obj, text, json, fakeContent, util, arrayBlock) {
function insertAbeEach (obj, text, json, util, arrayBlock) {
if(typeof arrayBlock[obj.keyArray][obj.realKey] === "undefined" || arrayBlock[obj.keyArray][obj.realKey] === null) {
arrayBlock[obj.keyArray][obj.realKey] = []
}
Expand All @@ -117,7 +93,7 @@ function insertAbeEach (obj, text, json, fakeContent, util, arrayBlock) {
}
}

function each(text, json, fakeContent, util, arrayBlock) {
function each(text, json, util, arrayBlock) {
let pattEach = /(\{\{#each (\r|\t|\n|.)*?\/each\}\})/g
let patt = /abe [^{{}}]+?(?=\}})/g
var textEach, match
Expand All @@ -136,10 +112,10 @@ function each(text, json, fakeContent, util, arrayBlock) {
if(json[keyArray]){
for (var i = 0; i < json[keyArray].length; i++) {
var key = json[keyArray]
addToForm(v, text, json, fakeContent, util, arrayBlock, keyArray, i)
addToForm(v, text, json, util, arrayBlock, keyArray, i)
}
}else{
addToForm(v, text, json, fakeContent, util, arrayBlock, keyArray, 0)
addToForm(v, text, json, util, arrayBlock, keyArray, 0)
}
}
}
Expand All @@ -154,13 +130,13 @@ function each(text, json, fakeContent, util, arrayBlock) {

for (var i = 0; i < length; i++) {
for (var j = 0; j < attrArray.length; j++) {
add(arrayBlock[keyArray][attrArray[j]][i], json, text, fakeContent, util)
add(arrayBlock[keyArray][attrArray[j]][i], json, text, util)
}
}
}
}

function addSource(text, json, fakeContent, util, arrayBlock) {
function addSource(text, json, util, arrayBlock) {
var listReg = /({{abe.*type=[\'|\"]data.*}})/g,
match,
limit = 0
Expand All @@ -169,7 +145,7 @@ function addSource(text, json, fakeContent, util, arrayBlock) {
var obj = Util.getAllAttributes(match[0], json)

if(obj.editable) {
add(obj, json, text, fakeContent, util)
add(obj, json, text, util)
}else {
json[obj.key] = obj.source
}
Expand Down Expand Up @@ -243,13 +219,12 @@ function orderBlock(util) {
return formTabsOrdered
}

export function editor(fileName, tplUrl, fake) {
export function editor(fileName, tplUrl) {
let p = new Promise((resolve, reject) => {
var util = new Util()
var arrayBlock = []
var text
var json
var fakeContent = fake
var tabIndex = 0

json = {}
Expand All @@ -261,13 +236,13 @@ export function editor(fileName, tplUrl, fake) {

Util.getDataList(fileUtils.removeLast(tplUrl.publish.link), text, json, true)
.then(() => {
addSource(text, json, fakeContent, util, arrayBlock)
addSource(text, json, util, arrayBlock)

text = Util.removeDataList(text)

matchAttrAbe(text, json, fakeContent, util, arrayBlock)
matchAttrAbe(text, json, util, arrayBlock)
arrayBlock = []
each(text, json, fakeContent, util, arrayBlock)
each(text, json, util, arrayBlock)

if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
var tpl = json.abe_meta.template.split('/')
Expand Down
3 changes: 1 addition & 2 deletions src/server/routes/get-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ var route = function(req, res, next) {
}

let tplUrl = FileParser.getFileDataFromUrl(filePath)
var fakeContent = (req.query.fakeContent) ? true : false

if(!fileUtils.isFile(tplUrl.json.path)) {
res.redirect("/abe/");
return;
}

editor(templatePath, tplUrl, fakeContent)
editor(templatePath, tplUrl)
.then((result) => {
var manager = {}

Expand Down

0 comments on commit 8aa0542

Please sign in to comment.