Closed razonyang closed 4 years ago
Can't pull v3.0.0 I am a novice and I don’t know what caused the problem
@codexuexi go get github.com/CloudyKit/jet/v3@latest
should get you v3. You will also have to use github.com/CloudyKit/jet/v3
wherever you import jet.
@razonyang v4 is coming! I just want to make sure the changes are documented, especially breaking ones.
@codexuexi What is the output of the following command?
go get -u github.com/CloudyKit/jet/v3
No output means pull successfully. You also need to change Jet's import path as github.com/CloudyKit/jet/v3
.
BTW, you should open a new issue for discussing since it is unrelated to the original topic.
@razonyang
Thank you, you can use this command
I use
go get -u github.com/CloudyKit/jet@v3
Can't get the result i want
@sauerbraten I'm looking forward to it, but in fact, code completion and highlighting are very popular among people like IntelliJ
and Visual Studio Code
After all, we all like a simple and fast experience
@sauerbraten That's great!
BTW, v3.0.0
seems unable to parse nil
variable, it works fine in master
, could you please confirm this bug has been fixed?
set := jet.NewHTMLSet("./")
t, _ := set.GetTemplate("index.tmpl")
buf := &bytes.Buffer{}
vars := jet.VarMap{}
vars.Set("user", nil)
if err := t.Execute(buf, vars, nil); err != nil {
log.Fatal(err)
}
fmt.Println(buf.String())
{{ if user }}
Authenticated
{{ else }}
Guest
{{ end }}
v3.0.0
:
Jet Runtime Error ("index.tmpl":1): identifier "user" is not available in the current scope map[user:<invalid Value>]
exit status 1
v3.0.0@master
:
Guest
@codexuexi: the command you use is simply wrong.
In Go, major versions > 1 require the module import path to be different. Jet v3's module import path is github.com/CloudyKit/jet/v3
, not github.com/CloudyKit/jet
.
You have to use something like I or @razonyang showed you in order to use version 3 or later of Jet.
I am also not sure what you mean with this:
but in fact, code completion and highlighting are very popular among people like IntelliJ and Visual Studio Code
I never said anything different, I never even touched that subject. Do you have in issue with IDE support? If so, please open an issue, or comment in one that's related to IDE support.
@razonyang: But you said yourself that it works on the current master? Didn't you confirm the bug has been fixed yourself?
@sauerbraten Yes, it works on the current master, but I didn't look into the source code, I am not quite sure that it has been fixed.
I guess you mean you're not sure the bug is fixed, even though your example code works now?
It's fixed: compare https://github.com/CloudyKit/jet/blob/v3.0.0/eval.go#L1096 to https://github.com/CloudyKit/jet/blob/697e9c8c48aaa93f43eaeb80812d5f8fcebafd7f/eval.go#L1074.
In v3.0.0, any identifier evaluating to nil
would cause a panic, because Resolve() returned the reflect equivalent of nil
in case it doesn't find anything, but also when the value was simply set to nil
. Outside of Resolve(), there was no way to know which of these two things happened.
Now, resolve()
returns an error if the variable can't be found anywhere, which means we know what happened when evaluating users
in your example: it was resolved just fine, and we let if
check wether it's truthy (which it isn't).
Hope this puts you at ease! 👍
Months have passed since the last version, would you please draft a new version.