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

Make placeholders case-insensitives for non-developers friendliness #46

Open
8BitJonny opened this issue Oct 17, 2020 · 4 comments
Open

Comments

@8BitJonny
Copy link
Contributor

The Issue

Hey, it's me again 😄

This ticket is about a small thing I noticed while working with the library and that is that formatter names are forced into lowercase.

I noticed it when I had a placeholder like {{ name | getFirstname }} and the corresponding formatter in code function getFirstname(name) {...}
When you then interpolate like this

const fileID = await mustaches.interpolate({
      source,
      data,
      destination,
      formatters: { getFirstname },
    });

it won't work. It'll throw you: Error: getfirstname is not defined in strict mode (note the the lowercase getfirstname when both the placeholder and the provided formatter are camel case.

This is because of this line right here and I just don't quite get why the .toLowerCase() is needed here

const formatterName = matches.groups.formatter.toLowerCase()
const formatter = formatters[formatterName]

I would just propose to remove the .toLowerCase() or why is it necessary there?

@Errorname
Copy link
Owner

Hi again 🙂

That's a good issue/question that I hadn't considered! What I see about the usage of google-docs-mustaches, is that it allows non-developers to write google-docs template. Because of that, those type of users may not know the importance of the casing when using placeholders/formatters. (They may write getfirstname or GetFirstName or GETFIRSTNAME)

So instead of throwing errors that they may not understand, I would prefer to allow any casing they prefer. What do you think?

@8BitJonny
Copy link
Contributor Author

That's a very good point!
I haven't considered the non developer friendliness yet but it definitely makes sense and I think your suggestion is the best step in that direction.

Do you want to include that feature in your refactoring?
If not I would be very happy to make a PR for it over the weekend

@Errorname
Copy link
Owner

Errorname commented Oct 23, 2020

I just pushed the first version of the refactoring here: #48. Don't hesitate to have a look and play with it. Having feedbacks would really help 🙂

I haven't included this feature in the refactoring. I think it can be a subsequent PR. If you feel up to it, you can definitely make the PR for this.

Here is what I have in mind (but open to discussion): Casing (except in strings) should be insensitive in placeholders.

{{ Document.User | GETFIRSTNAME | concat(" is OPEN for Business") }}

// Should be the same as:

{{ document.user | getfirsname | concat("is OPEN for Business") }}

An idea would be to "lowercase everything", data and formatters alike, before using them. But we need to make sure to cover such case:

{{ a.B[c(D)].E }}

(The new parser allows for such complicated syntax. I guess the lowercasing could be done in the new parser too?)

Anyway, that's just an idea. Feel free to propose a solution, or discuss it more here. 🙂

@Errorname Errorname changed the title Formatter Names are forced into lowercase Make placeholders case-insensitives for non-developers friendliness Oct 23, 2020
@8BitJonny
Copy link
Contributor Author

@Errorname Sounds good! I really like the idea of doing everything case insensitive and your first idea sounds good.

I'll have a look on Sunday to play with your first version of refactoring and also see how to implement the case insensitivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants