-
Notifications
You must be signed in to change notification settings - Fork 77
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
feat(value): Add null value #140
Conversation
My hope has been to avoid the billion dollar mistake. Is there a use case for you to have null in your data? |
Well, this is for parsing data in cobalt, where any json can contain a I don't think we are repeating that case here but are downwards compatible to those formats. We aren't repeating that problem, as all values have a way to be checked for being empty and will before interacting with it and I see your point that this might not be something we want in liquid though and therefore should be handled inside cobalt (where I'd argue, we should be able to parse any valid JSON and |
What is the reason for having null in your cobalt data? Is it because you are loading a existing data source and don't plan to touch the null part of the data? Do you need to touch the null part and need liquid to handle it gracefully?
Really, the question is whether we are loading arbitrary json/yaml/toml or loading liquid values. My initial impression is to load liquid Values unless someone has a reasonable use case that can't be supported. |
Thanks for the use case. I am fine moving forward with this. |
52de3ef
to
7cda923
Compare
@epage it's green. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I know I said we just needed green. If you want, this can go in now and we can open issues on these comments.
src/value.rs
Outdated
@@ -164,6 +165,7 @@ impl ToString for Value { | |||
Value::Num(ref x) => x.to_string(), | |||
Value::Bool(ref x) => x.to_string(), | |||
Value::Str(ref x) => x.to_owned(), | |||
Value::Null => "null".to_owned(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just thought about this last night. Are we aligned with Shopify on this?
Does it matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, what we use the ToString
for within templates. From the Shopify docs it is rather vague how this would come to be used. In their cheat sheet they only explain Nil
to be falsy
and all other of their filters and loops seem to make a check for truthy-ness before executing, which probably stems from that being the implied case in ruby. And is already a behavior we don't have that way (which we discussed the other day).
I am also happy to make it ""
, which is probably closer to the interpretation of their underlying ruby implementation...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're link answered the question of what ToString
should do
Tags or outputs that return nil will not print anything to the page.
https://help.shopify.com/themes/liquid/basics/types#nil
btw if Shopify calls it Nil
then we probably should too (Value::Nil
).
src/value.rs
Outdated
@@ -16,6 +16,7 @@ pub enum Value { | |||
Str(String), | |||
Array(Array), | |||
Object(Object), | |||
Null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how serde decides that None
gets serialized as this.
We should add a serde test for this
https://github.com/cobalt-org/liquid-rust/blob/master/tests/value.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly have no idea. I don't really get the inner-workings of serde -- but it is on my bucket list :D .
I used serde_json as the base and it defined Null
in their value and in JSON there also is no None
but only null
. For TOML and YAML I am not even sure a nothing-type even exists, I think it is just represented as empty strings ...
Thanks for making the changes! |
@epage don't be too happy to soon. I pushed before fixing the commit logs because the tests is going mad on me and wanted your input on it:
Any ideas? |
I wonder if |
This adds the missing Nil (null) type to the values of liquid, thus allowing to parse serde_json and others containing null-values in the data directly
3973c0b
to
89f6660
Compare
I assume you'd like me to publish liquid and cobalt with this as soon as possible? |
This adds the missing null type to the values of liquid, thus allowing to
parse serde_json and others containing null-values in the data directly