Skip to content

Commit

Permalink
enhancement: variable is editor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Nov 28, 2016
1 parent 2f0cf82 commit 1f9172b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/cli/cms/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class Page {
}

// I compile the text
var compiledTemplate = Handlebars.compile((!this._onlyHTML) ? cmsTemplates.insertDebugtoolUtilities(this.template) : this.template)
var compiledTemplate = Handlebars.compile(cmsTemplates.insertDebugtoolUtilities(this.template, this._onlyHTML))

// I create the html page ! yeah !!!
this.html = compiledTemplate(json, {data: {intl: config.intlData}})
Expand Down
4 changes: 2 additions & 2 deletions src/cli/cms/editor/handlebars/printBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
export default function printBlock (ctx, root) {
var res = ''
var precontrib = false
if (root.precontrib != null && root.precontrib === 'true') {
precontrib = true
if (root.precontrib != null) {
precontrib = root.precontrib
}

if(ctx[0].block != null && ctx[0].block !== '') {
Expand Down
6 changes: 6 additions & 0 deletions src/cli/cms/templates/handlebars/setVariable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
* Handlebars helper, to add variable inside template file
*/
export default function setVariable(varName, varValue, options){
if (varValue === "true") {
varValue = true
}
if (varValue === "false") {
varValue = false
}
options.data.root[varName] = varValue
}
32 changes: 19 additions & 13 deletions src/cli/cms/templates/insertDebugtoolUtilities.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
export default function insertDebugtoolUtilities(text){
return text.replace(
/<\/body>/,
`<style>
body [data-abe]{ transition: box-shadow 600ms ease-in-out; box-shadow: 0; }
body .select-border{ border-color: #007CDE; box-shadow: 0 3px 13px #7CBAEF; }
body img.display-attr:before { content: attr(alt); }
body a.display-attr:before { content: attr(title); }
body .display-attr:before { position: absolute; display: block; z-index: 555; font-size: 10px; background-color: rgba(255, 255, 255, 0.75); padding: 2px 5px; color: #5D5D5D; }
.hidden-abe{ display: none!important; width: 0px !important; height: 0px!important; position: absolute; left: -10000px; top: -10000px; visibility: hidden;}
</style>
</body>`
)
export default function insertDebugtoolUtilities(text, onlyHTML){
if (onlyHTML) {
text = `{{&setVariable "abeEditor" false}}\n${text}`
}else {
text = `{{&setVariable "abeEditor" true}}\n${text}`
text = text.replace(
/<\/body>/,
`<style>
body [data-abe]{ transition: box-shadow 600ms ease-in-out; box-shadow: 0; }
body .select-border{ border-color: #007CDE; box-shadow: 0 3px 13px #7CBAEF; }
body img.display-attr:before { content: attr(alt); }
body a.display-attr:before { content: attr(title); }
body .display-attr:before { position: absolute; display: block; z-index: 555; font-size: 10px; background-color: rgba(255, 255, 255, 0.75); padding: 2px 5px; color: #5D5D5D; }
.hidden-abe{ display: none!important; width: 0px !important; height: 0px!important; position: absolute; left: -10000px; top: -10000px; visibility: hidden;}
</style>
</body>`
)
}
return text
}
4 changes: 2 additions & 2 deletions src/server/public/scripts/modules/UserList.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var usersList = {
this._bindEvents()
}

if ($('#filtered-list').size() > 0) {
if (document.querySelectorAll('#filtered-list').length > 0) {
var orderables = document.querySelectorAll('#filtered-list thead th')
var columns = []
Array.prototype.forEach.call(orderables, (orderable) => {
Expand All @@ -41,7 +41,7 @@ var usersList = {
})
}

if ($('#filtered-list-url').size() > 0) {
if (document.querySelectorAll('#filtered-list-url').length > 0) {
this._handleFormUserRoleSubmit = this._formUserRoleSubmit.bind(this)

this._formUserRole = document.querySelector('[data-user-role]')
Expand Down
2 changes: 1 addition & 1 deletion src/server/views/partials/create-form-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<option></option>
{{#each @root.manager.list.templates}}
{{#ifCond @root.json.abe_meta.template name}}
{{#ifCond @root.precontrib "true"}}
{{#ifCond @root.precontrib true}}
<option value="{{name}}" clean-value="{{website}}">{{name}}</option>
{{else}}
<option value="{{name}}" clean-value="{{website}}" selected="selected">{{name}}</option>
Expand Down
9 changes: 9 additions & 0 deletions test/hbs-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,13 @@ describe("Helpers", function () {
chai.expect(rendered).to.eql(expected);
});
});
describe("setVariable", function () {
it('setVariable', function() {
var variableName = "variableName",
variableValue = 'variableValue',
obj = {data: {root: {}}},
rendered = Handlebars.helpers.setVariable(variableName, variableValue, obj);
chai.expect(obj.data.root.variableName).to.be.equal(variableValue);
});
});
});

0 comments on commit 1f9172b

Please sign in to comment.