Skip to content

Commit

Permalink
refactor remove-duplicate-attr
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Oct 4, 2016
1 parent 87e1e60 commit 922ed96
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/cli/cms/data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import removeDuplicateAttr from './remove-duplicate-attr'

export {
removeDuplicateAttr
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ function recurseDeleteKey(currentLevel, arrayKeyAttr) {
export default function removeDuplicateAttr(text, json) {
var regAbe = /{{abe[\S\s].*?duplicate=['|"]([\S\s].*?['|"| ]}})/g
var matches = text.match(regAbe)
var requiredValue = 0
var complete = 0
if(typeof matches !== 'undefined' && matches !== null){

Array.prototype.forEach.call(matches, (match) => {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/cms/operations/abe-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
save,
config,
Hooks,
removeDuplicateAttr,
cmsData,
Manager
} from '../../'

Expand All @@ -29,7 +29,7 @@ var create = function(template, pathCreate, name, req, forceJson = {}, duplicate
var tpl = templatePath
var text = getTemplate(tpl)
if (duplicate) {
json = removeDuplicateAttr(text, json)
json = cmsData.removeDuplicateAttr(text, json)
}
text = Util.removeDataList(text)
var resHook = Hooks.instance.trigger('beforeFirstSave', filePath, req.query, json, text)
Expand Down
1 change: 0 additions & 1 deletion src/cli/cms/templates/abe-get-select-template-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
save,
config,
Hooks,
removeDuplicateAttr,
Manager
} from '../../'

Expand Down
10 changes: 6 additions & 4 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Create from './cms/Create'
import config from './core/config/config'

import {getAttr, getEnclosingTags, escapeTextToRegex} from './cms/data/regex-helper'
import removeDuplicateAttr from './cms/data/abe-remove-duplicate-attr'

import Sql from './cms/data/abe-sql'

import abeCreate from './cms/operations/abe-create'
Expand All @@ -61,11 +61,14 @@ import abeProcess from './extend/abe-process'
import Hooks from './extend/abe-hooks'
import Plugins from './extend/abe-plugins'


import getSelectTemplateKeys from './cms/templates/abe-get-select-template-keys'

import * as cmsData from './cms/data'

export {
fileAttr
cmsData

,fileAttr
,moment
,fse
,Handlebars
Expand Down Expand Up @@ -103,7 +106,6 @@ export {
,escapeTextToRegex
,config
,getTemplate
,removeDuplicateAttr
,save
,Hooks
,Plugins
Expand Down
33 changes: 33 additions & 0 deletions test/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var chai = require('chai');

var config = require('../src/cli').config
config.set({root: __dirname + '/fixtures'})

var cmsData = require('../src/cli').cmsData;
var Manager = require('../src/cli').Manager;
var fse = require('fs-extra');

describe('Request', function() {
before( function(done) {
Manager.instance.init()
.then(function () {
Manager.instance._whereKeys = ['title', 'priority', 'abe_meta', 'articles']
Manager.instance.updateList()

this.fixture = {
html: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'),
json: fse.readJsonSync(__dirname + '/fixtures/data/article-1.json')
}
done()

}.bind(this))
});
/**
* getAbeImport
*
*/
it('cmsData.removeDuplicateAttr', function() {
var newJson = cmsData.removeDuplicateAttr(this.fixture.html, this.fixture.json)
chai.expect(newJson.title).to.be.undefined;
});
});
2 changes: 1 addition & 1 deletion test/fixtures/templates/article.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{abe type='data' key='title' desc='select title' source='select title,abe_meta from ./' editable='false'}}
{{abe type='data' key='title' desc='select title' source='select title,abe_meta from ./' editable='false' duplicate="false"}}

{{abe type='import' file='title.html'}}

Expand Down

0 comments on commit 922ed96

Please sign in to comment.