Giter VIP home page Giter VIP logo

Comments (6)

epage avatar epage commented on June 25, 2024

Is this a Rust variable or a Liquid variable?

from liquid-rust.

holly-hacker avatar holly-hacker commented on June 25, 2024

It's a complex rust struct that can contain HashSets, my own structs, etc.

from liquid-rust.

epage avatar epage commented on June 25, 2024

Thanks. Got some more questions to try to understand the need and how we might be able to fill it.

Is the data coupled to the specific render call? Or are you needing to know when each render call starts and ends? If neither, would it work to pas this into your tag's constructor as an Arc<Mutex<T>>?

Even if its just knowing the start/end of each render call, we can look into options of telling tags when we are starting a new render. Granted, there are threading issues with this and if you are rendering from multiple threads, then you might need to rely on TLS or thread ids.

Also, could you expand on the use case? Why is the rust code and the termplate needing to interact like this?

from liquid-rust.

holly-hacker avatar holly-hacker commented on June 25, 2024

I'm using liquid as the templating system for a content-first story engine and I have some custom tags/blocks for very basic operations such as checking or setting variables. These operations happen inside the liquid content since they're very tied to the story. More complex operations happen through a scripting language.

I'm running from wasm so everything is single-threaded. I just look up the liquid template, parse it, pass it some globals and then render it. After rendering I want it to have updated some data based on what the template contained.

My initial idea was be use the Registers struct to pass in a reference (or Rc<RefCell<T>>, or multi-threaded equivalent) which my tags can access and update. Passing in a full copy of the data and extracting it after rendering would be fine too.

Is this more clear? I understand my usecase may not be the typical one for liquid, but it's the best tool I found for the job that doesn't involve writing my own templating engine.

from liquid-rust.

epage avatar epage commented on June 25, 2024

Wow, that is a fun use case! That definitely helps understand the requirements for your use case.

So far the focus has been on more mundane cases where you you want to avoid rendering being stateful because that'd lead to bugs.

Its been a while since I've look at this part of liquid but I think registers can make sense for how we could allow this longer term.

One short term option is to pass the Rc<RefCell<T>> into your tag before passing your tag to liquid. This does mean you'd have the same state for the lifetime of your Parser and Template. It sounds like that might work for you but you'd know best. I actually wonder if this is better than registers.

from liquid-rust.

holly-hacker avatar holly-hacker commented on June 25, 2024

I just did a quick test and passing to the tags constructor seems to work! I need to use Arc<Mutex<MyState>> because tags are required to be Send+Sync, but the performance difference is negligible in my usecase. That solves my issue :)

I'll close this issue for now but feel free to re-open it if you want to track a change related to it (such as exposing Registers). Thanks for the help!

from liquid-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.