Comments (6)
please send me a simple test case (including code) to help me reproduce this, thanks.
from dmd.
{{#if ($ xy '==' 'abc')}}
id: {{id}}
longname: {{longname}}
name: {{name}}
{{/if}}
/**
* Function to handle generic expressions,
* can handle arbitrarily many arguments for math, but only one conditional (use subexpressions for nesting)
*
* example calls:
* {{123 '+' 456}}
* {{#if (7 '-' 3 '===' 4)}}
* {{false '||' true}}
* {{#if (2 '+' 3 '>' 4 '||' (7 '/' 3 '<' 6 '&&' (1 '!=' 2)))}}
* {{> global/svg-icon icon=('graph' + 'line')}}
*
* @returns {mixed} returns a result or a boolean, dependant on the call
*/
$: function () {
if (arguments.length === 1) {
return false;
}
var options = arguments[arguments.length - 1];
var equation = Object.keys(arguments).map(x => arguments[x]).slice(0, -1); // ecma 6 transform to array
// solve simple math
for (var i = 0; i < equation.length-1 && equation.length >= 3;) {
if (equation[i] === '+') {
if (equation[i-1] && equation[i+1]) {
equation.splice(i-1, 3, (equation[i-1]) + (equation[i+1]));
} else if (equation[i-1]) {
equation.splice(i-1, 3, (equation[i-1]));
} else if (equation[i+1]) {
equation.splice(i-1, 3, (equation[i+1]));
} else {
throw 'Invalid call to function.';
}
} else if (equation[i] === '-') {
equation.splice(i-1, 3, (equation[i-1] || 0) - (equation[i+1] || 0));
} else if (equation[i] === '*') {
equation.splice(i-1, 3, (equation[i-1] || 0) * (equation[i+1] || 0));
} else if (equation[i] === '/') {
equation.splice(i-1, 3, (equation[i-1] || 0) / (equation[i+1] || 0));
} else {
++i;
}
}
if (equation.length === 3) {
// compare (remaining) arguments
if (equation[1] === '===') {
return equation[0] === equation[2];
} else if (equation[1] === '==') {
return equation[0] == equation[2];
} else if (equation[1] === '!=') {
return equation[0] != equation[2];
} else if (equation[1] === '!==') {
return equation[0] !== equation[2];
} else if (equation[1] === '<') {
return equation[0] < equation[2];
} else if (equation[1] === '<=') {
return equation[0] <= equation[2];
} else if (equation[1] === '>') {
return equation[0] > equation[2];
} else if (equation[1] === '>=') {
return equation[0] >= equation[2];
} else if (equation[1] === '&&') {
return equation[0] && equation[2];
} else if (equation[1] === '||') {
return equation[0] || equation[2];
} else {
throw 'Invalid call to function.';
}
} else if (equation.length === 2) {
if (equation[0] === '!') {
return !equation[1];
} else if (equation[0] === '-') {
return -equation[1];
} else {
throw 'Invalid call to function.';
}
} else if (equation.length === 1) {
// return value
return equation[0];
}
throw 'Invalid call to function.';
}
from dmd.
and how are you calling jsdoc2md? Can you send details of the command you are running.. thanks.
from dmd.
I use it as a gulp-task:
/**
* API
* Generates API files out of JSDOC within .js files
*/
gulp.task('build:api', function () {
const jsdoc2md = require('jsdoc-to-markdown');
const files = [];
return gulp.src('./src/_global/production/scripts/**/*.js')
.pipe(through(function(file, encoding, done) {
files.push(file.path);
done(null, file);
}))
.on('end', function() {
files.forEach(function(file) {
fs.writeFileSync(
'./src/_global/documentation/partials/_doc-helper/api/' + path.basename(file) + '.hbs',
jsdoc2md.renderSync({
files: file,
partial: './src/_global/documentation/partials/_doc-helper/api/jsdocOverrides/*.hbs',
lang: 'js',
'no-gfm': true,
separators: true,
moduleIndexFormat: 'dl',
noCache: true,
configure: './jsdoc.json',
})
);
});
});
});
from dmd.
where are you passing in the custom helper? The custom helper module should be passed into options.helper.
from dmd.
At the moment I do not passing it into something, as it's registered within my own handlebars config, but nevertheless it's a good advice - I'm going to test it with also passing it into options.helper
// Edit: passing my helpers also to the plugin worked like a charm - thanks a lot! :)
from dmd.
Related Issues (20)
- Add note on how to migrate to V2 HOT 3
- Upgrade Handlebars package HOT 2
- Is there a way to suppress a specific tag without editing the partial? HOT 2
- whitespace at the end of a line HOT 1
- Pipes aren't escaped in param tables HOT 3
- Update handlebars to address three security vulnerabilities HOT 6
- failing when cache-point is 0.4.1 HOT 3
- Security: Update handlebars HOT 2
- Update Handlebars HOT 2
- Support Gitiles markdown rendering HOT 3
- {@link <namepath>} will break if "{@link" is at line ending
- {@link <namepath} will break if "{@link" is at line ending HOT 2
- @typicalname separation for any parent HOT 4
- Some jsdoc properties not being returned from the params function. HOT 6
- Address npm-audit warning about handlebars HOT 1
- security advisory in [email protected] HOT 2
- NPM audit warning for [email protected] HOT 1
- Mark async functions appropriately
- Handlebars Partials HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dmd.