Comments (6)
Is this a Rust variable or a Liquid variable?
from liquid-rust.
It's a complex rust struct that can contain HashSets, my own structs, etc.
from liquid-rust.
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.
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.
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.
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)
- with_time unimplemented HOT 3
- Change `master` branch to `main` HOT 3
- could not compile kstring HOT 1
- Render Tag HOT 3
- EmptyDrop and Object indexing HOT 7
- Make struct InnerError public HOT 1
- Open to the idea of supporting less strict parsing/rendering as an option? HOT 3
- Can't render dates with millisecond precision HOT 1
- No way to return a reference for the values method of trait ObjectView
- Dependency Dashboard
- Question: supporting object literals with unknown keys on custom filters HOT 8
- Thoughts on implementing `From<serde_json::Value> for liquid_core::Value`? HOT 2
- How do you use `{% include x.liquid %}`? HOT 5
- Liquid Tag and Echo Tag
- How would you go about implementing a Drop HOT 3
- Add support for u64 numbers?
- Inline comments are not supported HOT 1
- Hash access to globals produces parse error
- New release? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liquid-rust.