ttscoff / bunch

Documentation repository for Bunch.app
https://bunchapp.co
116 stars 5 forks source link

Boolean Snippet variable not working when assigned when defined in snippet file line #219

Closed ejf071189 closed 2 years ago

ejf071189 commented 2 years ago

Given the following snippet:

* say "${saying:No saying defined}"
if bool
    * say "True"
else
    * say "False"
end

The following is saying "Saying defined", "False"

<snippet-with-conditional-logic.test
- bool=true
- saying=Saying defined

While the following is saying "Saying defined", "True"

---
bool: true
---
<snippet-with-conditional-logic.test
- bool=${bool}
- saying=Saying defined

I'm using the Bunch Beta v1.4.8

ttscoff commented 2 years ago

Definitely something weird going on with variables read from snippet file lines. If I rename the variable from bool to testvar, and change the if statement to if testvar is true, then everything works with the file lines. But all of it works with no changes if the variable is set in frontmatter, which is very confusing.

I'll have to debug this line by line to figure out why there's a difference. Why does the variable name matter in some cases, and why does the if statement require is true in one case and not the other? This could take me a little bit to solve.

-Brett

On 3 Jun 2022, at 18:40, ejf071189 wrote:

Given the following snippet:

* say "${saying:No saying defined}"
if bool
    * say "True"
else
    * say "False"
end

The following is saying "Saying defined", "False"

<snippet-with-conditional-logic.test
- bool=true
- saying=Saying defined

While the following is saying "Saying defined", "True"

---
bool: true
---
<snippet-with-conditional-logic.test
- bool=${bool}
- saying=Saying defined

I'm using the Bunch Beta v1.4.8

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/bunch/issues/219 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

ejf071189 commented 2 years ago

So did you need to do both of those to make it work? (change the variable name AND the if statement) As a workaround, I'd be fine going through all of my if statements and just doing "if foo is true" across the board to make this work for both frontmatter/file lines.

ttscoff commented 2 years ago

Yes, I had to make both alterations as "bool" seems to fail as a variable name (not sure why). However, here's what I figured out:

Because of the order that snippets are inserted versus when variables are replaced, the variable set in the file line isn't available at the time that the condition is tested. Those are very temporary variables that don't affect the more static frontmatter variables, as they're intended to be transient and only apply to the snippet that's being called. The solution is to use ${var} syntax in the condition instead of just the bare variable name.

if ${bool}
  ...

The reason for this is a bit complicated, but basically at the time the snippet variables are updated, the file line variable is present but it's only looking to replace ${var} placeholders. By the time it gets to processing the logic portion, that variable has ceased to be populated. When it's set using front matter or a variable assignment outside of the snippet, the value is held statically and can be used. Does that make sense?

I don't want to change this behavior as it would require persisting the transient "file line" variables outside of the scope they were attached to. I might choose to process if/then statements within a snippet at the time they're inserted, but that leads to complications of its own.

ttscoff commented 2 years ago

Now that I've said that I've decided to try just running the conditional parsing inside of the snippet at the time it's imported. I think that will work fine without causing any further issues. Watch for build 141 to hit the beta channel in a little bit. Please download that beta and help me test it before I release this change to the main channel. You can access beta builds on the download page.

ejf071189 commented 2 years ago

My boy, you're as much a mad genius as the podcasters claim!

I'm getting a 403 when trying to access the beta download, is that just temporary?

Just joined your memberful as well!

ttscoff commented 2 years ago

Also, drop me a line via https://brettterpstra.com/contact/ to let me know what email address you want to use to join the paid subscriber mailing list. I don't have direct integration with memberful or paypal subscriptions, so I have to manually add subscribers to the (very low-traffic list).

On 7 Jun 2022, at 11:13, ejf071189 wrote:

My boy, you're as much a mad genius as the podcasters claim!

I'm getting a 403 when trying to access the beta download, is that just temporary?

Just joined your memberful as well!

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/bunch/issues/219#issuecomment-1148879614 You are receiving this because you commented.

Message ID: @.***>

ejf071189 commented 2 years ago

Done! (At least I think, I didn't get a confirmation at my own email)

ttscoff commented 2 years ago

This has made me realize that --- for the same reason my beta downloads broke --- my contact form was also broken. Who knows how many emails I've lost since I got this Mac Studio… but if you could submit your email one more time, I've tested and am certain it's working now. Sorry about that.

ejf071189 commented 2 years ago

Haha happy to point out another bug in your life and hope it wasn't too much data loss for you! Just filled the form again and downloaded the beta. I'll do a test later today!

ejf071189 commented 2 years ago

Sorry for the delay but I downloaded the beta, tested the files in this issue as well as others and as far as I can tell, everything is working as I would expect!

ttscoff commented 2 years ago

Interesting. This will take some testing. Variable inheritance got a little complex at one point, but a file line in a snippet call should absolutely work. Will get to this as soon as I have time.

On 3 Jun 2022, at 18:40, ejf071189 wrote:

Given the following snippet:

* say "${saying:No saying defined}"
if bool
    * say "True"
else
    * say "False"
end

The following is saying "Saying defined", "False"

<snippet-with-conditional-logic.test
- bool=true
- saying=Saying defined

While the following is saying "Saying defined", "True"

---
bool: true
---
<snippet-with-conditional-logic.test
- bool=${bool}
- saying=Saying defined

I'm using the Bunch Beta v1.4.8

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/bunch/issues/219 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

ttscoff commented 2 years ago

Sorry, permissions snafu when I swapped over to a new Mac. Should be fixed now, let me know if you still can't download.

On 7 Jun 2022, at 11:13, ejf071189 wrote:

My boy, you're as much a mad genius as the podcasters claim!

I'm getting a 403 when trying to access the beta download, is that just temporary?

Just joined your memberful as well!

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/bunch/issues/219#issuecomment-1148879614 You are receiving this because you commented.

Message ID: @.***>