Skip to content

Commit

Permalink
refactoring: object test + fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 9, 2016
1 parent f482916 commit a65f2c5
Show file tree
Hide file tree
Showing 23 changed files with 114 additions and 128 deletions.
1 change: 0 additions & 1 deletion src/cli/cms/data/attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ export default class Attr {
strWithoutAttr = strWithoutAttr.replace(new RegExp('\\.' + this.getExtension()), '')
return strWithoutAttr + '-abe-' + newValues + '.' + this.getExtension()
}

}
9 changes: 4 additions & 5 deletions src/cli/cms/data/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,21 @@ export function getAll(str, json) {
}

attrs.sourceString = attrs.source
attrs.source = (typeof attrs.source !== 'undefined' && attrs.source !== null && attrs.source !== '')?
((typeof json['abe_source'] !== 'undefined' && json['abe_source'] !== null && json['abe_source'] !== '')?
attrs.source = (attrs.source)?
((json != null && json['abe_source'] != null)?
json['abe_source'][attrs.key] :
null
) :
null
attrs.editable = (typeof attrs.editable === 'undefined' || attrs.editable === null || attrs.editable === '' || attrs.editable === 'false') ? false : true
attrs.editable = (attrs.editable) ? true : false

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

return attrs
}


export function sanitizeSourceAttribute(obj, jsonPage){
if(typeof obj.sourceString !== 'undefined' && obj.sourceString !== null && obj.sourceString.indexOf('{{') > -1) {
if(obj.sourceString != null && obj.sourceString.indexOf('{{') > -1) {
var matches = obj.sourceString.match(/({{[a-zA-Z._]+}})/g)
if(matches !== null) {
Array.prototype.forEach.call(matches, (match) => {
Expand Down
27 changes: 12 additions & 15 deletions src/cli/cms/data/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,25 @@ export function getAllWithKeys(withKeys) {
var cleanFile = file
var json = cmsData.file.get(file.path)

if(typeof json.abe_meta.latest !== 'undefined' && json.abe_meta.latest !== null
&& typeof json.abe_meta.latest !== 'undefined' && json.abe_meta.latest !== null
&& typeof json.abe_meta.latest.date !== 'undefined' && json.abe_meta.latest.date !== null) {
if(json.abe_meta.latest.date != null) {
file.date = json.abe_meta.latest.date
}

if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
if(json.abe_meta != null) {
var date = null
if (typeof json.abe_meta.latest !== 'undefined' && json.abe_meta.latest !== null
&& typeof json.abe_meta.latest.date !== 'undefined' && json.abe_meta.latest.date !== null) {
if (json.abe_meta.latest.date != null) {
date = json.abe_meta.latest.date
}else if (typeof json.abe_meta.date !== 'undefined' && json.abe_meta.date !== null) {
} else if (json.abe_meta.date != null) {
date = json.abe_meta.date
}
cleanFile.abe_meta = {
date: date
, type: (typeof json.abe_meta.type !== 'undefined' && json.abe_meta.type !== null) ? json.abe_meta.type : null
, link: (typeof json.abe_meta.link !== 'undefined' && json.abe_meta.link !== null) ? json.abe_meta.link : null
, template: (typeof json.abe_meta.template !== 'undefined' && json.abe_meta.template !== null) ? json.abe_meta.template : null
, status: (typeof json.abe_meta.status !== 'undefined' && json.abe_meta.status !== null) ? json.abe_meta.status : null
, cleanName: (typeof json.abe_meta.cleanName !== 'undefined' && json.abe_meta.cleanName !== null) ? json.abe_meta.cleanName : null
, cleanFilename: (typeof json.abe_meta.cleanFilename !== 'undefined' && json.abe_meta.cleanFilename !== null) ? json.abe_meta.cleanFilename : null
date: date,
type: (json.abe_meta.type != null) ? json.abe_meta.type : null,
link: (json.abe_meta.link != null) ? json.abe_meta.link : null,
template: (json.abe_meta.template != null) ? json.abe_meta.template : null,
status: (json.abe_meta.status != null) ? json.abe_meta.status : null,
cleanName: (json.abe_meta.cleanName != null) ? json.abe_meta.cleanName : null,
cleanFilename: (json.abe_meta.cleanFilename != null) ? json.abe_meta.cleanFilename : null
}
}
Array.prototype.forEach.call(withKeys, (key) => {
Expand Down Expand Up @@ -91,7 +88,7 @@ export function fromUrl(url) {
}
}

if(typeof url !== 'undefined' && url !== null) {
if(url != null) {

var dir = path.dirname(url).replace(config.root, '')
var filename = path.basename(url)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cms/data/fileAttr.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class FileAttr {
*/
static test(str) {
var att = new attr(str).val
return (typeof att.s !== 'undefined' && att.s !== null)
return (att.s != null)
}
}

14 changes: 7 additions & 7 deletions src/cli/cms/data/metas.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import {
export function add(tpl, json, type, obj = {}, date = null, realType = 'draft') {
let meta = config.meta.name

var currentDate = (typeof date !== 'undefined' && date !== null && date !== '') ? date : new Date()
var currentDate = (date != null && date !== '') ? date : new Date()
var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + cmsData.revision.removeStatusAndDateFromFileName(currentDate.toISOString())) + ''

if(typeof json[meta].date === 'undefined' || json[meta].date === null) {
if(json[meta].date == null) {
json[meta].date = currentDate
}
json[meta].latest = {
date: currentDate,
abeUrl: abeUrl
}
json[meta].status = realType === 'reject' ? 'draft' : realType
if(typeof json[meta][type] === 'undefined' || json[meta][type] === null) {
if(json[meta][type] == null) {
json[meta][type] = JSON.parse(JSON.stringify(obj))
json[meta][type].date = currentDate
json[meta][type].abeUrl = abeUrl
Expand All @@ -34,15 +34,15 @@ export function get(arr) {

var jsonPath = cmsData.file.fromUrl(file.path).json.path
var json = cmsData.file.get(jsonPath)
if(typeof json[meta] === 'undefined' || json[meta] === null) json[meta] = {}
if(json[meta] == null) json[meta] = {}
file['template'] = json[meta].template
if(typeof json[meta].latest !== 'undefined' && json[meta].latest !== null) {
if(json[meta].latest != null) {
file['date'] = json[meta].latest.date
}
if(typeof json[meta].complete === 'undefined' || json[meta].complete === null) {
if(json[meta].complete == null) {
json[meta].complete = 0
}
if(typeof json[meta] !== 'undefined' && json[meta] !== null) {
if(json[meta] != null) {
file[config.meta.name] = json[meta]
}
res.push(file)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cms/data/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export function getAttr (str, attr) {
var rex = new RegExp(attr + '=["|\']([\\S\\s]*?)["|\']( +[a-zA-Z0-9-]*?=|}})')
var res = rex.exec(str)
res = (typeof res !== 'undefined' && res !== null && res.length > 1) ? res[1] : ''
res = (res != null && res.length > 1) ? res[1] : ''
return res
}

Expand Down
35 changes: 17 additions & 18 deletions src/cli/cms/data/revision.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export function getFilesRevision(urls, fileName) {

if(coreUtils.file.exist(tplUrl.publish.json)) {
json = cmsData.file.get(tplUrl.publish.json)
if(typeof json !== 'undefined' && json !== null
&& typeof json[config.meta.name] !== 'undefined' && json[config.meta.name] !== null) {
if(json != null && json[config.meta.name] != null) {
publishDate = new Date(json[config.meta.name].latest.date)
}
}
Expand All @@ -30,7 +29,7 @@ export function getFilesRevision(urls, fileName) {
if(fileData.s === 'd' && cmsData.fileAttr.delete(urlObj.cleanPath) == cmsData.fileAttr.delete(fileName)) {
var currentDate = new Date(urlObj.date)
if(currentDate.getTime() > publishDate.getTime()) {
if(!publishVersion && typeof res[res.length - 1] !== 'undefined' && res[res.length - 1] !== null) {
if(!publishVersion && res[res.length - 1] != null) {
res[res.length - 1].publishedDate = 'same'
}
publishVersion = true
Expand Down Expand Up @@ -95,7 +94,7 @@ export function getDocumentRevision(docPath) {
var revisions = getVersions(documentPath)
if (latest && revisions.length >= 0) {
result = revisions[0]
}else if (!latest) {
} else if (!latest) {
Array.prototype.forEach.call(revisions, (revision) => {
if (revision.html === docPath) {
result = revision
Expand Down Expand Up @@ -145,7 +144,7 @@ export function getFilesMerged(files) {
var cleanFilePath = file.cleanFilePath

var fileStatusIsPublish = cmsData.fileAttr.get(file.cleanPath)
if(typeof fileStatusIsPublish.s !== 'undefined' && fileStatusIsPublish.s !== null && file.abe_meta.status === 'publish') {
if(fileStatusIsPublish.s != null && file.abe_meta.status === 'publish') {
file.abe_meta.status = 'draft'
}

Expand All @@ -156,19 +155,19 @@ export function getFilesMerged(files) {
file.htmlPath = path.join(config.root, config.draft.url, path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)))
}

if(typeof merged[cleanFilePath] === 'undefined' || merged[cleanFilePath] === null) {
if(merged[cleanFilePath] == null) {
merged[cleanFilePath] = {
name: cmsData.fileAttr.delete(file.name)
, path: cmsData.fileAttr.delete(file.path)
, html: cmsData.fileAttr.delete(path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)))
, htmlPath: path.join(config.root, config.publish.url, path.join('/', cmsData.fileAttr.delete(file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))))
, cleanPathName: file.cleanPathName
, cleanPath: file.cleanPath
, cleanName: file.cleanName
, cleanNameNoExt: file.cleanNameNoExt
, cleanFilePath: file.cleanFilePath
, filePath: cmsData.fileAttr.delete(file.filePath)
, revisions: []
name: cmsData.fileAttr.delete(file.name),
path: cmsData.fileAttr.delete(file.path),
html: cmsData.fileAttr.delete(path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))),
htmlPath: path.join(config.root, config.publish.url, path.join('/', cmsData.fileAttr.delete(file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)))),
cleanPathName: file.cleanPathName,
cleanPath: file.cleanPath,
cleanName: file.cleanName,
cleanNameNoExt: file.cleanNameNoExt,
cleanFilePath: file.cleanFilePath,
filePath: cmsData.fileAttr.delete(file.filePath),
revisions: []
}
}

Expand All @@ -179,7 +178,7 @@ export function getFilesMerged(files) {
Array.prototype.forEach.call(Object.keys(merged), (key) => {
var revisions = merged[key].revisions
revisions.sort(coreUtils.sort.predicatBy('date', -1))
if(typeof revisions[0] !== 'undefined' && revisions[0] !== null) {
if(revisions[0] != null) {
merged[key].date = revisions[0].date
}

Expand Down
8 changes: 4 additions & 4 deletions src/cli/cms/data/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function requestList(obj, tplPath, match, jsonPage) {
}else {
jsonPage[obj.key] = data
}
} else if ((typeof jsonPage[obj.key] === 'undefined' || jsonPage[obj.key] === null) && obj.prefill) {
} else if ((jsonPage[obj.key] == null) && obj.prefill) {
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']) {
Expand Down Expand Up @@ -75,7 +75,7 @@ export function urlList(obj, tplPath, match, jsonPage) {
host = host[2].split(':')

var pathSource = obj.sourceString.split('//')
if(typeof pathSource[1] !== 'undefined' && pathSource[1] !== null) {
if(pathSource[1] != null) {
pathSource = pathSource[1].split('/')
pathSource.shift()
pathSource = '/' + path.join('/')
Expand All @@ -84,7 +84,7 @@ export function urlList(obj, tplPath, match, jsonPage) {
}
var options = {
hostname: host[0],
port: (typeof host[1] !== 'undefined' && host[1] !== null) ? host[1] : defaultPort,
port: (host[1] != null) ? host[1] : defaultPort,
path: pathSource,
method: 'GET',
headers: {
Expand Down Expand Up @@ -149,7 +149,7 @@ export function fileList(obj, tplPath, match, jsonPage) {

export function nextDataList(tplPath, jsonPage, match) {
var p = new Promise((resolve) => {
if(typeof jsonPage['abe_source'] === 'undefined' || jsonPage['abe_source'] === null) {
if(jsonPage['abe_source'] == null) {
jsonPage['abe_source'] = {}
}

Expand Down
Loading

0 comments on commit a65f2c5

Please sign in to comment.