-
-
Notifications
You must be signed in to change notification settings - Fork 259
Utility function to handle empty query results and templates #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hmm. Need to think if the bug isn't really the incompatibility with Lua here. Not sure if we should double down on this being useful. I'd rather make this lua constituent otherwise we're just asking for future trouble. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will be a nice change! I added some minor comments.
website/Space Lua.md
Outdated
@@ -127,10 +129,17 @@ There's a magic `_CTX` global variable available from which you can access usefu | |||
# Lua implementation notes | |||
Space Lua is intended to be a more or less complete implementation of [Lua 5.4](https://www.lua.org/manual/5.4/). However, a few features are (still) missing: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the lead in here should be more inclusive of the following headers. Maybe:
Here are some of the expected differences and planned and not planned features:
website/Space Lua.md
Outdated
* _ENV (planned) | ||
* Full metatable support (only partial now, planned) | ||
## Differences | ||
* empty table `{}` tests false, while in [Lua 5.4](https://www.lua.org/manual/5.4/manual.html#3.3.4) "All values different from **nil** nad **false** test true". However this has a really nice interaction with empty [[Space Lua/Lua Integrated Query|query]] results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo on nad
in the docs quote.
website/Space Lua.md
Outdated
## Planned | ||
* _ENV | ||
* Full [metatable](https://www.lua.org/manual/5.4/manual.html#2.4) support (only partial now) | ||
* Complete [[API/string]] API (some patterns in `gmatch` don’t work correctly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a section to [[API/string]]
about how Lua patterns and Space Lua patterns have some key differences, not just for gmatch
. What do you think about removing:
(some patterns in
gmatch
don’t work correctly)
and adding a bullet to the Differences section above, maybe:
- lua patterns are translated to Javascript regex, so there are some [[API/string|key differences]].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably same comment applies as the empty table truthiness. See link in #1284, maybe we can actually get 100% compatibility?
Essentially we would like to have some behavior like ?? operator. A Lua-compatible solution would be to add a function that checks for truthiness in a different way, appropriate for content:
I'll keep in mind that we're aiming for full Lua compatibility. Then a fully Lua-compatible way would be Yet another conformant solution could be to use metatables to override an operation on the query result. By setting our custom method for
I don't have a strong opinion on which operator to use, I went with XOR because "only one of the inputs is true" This would be completely normal Lua, and even shorter syntax than now (by 1 character xD). I'm not worried about making query function inconsistent with expectations, since it already has special parsing rules, but it may confuse new users as to what Bonus: Maybe this would be a path for composing queries together using some other overridable operators? Like |
I like the |
Moved documentation for 'each' function to non-standard section.
The scope has changed a bit, but I thought that it's better to just reorganize this PR to keep the discussion about possible options. I think this is a more elegant solution, are we OK to remove #1359? Everyone is supposed to know this is unstable version, and I don't recall any changelog or forum talk about that feature. |
Very nice. I like this solution. And indeed I hope/assume people will not have used the extra template.each argument yet, and if so they'll figure it out 😄 |
…ulletmd#1386) * Add global Lua function 'some' Moved documentation for 'each' function to non-standard section. * Revert "Add optional argument to template.each for empty collection output (silverbulletmd#1359)" This reverts commit b73dade. * Reimplement silverbulletmd#1359 using 'some' function
* Adding support for hosting with URL prefix to make reverse-proxy setup on sub-path possible * Adjusting recent changes to auth.html (changing to relative URLs) after rebasing from upstream * Adjusting service_worker and application manifest to support URL-prefix * Add notes on Space Lua Pattern Matching (#1366) * Remove common/space_lua/stdlib/math.md (#1371) * Escape pipe symbol in string.gsub (#1370) * feat: configure vim in CONFIG (#1369) * Fix week calculation (#1368) * Add more tests for week calculation * Fix week calculation * Add more tests * Implement Lua built-in function os.difftime (#1367) * Implement Lua built-in function os.difftime * Test os.difftime --------- Co-authored-by: Zef Hemel <[email protected]> * Fix index page naming during server initialization (#1365) * Allow non-zero shell exit codes (#1377) * Generate version from git describe at build time (#1374) * Generate version from git describe at build time * Add 2.0-beta prefix * Use Deno.Command instead of Deno.run * Add missing case to math.random and check arguments (#1372) * Fix paragraphs for the tag page (#1376) * Render a predefined string for empty markdown table instead of pipe characters (#1387) * Fix string.find (#1390) * Fetch tags and history for proper version string generation (#1388) * Fix support for disabling shortcuts (#1393) * Add GitHub Actions Cache to reduce build times (#1394) * Order strings in queries using collation algorithm (#1391) Configurable with queryCollation, default value maintains old behaviour. Added tests, schema, example settings, and documentation to query page. Close: #614 Close: #1316 * Utility function to handle empty query results and templates (#1386) * Add global Lua function 'some' Moved documentation for 'each' function to non-standard section. * Revert "Add optional argument to template.each for empty collection output (#1359)" This reverts commit b73dade. * Reimplement #1359 using 'some' function * Update Lua to event.listEvents to match plugos syscall (#1397) The documentation, example, and other function names use `event.listEvents`, but `event.list` is being registered with the client. * Update widget header to not overflow container (#1410) Also add a 10px margin below the header to maintain consistent spacing around the widget contents. * fix: case insensitive admonitions by default (#1409) * fix: closing bracket is missing (#1408) * Add optional priority attribute to PageCreatingContent (#1392) * Add optional priority attribute to PageCreatingContent * Minor simplification * Fix comments * Revert changes * Add pageEventHandlers * Use UTC year, month, and date for strings lacking time components (#1403) * feat: allow CONFIG.md in any directory (#1398) * fix: bundle external dependencies (#1379) * Deno bump * Copy-edit splash screen text (#1413) * Fixes #1401 by implementing Lua's select * Fixes offline capability of PWA (I hope). Now storing config in localStorage. * fix lint * Reduce blast radius of Lua errors * Fixes #1411: adds 'priority' setting for space style * Refactor: Merging common/ into web/ * Fixes #1400 * Improves #1312 by rendering Lua expressions (but not widgets) * Fix minor typos, add configuration to the docs --------- Co-authored-by: wbhouston <[email protected]> Co-authored-by: Lennart Ochel <[email protected]> Co-authored-by: Matthias Benaets <[email protected]> Co-authored-by: Zef Hemel <[email protected]> Co-authored-by: Marek S. Łukasiewicz <[email protected]> Co-authored-by: Ivan Alejandro <[email protected]> Co-authored-by: Albert-Jan de Vries <[email protected]> Co-authored-by: Cole Stowell <[email protected]> Co-authored-by: Jim Tittsler <[email protected]>
More general implementation of #1359
This also documents current workaround for #1343