Skip to content

Commit

Permalink
fix: BC break on each statement for mixed Abe tags in a each
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Jan 14, 2017
1 parent 6e83f4d commit c389516
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cli/cms/templates/prepare.js
Expand Up @@ -296,7 +296,7 @@ export function indexEachBlocks(template, json, onlyHtml) {

var voidData = {}
voidData[key] = [{}]
var blockCompiled = Handlebars.compile(block.replace(/{{abe (.*?["']) ?}}/g, '[[abe $1]]').replace(new RegExp(`\\.\\.\/${config.meta.name}`, 'g'), config.meta.name))
var blockCompiled = Handlebars.compile(block.replace(/{{abe (.*?["'])[ ]?( has\-abe=1)?}}/g, '[[abe $1]]').replace(new RegExp(`\\.\\.\/${config.meta.name}`, 'g'), config.meta.name))
var blockHtml = blockCompiled(voidData, {data: {intl: config.intlData}}).replace(/\[\[abe (.*?)\]\]/g, '{{abe $1}}')

// je rajoute un data-abe-block avec index sur tous les tags html du bloc each
Expand Down
11 changes: 8 additions & 3 deletions test/cms/templates/prepare.js
Expand Up @@ -29,6 +29,7 @@ describe('cmsTemplates.prepare', function() {
source: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-source.html'), 'utf-8'),
each: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each.html'), 'utf-8'),
eachMultiple: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each-multiple.html'), 'utf-8'),
eachMultiplePrepared: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each-multiple-prepared.html'), 'utf-8'),
eachVariable: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each-variable.html'), 'utf-8'),
rawHandlebar: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-raw-handlebars.html'), 'utf-8'),
noHtml: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-nohtml.html'), 'utf-8')
Expand Down Expand Up @@ -238,9 +239,13 @@ describe('cmsTemplates.prepare', function() {
chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1)
});

it('cmsTemplates.prepare.indexEachBlocks() eachMultiple', function() {
var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.eachMultiple, {}, false)
chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1)
// eachMultiplePrepared is the string obtained after all other functions have "prepared" the string
// and just before indexEachBlocks() is triggered
it('cmsTemplates.prepare.indexEachBlocks() eachMultiplePrepared', function() {
var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.eachMultiplePrepared, {}, false)
console.log(template)
var count = (template.match(/abe dictionnary=/g) || []).length;
chai.expect(count).to.be.equal(2)
});

it('cmsTemplates.prepare.indexEachBlocks() eachMultiple with data', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/cms/templates/template.js
Expand Up @@ -49,7 +49,7 @@ describe('cmsTemplates', function() {

cmsTemplates.template.getTemplatesAndPartials(this.fixture.pathTemplates, this.fixture.pathPartials)
.then((templatesList) => {
chai.expect(templatesList.length).to.be.equal(28);
chai.expect(templatesList.length).to.be.equal(29);
done()
})
});
Expand Down
4 changes: 2 additions & 2 deletions test/core/manager/Manager.js
Expand Up @@ -28,14 +28,14 @@ describe('Manager', function() {
it('getStructureAndTemplates()', function() {
const data = Manager.instance.getStructureAndTemplates()
chai.assert.equal(data['templates'][0].name, 'article-data-arrayinline', 'failed !')
chai.assert.equal(data['templates'].length, 26, 'failed !')
chai.assert.equal(data['templates'].length, 27, 'failed !')
});

it('updateStructureAndTemplates()', function() {
Manager.instance.updateStructureAndTemplates()
const data = Manager.instance.getStructureAndTemplates()
chai.assert.equal(data['templates'][0].name, 'article-data-arrayinline', 'failed !')
chai.assert.equal(data['templates'].length, 26, 'failed !')
chai.assert.equal(data['templates'].length, 27, 'failed !')
});

it('getList()', function() {
Expand Down
@@ -0,0 +1,3 @@
{{#each test}}
{{abe type='link' key='test.link' desc='Navigation Link' tab='Header' order='2' has-abe=1}}"><abe data-abe-test{{@index}}-text="test{{@index}}-text" >{{abe type='text' key="test.text" desc="Navigation Label" tab="Header" order='3'}}
{{/each}}

0 comments on commit c389516

Please sign in to comment.