Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove log #8

Merged
merged 1 commit into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions dist/bracket.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ return /******/ (function(modules) { // webpackBootstrap
/* global window VERSION */

var settings = {
log: false,

// Extract anything inside [[ ]] to be evaluated as js
evaluate: /\[\[([\s\S]+?(\}?)+)]]/g,

Expand All @@ -85,25 +83,6 @@ return /******/ (function(modules) { // webpackBootstrap
varname: 'model'
};

var logger = {
context: function context(name) {
var result = {
debug: function debug() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

if (settings.log) {
var _console;

(_console = console).log.apply(_console, [name, ': '].concat(args));
}
}
};
return result;
}
};

function compile(tmpl, conf) {
var str = tmpl || '';
var c = Object.assign({}, settings, conf);
Expand All @@ -112,9 +91,6 @@ return /******/ (function(modules) { // webpackBootstrap
str = str
// handle section def
.replace(c.blockDef, function (m, name, args, body) {
var log = logger.context('block.def');
log.debug(name + ' accepting ' + args);

blocks[name] = {
args: args.split(',').map(function (a) {
return a.trim();
Expand All @@ -126,15 +102,10 @@ return /******/ (function(modules) { // webpackBootstrap

// handle section call
.replace(c.block, function (m, name, args) {
var log = logger.context('block.call');

if (!blocks[name]) {
log.debug('Block doesn\'t exist');
return '';
}

log.debug('Calling ' + name + ' with ' + args);

// arg -> value
var argValues = [];
args.replace(c.argValues, function (m2, val) {
Expand All @@ -146,8 +117,6 @@ return /******/ (function(modules) { // webpackBootstrap
return hash;
}, {});

log.debug('Lookup args:', lookup);

var blockStr = blocks[name].body.replace(c.interpolate, function (m2, codeVal) {
var code = codeVal.trim();

Expand All @@ -160,13 +129,11 @@ return /******/ (function(modules) { // webpackBootstrap
// Generate the value by making a scoped function
// e.g. function() { var arg = { test1: '123' }; return arg.test1; }
var valStr = 'var ' + key + '=' + lookup[key] + ';return ' + code + ';';
log.debug('Arg retrieval for ' + code + ' (' + key + ') -> ' + valStr);
var val = Function(valStr)(); // eslint-disable-line

return '\';out+=' + JSON.stringify(val) + ';out+=\'';
});

log.debug('Replaced:', blockStr);
return blockStr;
})

Expand All @@ -185,13 +152,11 @@ return /******/ (function(modules) { // webpackBootstrap
// remove the newlines or '' will break
).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '');

logger.context('template').debug('Generated template function:', str);
return new Function(c.varname, str); // eslint-disable-line
}

var res = {
version: false ? 'test' : ("1.0.2"), // read from package.json
logger: logger,
settings: settings,
compile: compile
};
Expand All @@ -200,10 +165,7 @@ return /******/ (function(modules) { // webpackBootstrap
var isBrowser = typeof window !== 'undefined';

if (isBrowser) {
logger.context('global').debug('Browser context, adding to window.bracket');
window.bracket = res;
} else {
logger.context('global').debug('Node context');
}

exports.default = res;
Expand Down
2 changes: 1 addition & 1 deletion dist/bracket.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* global window VERSION */

const settings = {
log: false,

// Extract anything inside [[ ]] to be evaluated as js
evaluate: /\[\[([\s\S]+?(\}?)+)]]/g,

Expand All @@ -24,19 +22,6 @@ const settings = {
varname: 'model',
};

const logger = {
context: (name) => {
const result = {
debug: (...args) => {
if (settings.log) {
console.log(name, ': ', ...args);
}
},
};
return result;
},
};

function compile(tmpl, conf) {
let str = tmpl || '';
const c = Object.assign({}, settings, conf);
Expand All @@ -45,9 +30,6 @@ function compile(tmpl, conf) {
str = str
// handle section def
.replace(c.blockDef, (m, name, args, body) => {
const log = logger.context('block.def');
log.debug(`${name} accepting ${args}`);

blocks[name] = {
args: args.split(',').map(a => a.trim()),
body,
Expand All @@ -57,15 +39,10 @@ function compile(tmpl, conf) {

// handle section call
.replace(c.block, (m, name, args) => {
const log = logger.context('block.call');

if (!blocks[name]) {
log.debug('Block doesn\'t exist');
return '';
}

log.debug(`Calling ${name} with ${args}`);

// arg -> value
const argValues = [];
args.replace(c.argValues, (m2, val) => {
Expand All @@ -77,8 +54,6 @@ function compile(tmpl, conf) {
return hash;
}, {});

log.debug('Lookup args:', lookup);

const blockStr = blocks[name].body.replace(c.interpolate, (m2, codeVal) => {
const code = codeVal.trim();

Expand All @@ -91,13 +66,11 @@ function compile(tmpl, conf) {
// Generate the value by making a scoped function
// e.g. function() { var arg = { test1: '123' }; return arg.test1; }
const valStr = `var ${key}=${lookup[key]};return ${code};`;
log.debug(`Arg retrieval for ${code} (${key}) -> ${valStr}`);
const val = Function(valStr)(); // eslint-disable-line

return `';out+=${JSON.stringify(val)};out+='`;
});

log.debug('Replaced:', blockStr);
return blockStr;
})

Expand All @@ -116,13 +89,11 @@ function compile(tmpl, conf) {
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1')
.replace(/\+''/g, '');

logger.context('template').debug('Generated template function:', str);
return new Function(c.varname, str); // eslint-disable-line
}

const res = {
version: typeof VERSION === 'undefined' ? 'test' : VERSION, // read from package.json
logger,
settings,
compile,
};
Expand All @@ -131,10 +102,7 @@ const res = {
const isBrowser = (typeof window !== 'undefined');

if (isBrowser) {
logger.context('global').debug('Browser context, adding to window.bracket');
window.bracket = res;
} else {
logger.context('global').debug('Node context');
}

export default res;