Handlebars-Net / Handlebars.Net.Helpers

Handlebars.Net helpers in the categories: 'Boolean', 'Constants', 'Enumerable', 'Environment', 'Math', 'Regex', 'String', 'DateTime' and 'Url'.
MIT License
38 stars 14 forks source link

Compatibility with Handlebarsjs (and Handlerbars.CSharp)? #7

Closed oformaniuk closed 3 years ago

oformaniuk commented 4 years ago

The problem

According to Handlebars helper documentation:

A Handlebars helper call is a simple identifier, followed by zero or more parameters

and Identifier definition:

Identifiers may be any unicode character except for the following: Whitespace ! " # % & ' ( ) * + , . / ; < = > @ [ \ ] ^ ` { | } ~

It looks like usage example is not valid:

{{String.Append "foobar" "bar"}}

In order to be rendered correctly it should be:

{{[String.Append] "foobar" "bar"}}

Simple example of Handlebarsjs behavior using suggested syntax: https://jsfiddle.net/bc89sjmg/1/

In Handlerbars.CSharp I've followed the same approach to be as close to Handlebarsjs as possible. Changes related to the topic were made in zjklee/Handlebars.CSharp/pull/20 and zjklee/Handlebars.CSharp/pull/21

StefH commented 4 years ago

@zjklee This is only for normal helpers, not for block-helpers? Correct?

StefH commented 4 years ago

https://github.com/StefH/Handlebars.Net.Helpers/pull/8

oformaniuk commented 4 years ago

@zjklee This is only for normal helpers, not for block-helpers? Correct?

Unfortunately this is true also for block helpers.

oformaniuk commented 4 years ago

I assume that a lot of users rely on this behavior so I consider adding compatibility switch to Handlebars that would allow using helpers as before.

StefH commented 4 years ago

How would this template be used when using a prefix of "String." ?

"{{#StartsWith \"Hello\" \"x\"}}Hi{{else}}Goodbye{{/StartsWith}}"

"{{#String.StartsWith \"Hello\" \"x\"}}Hi{{else}}Goodbye{{/String.StartsWith}}" does not work?

oformaniuk commented 4 years ago

@StefH Unfortunately it wouldn't work with prefix - take a loot at an example: https://jsfiddle.net/bc89sjmg/2/

As a valid alternative to prefixes separated by . I may recommend using - instead, see https://jsfiddle.net/bc89sjmg/3/

StefH commented 4 years ago

In this library, I'll also add a PrefixSeparator option which can be set to any value, default however will be a dot ..