cobalt.rs
cobalt.rs copied to clipboard
RFC: User-defined plugins
We'd have a new folder _plugins
full of FILLER that we load.
Plugins include
- Liquid tags, blocks, and filters
- For tags and blocks, we just parse all parameters as named or position arguments without any validating logic (ie
Vec<(Option<KString>, Value)>
) until end of%}
. We then pass that to the plugin to deal with - Plugins can just accept these as arguments
- Plugins can turn these into a form of syntax like treating one of the elements as a keyword
- For tags and blocks, we just parse all parameters as named or position arguments without any validating logic (ie
Open questions
- What language?
- Lua is well know
- Rhai would integrate well with Rust
- Dyon and Gluon are from the game community
- Plugin per file or multiple in a file?
- If multiple, whats the idiomatic way to do it for the given language?
Can you develop what kind of plugins?
On the language, I'd vote for Rhai, because Rust. And I have bad past experience with Lua (I don't know if it's still true, but the "if not marked as local, it's global) made me freak out a lot
Can you develop what kind of plugins?
So far the only ones I've thought are are listed:
Liquid tags, blocks, and filters
So say you want a custom shortcode plugin ({% youtube id="foobar" %}
). In python (since I don't know the embedded languages) it'd look like
def plugins():
return {
"tag": {
"youtube": youtube_shortcode,
}
}
def youtube_shortcode(arguments):
args = {}
for name, value in arguments:
if name is None:
raise ValueError("Only named arguments are supported")
elif name in ["id"]:
args[name] = value
else:
raise ValueError("Unsupported argument: %s" % name)
... do formatting ...
return full_url
I see :) (Even if for shortcodes, I have something in antimoine to load custom shortcode, so they're easier to write, but maybe plugins is a better way?)
I see :) (Even if for shortcodes, I have something in antimoine to load custom shortcode, so they're easier to write, but maybe plugins is a better way?)
Shortcodes was a trivial example that can be solved in multiple ways. Other extensibilty ideas include filter-blocks and macros
https://github.com/cobalt-org/liquid-rust/issues/321 https://github.com/cobalt-org/liquid-rust/issues/322
If plugins are supported, having the ability to write custom generators in Rust would be nice.
I'd love to port https://github.com/avillafiorita/jekyll-datapage_gen/ and https://github.com/captn3m0/jekyll-sqlite/ for eg.