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

Support special characters as key names in dust #229

Open
vybs opened this issue Feb 9, 2013 · 9 comments
Open

Support special characters as key names in dust #229

vybs opened this issue Feb 9, 2013 · 9 comments

Comments

@vybs
Copy link
Contributor

vybs commented Feb 9, 2013

Support a use case "a.b.c" : " You are here"

Note: the json key itself has .

One way to solve is allow {a.b.c} to render the a.b.c. as the key ans not compile the same to getPath

https://github.com/linkedin/dustjs/blob/master/src/dust.pegjs

-------------------------------------------------------------------------------------------------------------------------------------
key is defined as a character matching a to z, upper or lower case, followed by 0 or more alphanumeric characters
---------------------------------------------------------------------------------------------------------------------------------------
/
key "key"
= h:[a-zA-Z_$] t:[0-9a-zA-Z_$-]*
{ return h + t.join('') }

@ghost ghost assigned vybs Feb 9, 2013
@baohouse
Copy link

Haha, my use case is worse, it has a colon in the key!
{>controlDropdown label=Messages.Plan_Account:Business /}

I'm thinking there has to be a way to either escape special characters, or to somehow specify strings for the keys.

@rragan
Copy link
Contributor

rragan commented Jan 28, 2014

Need a good syntax and then a compiler change could provide this. This might work {['string']}. It would be analogous to the ['xxx'] property reference in JS. With both the brackets and the quotes I don't think it would be ambiguous with any existing syntax.

@prashn64
Copy link
Contributor

Agreed Richard.

Also, it should be combinable with our dot seperated references and arrays as well, and I think we should use double quotes to keep with current dust syntax. So I propose these be all the use cases:

{["foo.bar"]}
{.["foo.bar"]}
{["#{}'><'foo.bar"]}
{["foo".b"ar"]}
{baz["foo.bar"]}
{baz["foo.bar"].fiz}
{baz[1]["foo.bar"]}
{baz[1]["foo.bar"].fiz}
{baz[1].fiz["foo.bar"]}

Basically anything that gets put inside [""] that is contained in a reference would be treated as the literal key name and not try to do any special dust logic on it. Not putting a dot between baz and the literal reference is to keep it aligned with the Javascript syntax and the pattern already exists with arrays in dust. If you have double quotes in the key name, you would have to escape them in the template.

Does this sound reasonable/cover all the cases?

EDIT: Added {.["foo.bar"]}

@rragan
Copy link
Contributor

rragan commented Mar 18, 2014

Seems complete but you might want to add an example of {.["foo.bar"]}.

They are strings so all Unicode chars but no control chars including line breaks but see http://timelessrepo.com/json-isnt-a-javascript-subset for an edge case. What about \unnnn? Probably want it.

@prashn64
Copy link
Contributor

For the line break and paragraph seperator cases, we can let whatever the generates the JSON handle it, since it's such a small edge case, so it's probably not worth adding the special replaces for them.

What's \unnnn? I couldn't find much info on it.

@rragan
Copy link
Contributor

rragan commented Mar 18, 2014

\unnnn lets you enter arbitrary Unicode value in a string. See JS string rules.

@rchawdry
Copy link

Would be nice to have. Working on a project that is converting XML to JSON for rendering. The generated JSON preserves the XML namespaces, (i.e. nc:Person), but I can't use that as is with dustjs

@ghost
Copy link

ghost commented Nov 24, 2015

Any news on this?

Edit: How did I unassigned vybs? I didn't want to

@ghost ghost unassigned vybs Nov 24, 2015
@sethkinast
Copy link
Contributor

We'd still like to do this; I have some thoughts on it once I get time to work on dust core.

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

6 participants