Git Product home page Git Product logo

Comments (6)

75lb avatar 75lb commented on June 25, 2024

please send me a simple test case (including code) to help me reproduce this, thanks.

from dmd.

jennifer-sevenval avatar jennifer-sevenval commented on June 25, 2024
  {{#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.

75lb avatar 75lb commented on June 25, 2024

and how are you calling jsdoc2md? Can you send details of the command you are running.. thanks.

from dmd.

jennifer-sevenval avatar jennifer-sevenval commented on June 25, 2024

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.

75lb avatar 75lb commented on June 25, 2024

where are you passing in the custom helper? The custom helper module should be passed into options.helper.

from dmd.

jennifer-sevenval avatar jennifer-sevenval commented on June 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.