Skip to content

Commit

Permalink
fix: non editable Abe data tags were improperly displayed in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Jan 12, 2017
1 parent 5497ed3 commit cf46b79
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/cli/cms/data/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export let abeAsAttributePattern = /( [A-Za-z0-9\-\_]+=["|']{1})([^=]*?)({{abe.*
export let eachBlockPattern = /(\{\{#each (\r|\t|\n|.)*?\/each\}\})/g
// This pattern finds all {{#each ...}}...{{/each}} blocks
export let blockPattern = /(\{\{#each.*\}\}[\s\S]*?\{\{\/each\}\})/g
// This pattern finds all non editable data types
export let nonEditableDataReg = /({{abe.*(type=[\'|\"]data')?.*editable=[\'|\"]false.*(type=[\'|\"]data')?.*}})/g
// This pattern finds all data types
export let dataTypeReg = /({{abe.*type=[\'|\"]data.*}})/g

/**
* escape a regex
Expand Down
10 changes: 7 additions & 3 deletions src/cli/cms/data/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ export function getDataList(tplPath, text, jsonPage, onlyDynamicSelect = false)
}

export function removeDataList(text) {
var listReg = /({{abe.*type=[\'|\"]data.*}})/g

return text.replace(listReg, '')
}
return text.replace(cmsData.regex.dataTypeReg, '')
}

export function removeNonEditableDataList(text) {

return text.replace(cmsData.regex.nonEditableDataReg, '')
}
2 changes: 1 addition & 1 deletion src/server/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ export function editor(text, json, documentLink, precontrib = false) {
let p = new Promise((resolve) => {
var util = new cmsEditor.form()
var arrayBlock = []

cmsData.source.getDataList(path.dirname(documentLink), text, json)
.then(() => {
addSource(text, json, util)
Expand All @@ -260,6 +259,7 @@ export function editor(text, json, documentLink, precontrib = false) {
text = cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist(text)
}

text = cmsData.source.removeNonEditableDataList(text)
matchAttrAbe(text, json, util, arrayBlock)
arrayBlock = []
each(text, json, util, arrayBlock)
Expand Down
14 changes: 14 additions & 0 deletions tests/demo/templates/data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

{{abe type='data' key='stores' source='reference/category.json' editable='false'}}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>test</title>
</head>
<body>
content
</body>
</html>
2 changes: 1 addition & 1 deletion tests/functional/1-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Abe', function() {
.waitForElementVisible('//body')
.assert.title('Abe')
.click('//*[@id="level-1"]/option[2]')
.click('//*[@id="selectTemplate"]/option[9]')
.click('//*[@id="selectTemplate"]/option[10]')
.waitForElementVisible("//div[@data-precontrib-templates='single']//input[@id='name']", 1000)
.setValue("//div[@data-precontrib-templates='single']//input[@id='name']", 'ftest')
.click("//button[@type='submit']")
Expand Down
60 changes: 60 additions & 0 deletions tests/functional/3-abe-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
describe('Abe', function() {

describe('data', function() {

before(function(client, done) {
done();
});

after(function(client, done) {
client.end(function() {
done();
});
});

afterEach(function(client, done) {
done();
});

beforeEach(function(client, done) {
done();
});

it('Create a autocomplete template post', function(client) {
client
.useXpath()
.url('http://localhost:3003/abe/editor')
.click('//*[@id="selectTemplate"]/option[3]')
.waitForElementVisible("//div[@data-precontrib-templates='data']//input[@id='name']", 1000)
.setValue("//div[@data-precontrib-templates='data']//input[@id='name']", 'data')
.click("//button[@type='submit']")
.pause(1000)
.waitForElementVisible('//*[@id="abeForm"]', 2000)
.assert.urlEquals("http://localhost:3003/abe/editor/data.html", "Clicked URL Matches with URL of the New Window");
});

it('Abe type data reference json', function(client) {
client
.useXpath()
.url('http://localhost:3003/abe/editor/data.html')
.waitForElementVisible('//body')
.pause(1000)
.expect.element("//form[@id='abeForm']//li[@class='active']/a").text.to.contain('slug');
});


it('The autocomplete article is deleted in the manager', function(client) {
client
.useXpath()
.url('http://localhost:3003/abe/editor')
.waitForElementVisible('//body')
.pause(1000)
.click("//table[@id='navigation-list']/tbody/tr[1]/td[7]/div/a")
.pause(1000)
.acceptAlert()
.url('http://localhost:3003/abe/editor')
.pause(2000)
.expect.element("//table[@id='navigation-list']/tbody/tr[1]/td[2]/a").text.to.not.contain('/articles/ftest.html');
});
});
});

0 comments on commit cf46b79

Please sign in to comment.