Giter Site home page Giter Site logo

leapfrogtechnology / just-handlebars-helpers Goto Github PK

View Code? Open in Web Editor NEW
68.0 68.0 21.0 3.03 MB

A package with common Handlebars helpers.

Home Page: https://yarn.pm/just-handlebars-helpers

License: MIT License

JavaScript 97.90% Shell 2.10%
hacktoberfest handlebars handlebars-helpers javascript just-handlebars-helpers template templating

just-handlebars-helpers's People

Contributors

bipenc avatar dependabot[bot] avatar kabirbaidhya avatar lftrajug avatar mesaugat avatar rhanton avatar ryrob89 avatar sanjeevkpandit avatar thebinitghimire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

just-handlebars-helpers's Issues

Implement the `include` helper

  • The include helper just like what we have in cummings {{{include 'sometemplate abc='xyz'}}}`
  • Improve it's functionality to allow retrieval of the current context information from included templates without having to explicitly provide the data like {{{lead=lead ...}}}

The 'or' operation doesn't seem to work

I have this in my page:

{{log "The or operator: " (or false false)}}

And I get back:

The or operator: true

which is obviously wrong.

If I register a new 'or' helper, where I check the hasOwnProperty then everything works fine:

        Handlebars.registerHelper('or', function () {
            var params =  Array.prototype.slice.call(arguments);
            if ((typeof params[params.length - 1] === 'object')) {
                params.pop();
            }

            for (var index in params) {
                if (params.hasOwnProperty(index) && params[index]) {
                    return true;
                }
            }

            return false;
        });

The or operator: false

Logical operator consistency

Currently logical operators (like and, or) in the helpers are based on Javascript if operator.
Please consider implementing logical operators bases of the way of Handlebars if operator functions.
So that
{{#if (and a b)}} smth {{/if}} would act 100% as {{#if a}}{{#if b}} smth {{/if}}{{/if}}
Currently there are cases (for example empty array) where these two constructions differ and it may result unexpected behaviour in constructions like:

{{# if (or a b)}}
  Found:
  {{#if a}}Element a{{/if}}
  {{#if b}}Element b{{/if}}
{{/if}}

Thank you.

Have List of helpers like a table of contents

  • Have a list of helpers in the README above the Helpers section to give the short overview of what helpers do we have and what they do.
  • The format would be like this:
    | [Helper Name] | [One line description] |

Improvements on ifx helper

The ifx helper just provides a way of using the ternary operator ?: in handlebars.

Currently, we can do this with it:

<li class="{{ifx isEven 'even' 'odd'}}">

But a lot of times we we simply want to return nothing for the else case.
For instance:

<li class="{{ifx isActive 'active' ''}}">
<li class="{{ifx isUnavailable 'unavailable' ''}}">
<li class="{{ifx isUnavailable 'unavailable' ''}}">

So, I think we need to make the third parameter for {{ifx}} optional with a default value empty string ("").
So, we can just omit the else case like this:

<li class="{{ifx isActive 'active'}}">
<li class="{{ifx isUnavailable 'unavailable'}}">
<li class="{{ifx isUnavailable 'unavailable'}}">

Add `and` and `or` helpers

  • Add and and or helper.
  • For and: this will accept two or more parameters and return true if all of them are true.
  • For or: this will accept two or more parameters and return true if any of them is true.
  • This will allow us to do:
{{#if (and value1 value2) }}
    // do Something
{{else}}
    // do something else
{{/if}}

{{#if (or value1 value2) }}
    // do Something
{{else}}
    // do something else
{{/if}}

how to avoid conflicts with naming when we use variables inside with block helper?

Hi.
From backend I received this data

{
count: '...'',
hasResult: true,
query: '123', // input value
}

and my template is something like this

{{#with this}}
	{{#if hasResult}}
		For your query <strong>"{{query}}"</strong> found <strong>{{count}} peoples</strong>
	{{else}}
		Peoples not found
	{{/if}}
{{/with}}

I spent a lot of time trying to understand why instead of the value, a lie is returned to me before I realized that I connected your package with helper that have same name as "count".

How to avoid this with continue to use with (I like to use direct variables comp. to this.someValue)
Thanks!

Need an array helper contains or includes

This helper should check whether or not the array contains an element and return boolean.

Something like this:

var array = [1, 2, 3];
var value = 2;

{{includes array value}}

Since it returns a boolean, we can use it in any conditional helpers like:

{{#if (includes array value)}}
   <!-- Do something -->
{{/if}}

Includes = {{ifx (includes array value) 'Yes' 'No'}}

Proper formatting of JSDoc

Change the current set of JSDoc to use a proper standard.

Right now we have this:

/**
 * Determine whether or not two values are equal (==) i.e weak checking.
 * @example
 *      {{eqw '3' 3}}   => true
 *
 * @param value1
 * @param value2
 * @returns boolean
 */
export function eqw(value1, value2) {
  return (value1 == value2);
}

We are missing the type of parameter in all places. Need to update all the JSDoc blocks throughout the repository.

Example:

/**
 * Determine whether or not two values are equal (==) i.e weak checking.
 * @example
 *      {{eqw '3' 3}}   => true
 *
 * @param {any} value1
 * @param {any} value2
 * @returns {boolean}
 */
export function eqw(value1, value2) {
  return (value1 == value2);
}

Our docs does include the parameter type. We need to do the same in our code.

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.