Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AdFabConnect/abejs
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Sep 25, 2016
2 parents 8703af0 + 04c323d commit d687dd4
Show file tree
Hide file tree
Showing 11 changed files with 986 additions and 969 deletions.
5 changes: 1 addition & 4 deletions dist/cli/controllers/Save.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ function save(url, tplPath) {
type = 'draft';
realType = 'draft';
url = _.Hooks.instance.trigger('afterReject', url);
// resolve({reject: fileAttr.delete(url).replace(path.join(config.root, config.draft.url), '')})
}
var tplUrl = _.FileParser.getFileDataFromUrl(url);
type = type || _.FileParser.getType(url);
Expand Down Expand Up @@ -173,8 +172,6 @@ function save(url, tplPath) {

obj.json.content[meta].complete = checkRequired(text, obj.json.content);

text = _.Util.removeDataList(text);

var res = saveJsonAndHtml(tpl.replace(/^\/+/, ''), obj, text, type);
if (isRejectedDoc) {
res.reject = _.fileAttr.delete(url).replace(_path2.default.join(_.config.root, _.config.draft.url), '');
Expand Down Expand Up @@ -206,7 +203,7 @@ function splitArray(ar, chunkSize) {
}));
}

function saveJsonAndHtml(templateId, obj, html, type) {
function saveJsonAndHtml(templateId, obj, html) {
var page = new _.Page(templateId, html, obj.json.content, true);

saveHtml(obj.html.path, page.html);
Expand Down
1 change: 0 additions & 1 deletion dist/cli/helpers/file-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var Attr = function () {
* @param {String} str string to work with
* @return {void}
*/

function Attr(str) {
_classCallCheck(this, Attr);

Expand Down
176 changes: 87 additions & 89 deletions dist/cli/models/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
* Page class
* manage HTML generation for page template
*/

var Page = function () {

/**
Expand All @@ -35,7 +34,6 @@ var Page = function () {
* @param {Boolean} onlyHTML default = false, if true HTML content will contains abe attributes
* @return {String} HTML page as string
*/

function Page(templateId, template, json) {
var _this = this;

Expand All @@ -55,128 +53,128 @@ var Page = function () {

//console.log('precompile')
} else {
var source;
var keys;
var i;
var replaceEach;
var patAttrSource;
var patAttrSourceMatch;
var patAttrSourceInside;
var eachSource;
var matches;
var compiledTemplate;

(function () {

_this._onlyHTML = onlyHTML;
_this.template = template;
_this.HbsTemplatePath = _.fileUtils.getTemplatePath('hbs/' + templateId + '.hbs');
var source;
var keys;
var i;
var replaceEach;
var patAttrSource;
var patAttrSourceMatch;
var patAttrSourceInside;
var eachSource;
var matches;
var compiledTemplate;

(function () {

_this._onlyHTML = onlyHTML;
_this.template = template;
_this.HbsTemplatePath = _.fileUtils.getTemplatePath('hbs/' + templateId + '.hbs');

var util = new _.Util();
var util = new _.Util();

_.abeEngine.instance.content = json;
_.abeEngine.instance.content = json;

// This pattern finds all abe tags which are not enclosed in a html tag attribute
// it finds this one: <title>{{abe type='text' key='meta_title' desc='Meta title' tab='Meta' order='4000'}}</title>
// it excludes this one: <meta name="description" content='{{abe type="text" key="meta_description" desc="Meta description" tab="Meta" order="4100"}}"/>
_this.abePattern = /[^"']({{abe.*?type=[\'|\"][text|rich|textarea]+[\'|\"][\s\S].*?}})/g;
// This pattern finds all abe tags which are not enclosed in a html tag attribute
// it finds this one: <title>{{abe type='text' key='meta_title' desc='Meta title' tab='Meta' order='4000'}}</title>
// it excludes this one: <meta name="description" content='{{abe type="text" key="meta_description" desc="Meta description" tab="Meta" order="4100"}}"/>
_this.abePattern = /[^"']({{abe.*?type=[\'|\"][text|rich|textarea]+[\'|\"][\s\S].*?}})/g;

// This pattern finds all abe tags enclosed in a HTML tag attribute
_this.abeAsAttributePattern = /( [A-Za-z0-9\-\_]+=["|']{1}{{abe.*?}})/g;
// This pattern finds all abe tags enclosed in a HTML tag attribute
_this.abeAsAttributePattern = /( [A-Za-z0-9\-\_]+=["|']{1}{{abe.*?}})/g;

// This pattern finds all {{#each ...}}...{{/each}} blocks
_this.eachBlockPattern = />\s*(\{\{#each (\r|\t|\n|.)*?\/each\}\})/g;
// This pattern finds all {{#each ...}}...{{/each}} blocks
_this.eachBlockPattern = />\s*(\{\{#each (\r|\t|\n|.)*?\/each\}\})/g;

// This pattern finds all {{#each ...}}...{{/each}} blocks
_this.blockPattern = /(\{\{#each.*\}\}[\s\S]*?\{\{\/each\}\})/g;
// This pattern finds all {{#each ...}}...{{/each}} blocks
_this.blockPattern = /(\{\{#each.*\}\}[\s\S]*?\{\{\/each\}\})/g;

// Remove text with attribute "visible=false"
_this._removeHidden();
// Remove text with attribute "visible=false"
_this._removeHidden();

if (!_this._onlyHTML) {
if (!_this._onlyHTML) {

// Surrounds each Abe tag (which are text/rich/textarea and not in html attribute) with <abe> tag
// ie. <title><abe>{{abe type='text' key='meta_title' desc='Meta title' tab='Meta' order='4000'}}</abe></title>
_this._encloseAbeTag();
}
// Surrounds each Abe tag (which are text/rich/textarea and not in html attribute) with <abe> tag
// ie. <title><abe>{{abe type='text' key='meta_title' desc='Meta title' tab='Meta' order='4000'}}</abe></title>
_this._encloseAbeTag();
}

// je rajoute les index pour chaque bloc lié à un each
_this._indexEachBlocks();
// je rajoute les index pour chaque bloc lié à un each
_this._indexEachBlocks();

if (!_this._onlyHTML) {
if (!_this._onlyHTML) {

// Je maj les attributs associés aux Abe qui sont dans des attributs de tag HTML
_this._updateAbeAsAttribute();
// Je maj les attributs associés aux Abe qui sont dans des attributs de tag HTML
_this._updateAbeAsAttribute();

// je rajoute les attributs pour les tags Abe (qui ne sont pas dans un attribut HTML)
_this._updateAbeAsTag();
// je rajoute les attributs pour les tags Abe (qui ne sont pas dans un attribut HTML)
_this._updateAbeAsTag();

// Don't know what it does...
source = _.config.source.name;
// Don't know what it does...
source = _.config.source.name;

if (typeof json[source] !== 'undefined' && json[source] !== null) {
keys = Object.keys(json[source]);
if (typeof json[source] !== 'undefined' && json[source] !== null) {
keys = Object.keys(json[source]);


for (i in keys) {
replaceEach = new RegExp('<!-- \\[\\[' + keys[i] + '\\]\\][\\s\\S]*?-->', 'g');
for (i in keys) {
replaceEach = new RegExp('<!-- \\[\\[' + keys[i] + '\\]\\][\\s\\S]*?-->', 'g');

_this.template = _this.template.replace(replaceEach, '');
_this.template = _this.template.replace(replaceEach, '');

patAttrSource = new RegExp(' ([A-Za-z0-9\-\_]+)=["|\'].*?({{' + keys[i] + '}}).*?["|\']', 'g');
patAttrSourceMatch = _this.template.match(patAttrSource);
patAttrSource = new RegExp(' ([A-Za-z0-9\-\_]+)=["|\'].*?({{' + keys[i] + '}}).*?["|\']', 'g');
patAttrSourceMatch = _this.template.match(patAttrSource);


if (typeof patAttrSourceMatch !== 'undefined' && patAttrSourceMatch !== null) {
patAttrSourceInside = new RegExp('(\\S+)=["\']?((?:.(?!["\']?\\s+(?:\\S+)=|[>"\']))+.)["\']?({{' + keys[i] + '}}).*?["|\']', 'g');
if (typeof patAttrSourceMatch !== 'undefined' && patAttrSourceMatch !== null) {
patAttrSourceInside = new RegExp('(\\S+)=["\']?((?:.(?!["\']?\\s+(?:\\S+)=|[>"\']))+.)["\']?({{' + keys[i] + '}}).*?["|\']', 'g');

Array.prototype.forEach.call(patAttrSourceMatch, function (pat) {
var patAttrSourceCheck = patAttrSourceInside.exec(pat);
if (typeof patAttrSourceCheck !== 'undefined' && patAttrSourceCheck !== null) {
var checkEscaped = /["|'](.*?)["|']/;
checkEscaped = checkEscaped.exec(patAttrSourceCheck[0]);
if (typeof checkEscaped !== 'undefined' && checkEscaped !== null && checkEscaped.length > 0) {
checkEscaped = escape(checkEscaped[1]);
_this.template = _this.template.replace(patAttrSourceCheck[0], ' data-abe-attr="' + patAttrSourceCheck[1] + '" data-abe-attr-escaped="' + checkEscaped + '" data-abe="' + keys[i] + '" ' + patAttrSourceCheck[0]);
}
Array.prototype.forEach.call(patAttrSourceMatch, function (pat) {
var patAttrSourceCheck = patAttrSourceInside.exec(pat);
if (typeof patAttrSourceCheck !== 'undefined' && patAttrSourceCheck !== null) {
var checkEscaped = /["|'](.*?)["|']/;
checkEscaped = checkEscaped.exec(patAttrSourceCheck[0]);
if (typeof checkEscaped !== 'undefined' && checkEscaped !== null && checkEscaped.length > 0) {
checkEscaped = escape(checkEscaped[1]);
_this.template = _this.template.replace(patAttrSourceCheck[0], ' data-abe-attr="' + patAttrSourceCheck[1] + '" data-abe-attr-escaped="' + checkEscaped + '" data-abe="' + keys[i] + '" ' + patAttrSourceCheck[0]);
}
});
}
}
});
}

eachSource = new RegExp('({{#each ' + keys[i] + '}[\\s\\S a-z]*?{{/each}})', 'g');
matches = _this.template.match(eachSource);
eachSource = new RegExp('({{#each ' + keys[i] + '}[\\s\\S a-z]*?{{/each}})', 'g');
matches = _this.template.match(eachSource);

if (typeof matches !== 'undefined' && matches !== null) {
Array.prototype.forEach.call(matches, function (match) {
_this.template = _this.template.replace(match, match + '<!-- [[' + keys[i] + ']] ' + util.encodeAbe(match) + ' -->');
});
}
if (typeof matches !== 'undefined' && matches !== null) {
Array.prototype.forEach.call(matches, function (match) {
_this.template = _this.template.replace(match, match + '<!-- [[' + keys[i] + ']] ' + util.encodeAbe(match) + ' -->');
});
}
}
}
}

_this._addSource(json);
_this._addSource(json);

// We remove the {{abe type=data ...}} from the text
_this.template = _.Util.removeDataList(_this.template);
// We remove the {{abe type=data ...}} from the text
_this.template = _.Util.removeDataList(_this.template);

// It's time to replace the [index] by {{@index}} (concerning each blocks)
_this.template = _this.template.replace(/\[index\]\./g, '{{@index}}-');
// It's time to replace the [index] by {{@index}} (concerning each blocks)
_this.template = _this.template.replace(/\[index\]\./g, '{{@index}}-');

if (_.config.files.templates.precompile) {
// Let's persist the precompiled template for future use (kind of cache)
_fsExtra2.default.writeFileSync(_this.HbsTemplatePath, _handlebars2.default.precompile(_this.template), 'utf8');
_.Manager.instance.addHbsTemplate(templateId);
}
if (_.config.files.templates.precompile) {
// Let's persist the precompiled template for future use (kind of cache)
_fsExtra2.default.writeFileSync(_this.HbsTemplatePath, _handlebars2.default.precompile(_this.template), 'utf8');
_.Manager.instance.addHbsTemplate(templateId);
}

// I compile the text
compiledTemplate = _handlebars2.default.compile(!_this._onlyHTML ? util.insertDebugtoolUtilities(_this.template) : _this.template);
// I compile the text
compiledTemplate = _handlebars2.default.compile(!_this._onlyHTML ? util.insertDebugtoolUtilities(_this.template) : _this.template);

// I create the html page ! yeah !!!
// I create the html page ! yeah !!!

_this.html = compiledTemplate(json, { data: { intl: _.config.intlData } });
})();
}
_this.html = compiledTemplate(json, { data: { intl: _.config.intlData } });
})();
}

if (this._onlyHTML) {
this.html = _.Hooks.instance.trigger('afterPageSaveCompile', this.html, json);
Expand Down
2 changes: 0 additions & 2 deletions dist/cli/process/update-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

// ./node_modules/.bin/babel-node src/cli/process/publish-all.js ABE_WEBSITE=/path/to/website
// ./node_modules/.bin/babel-node src/cli/process/publish-all.js FILEPATH=/path/to/website/path/to/file.html ABE_WEBSITE=/path/to/website


var pConfig = {};
Array.prototype.forEach.call(process.argv, function (item) {
if (item.indexOf('=') > -1) {
Expand Down
3 changes: 1 addition & 2 deletions dist/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ if (_cli.config.security === true) {
sandbox: ['allow-same-origin', 'allow-scripts', "allow-modals", 'allow-popups', 'allow-forms'],
reportUri: '/report-violation',
objectSrc: [] },
// An empty array allows nothing through
reportOnly: false, // Set to true if you only want browsers to report errors, not block them
setAllHeaders: false, // Set to true if you want to blindly set all headers: Content-Security-Policy, X-WebKit-CSP, and X-Content-Security-Policy.
disableAndroid: false, // Set to true if you want to disable CSP on Android where it can be buggy.
disableAndroid: false, // Set to true if you want to disable CSP on Android where it can be buggy.
browserSniff: true // Set to false if you want to completely disable any user-agent sniffing. This may make the headers less compatible but it will be much faster. This defaults to `true`.
}));
}
Expand Down
2 changes: 1 addition & 1 deletion dist/server/public/libs/bootstrap.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ if ("undefined" == typeof jQuery) throw new Error("Bootstrap's JavaScript requir
c = this.options;return a = b.attr("data-original-title") || ("function" == typeof c.title ? c.title.call(b[0]) : c.title);
}, c.prototype.getUID = function (a) {
do {
a += ~ ~(1e6 * Math.random());
a += ~~(1e6 * Math.random());
} while (document.getElementById(a));return a;
}, c.prototype.tip = function () {
if (!this.$tip && (this.$tip = a(this.options.template), 1 != this.$tip.length)) throw new Error(this.type + " `template` option must consist of exactly 1 top-level element!");return this.$tip;
Expand Down
2 changes: 1 addition & 1 deletion dist/server/public/libs/jquery-2.1.0.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
b(a[h], c, g ? d : d.call(a[h], h, b(a[h], c)));
}return e ? a : j ? b.call(a) : i ? b(a[0], c) : f;
};o.acceptData = function (a) {
return 1 === a.nodeType || 9 === a.nodeType || ! +a.nodeType;
return 1 === a.nodeType || 9 === a.nodeType || !+a.nodeType;
};function K() {
Object.defineProperty(this.cache = {}, 0, { get: function get() {
return {};
Expand Down
Loading

0 comments on commit d687dd4

Please sign in to comment.