Skip to content

Commit

Permalink
refactoring: insertDebugtoolUtilities + UT
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Oct 5, 2016
1 parent 880c093 commit d1844cf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/cli/cms/Page.js
Expand Up @@ -144,7 +144,7 @@ export default class Page {
}

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

// I create the html page ! yeah !!!
this.html = compiledTemplate(json, {data: {intl: config.intlData}})
Expand Down
2 changes: 2 additions & 0 deletions src/cli/cms/templates/index.js
Expand Up @@ -21,6 +21,7 @@ import truncate from './handlebars/truncate'

import * as template from './template'
import encodeAbeTagAsComment from './encodeAbeTagAsComment'
import insertDebugtoolUtilities from './insertDebugtoolUtilities'

/* Register utilities */
Handlebars.registerHelper('attrAbe', attrAbe)
Expand All @@ -43,6 +44,7 @@ HandlebarsIntl.registerWith(Handlebars)
export {
template,
encodeAbeTagAsComment,
insertDebugtoolUtilities,
attrAbe,
className,
cleanTab,
Expand Down
18 changes: 18 additions & 0 deletions src/cli/cms/templates/insertDebugtoolUtilities.js
@@ -0,0 +1,18 @@
import {
cmsData
} from '../../'

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>`
)
}
20 changes: 0 additions & 20 deletions src/cli/core/utils/abe-utils.js
Expand Up @@ -90,26 +90,6 @@ export default class Utils {
this._form[obj.tab].item.push(obj)
}

/**
* Add some stuff like style / script before closing </body> tag
* @param {String} text html page
* @return {String} text + some sugar stuff added on the fly
*/
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>`
)
}

static sanitizeSourceAttribute(obj, jsonPage){
if(typeof obj.sourceString !== 'undefined' && obj.sourceString !== null && obj.sourceString.indexOf('{{') > -1) {
var matches = obj.sourceString.match(/({{[a-zA-Z._]+}})/g)
Expand Down
32 changes: 0 additions & 32 deletions test/data.js

This file was deleted.

19 changes: 19 additions & 0 deletions test/template.js
Expand Up @@ -14,6 +14,7 @@ describe('Template', function() {
.then(function () {
this.fixture = {
template: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf-8'),
articleEach: fse.readFileSync(__dirname + '/fixtures/templates/article-each-abe.html', 'utf-8'),
templateKeys: fse.readFileSync(__dirname + '/fixtures/templates/article-keys.html', 'utf-8')
}
done()
Expand Down Expand Up @@ -69,4 +70,22 @@ describe('Template', function() {
var ar = cmsTemplate.template.execRequestColumns(this.fixture.templateKeys)
chai.expect(ar.indexOf('abe_meta.date')).to.be.above(-1);
});

/**
* cmsTemplate.insertDebugtoolUtilities
*
*/
it('cmsTemplate.insertDebugtoolUtilities()', function() {
var txt = cmsTemplate.insertDebugtoolUtilities('</body>');
chai.expect(txt.length).to.above(10);
});

/**
* cmsTemplate.encodeAbeTagAsComment
*
*/
it('cmsTemplate.encodeAbeTagAsComment()', function() {
var txt = cmsTemplate.encodeAbeTagAsComment(this.fixture.articleEach);
chai.expect(txt.indexOf('{')).to.equal(-1);
});
});

0 comments on commit d1844cf

Please sign in to comment.