Skip to content

Commit aff178b

Browse files
committed
Fix index.defineTag after refactor
1 parent de561cd commit aff178b

File tree

5 files changed

+49
-18
lines changed

5 files changed

+49
-18
lines changed

Library/Std/Config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ config.define("tagDefinitions", {
8282
type = "object",
8383
properties = {
8484
schema = { type = "object" },
85-
metatable = { type = "object" },
85+
metatable = { },
8686
},
8787
},
8888
})

web/syscalls/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function eventListenerSyscalls(
1515
_ctx,
1616
def: EventSubscription,
1717
) => {
18-
console.log("Registering Lua event listener: ", def.name);
18+
// console.log("Registering Lua event listener: ", def.name);
1919
const listeners = client.config.get<Function[]>([
2020
"eventListeners",
2121
def.name,

web/syscalls/index.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ import {
77
jsToLuaValue,
88
type LuaEnv,
99
type LuaStackFrame,
10+
type LuaTable,
1011
} from "../../lib/space_lua/runtime.ts";
1112

1213
import type { Client } from "../client.ts";
1314

14-
type TagDef = {
15-
name: string;
16-
schema?: any;
17-
metatable?: any;
18-
};
19-
2015
export function indexSyscalls(client: Client): SysCallMapping {
2116
return {
2217
"index.tag": (_ctx, tagName: string): LuaQueryCollection => {
@@ -33,26 +28,29 @@ export function indexSyscalls(client: Client): SysCallMapping {
3328
sf,
3429
(key, value: any) => {
3530
const tag = key[1];
36-
const tagDef = client.config.get<Record<string, TagDef>>(
37-
"tagDefinitions",
38-
{},
39-
)[tag];
40-
if (!tagDef) {
31+
const tagDef = client.config.get<LuaTable | undefined>(
32+
["tagDefinitions", tag],
33+
undefined,
34+
);
35+
if (!tagDef || !tagDef.has("metatable")) {
4136
// Return as is
4237
return value;
4338
}
44-
console.log("Found this tagDef", tagDef);
4539
// Convert to LuaTable
4640
value = jsToLuaValue(value);
47-
value.metatable = tagDef.metatable;
41+
value.metatable = tagDef.get("metatable");
4842
return value;
4943
},
5044
);
5145
},
5246
};
5347
},
54-
"index.defineTag": (_ctx, tagDef: TagDef) => {
55-
client.config.set(tagDef.name, tagDef);
48+
"lua:index.defineTag": (_ctx, tagDef: LuaTable) => {
49+
// Using 'lua:' prefix to _not_ convert tagDef to a JS version (but keep original LuaTable)
50+
if (!tagDef.has("name")) {
51+
throw new Error("A tag name is required");
52+
}
53+
client.config.set(["tagDefinitions", tagDef.get("name")], tagDef);
5654
},
5755
};
5856
}

website/API/index.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,24 @@ The `extractOptions` is an optional table that can contain the following keys (w
5959
- `removeFrontmatterSection`: A boolean to remove the frontmatter section from the document.
6060

6161
Example applied to this page:
62-
${(index.extractFrontmatter(editor.getText())).frontmatter}
62+
${(index.extractFrontmatter(editor.getText())).frontmatter}
63+
64+
## index.defineTag(def)
65+
Allows you to attach a custom Lua metatable to objects part of a particular tag.
66+
67+
### Example
68+
The following adds a custom attribute to all page objects that dynamically produces an ALL CAPS version of the page name:
69+
```space-lua
70+
index.defineTag {
71+
name = "page",
72+
metatable = {
73+
__index = function(self, attr)
74+
if attr == "loudName" then
75+
return string.upper(self.name)
76+
end
77+
end
78+
}
79+
}
80+
```
81+
In use:
82+
${query[[from index.tag "page" select {name=_.name, loudName=_.loudName} limit 3]]}

website/SilverBullet.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Introduction
2+
SilverBullet is a tool to **keep, organize, and structure your personal knowledge** and to make it **universally accessible** across all your devices.
3+
4+
It stores your content as a collection of [[Pages]] (called a [[Spaces|Space]]) as [[Markdown]] files on disk. It enables [[Links|Linking]], [[Tags|Tagging]] and **annotating** with [[Metadata]] at various levels. These annotations let you treat your space as a [[Objects|database]], enabling you to [[Space Lua/Lua Integrated Query|Query]] it in interesting ways.
5+
6+
SilverBullet is a deeply **programmable** and **personalizable** environment. Using [[Space Lua]] (its custom [[Lua]] implementation), you can dynamically generate part of your pages using [[Space Lua/Lua Integrated Query|Queries]] and other [[Space Lua|Expressions]], create custom [[Commands]] and [[Space Lua/Widgets]]. [[Space Style]] allows you to tweak your Space’s look and feel using CSS.
7+
8+
You [[Install|self host]] SilverBullet on a server under your control. It is deployable as a single [[Install/Binary]] or [[Install/Docker]] container. _You_ decide if you run it locally, in your VPN, or on the cloud.
9+
10+
The SilverBullet client is built as a [[Local First]], progressive web application, syncing all your content into your browser’s IndexedDB, enabling you **instant access** to your entire space no matter if you are **online or offline**.
11+
12+
---
13+
114
# Introduction
215
SilverBullet is an open source **personal productivity platform** built on [[Markdown]], turbo charged with the scripting power of [[Space Lua|Lua]]. You [[Install|self host]] it on your server, access it via any modern browser on any device (desktop, laptop, mobile). Since SilverBullet is built as a [[Local First]] [[PWA]], it is fully offline capable. Temporarily don’t have network access? No problem, SilverBullet will sync your content when you get back online.
316

0 commit comments

Comments
 (0)