Template sets
This commit is contained in:
parent
b26b7f4f0a
commit
663a15fe33
@ -1,9 +1,10 @@
|
||||
import { WidgetContent } from "$sb/app_event.ts";
|
||||
import { handlebars, markdown, space, system, YAML } from "$sb/syscalls.ts";
|
||||
import { markdown, space, system, YAML } from "$sb/syscalls.ts";
|
||||
import { rewritePageRefs } from "$sb/lib/resolve.ts";
|
||||
import { loadPageObject, replaceTemplateVars } from "../template/template.ts";
|
||||
import { renderToText } from "$sb/lib/tree.ts";
|
||||
import { PageMeta } from "$sb/types.ts";
|
||||
import { renderTemplate } from "../template/plug_api.ts";
|
||||
|
||||
type TemplateConfig = {
|
||||
// Pull the template from a page
|
||||
@ -39,13 +40,15 @@ export async function widget(
|
||||
)
|
||||
: undefined;
|
||||
|
||||
let rendered = config.raw ? templateText : await handlebars.renderTemplate(
|
||||
templateText,
|
||||
value,
|
||||
{
|
||||
page: pageMeta,
|
||||
},
|
||||
);
|
||||
console.log("Value", value);
|
||||
|
||||
let { text: rendered } = config.raw
|
||||
? { text: templateText }
|
||||
: await renderTemplate(
|
||||
templateText,
|
||||
pageMeta,
|
||||
value,
|
||||
);
|
||||
|
||||
if (templatePage) {
|
||||
const parsedMarkdown = await markdown.parseMarkdown(rendered);
|
||||
|
@ -57,7 +57,7 @@ export function PageNavigator({
|
||||
darkMode={darkMode}
|
||||
completer={completer}
|
||||
allowNew={true}
|
||||
helpText="Press <code>Enter</code> to open the selected page, or <code>Shift-Enter</code> to create a new page."
|
||||
helpText="Press <code>Enter</code> to open the selected page, or <code>Shift-Enter</code> to create a new page with this exact name."
|
||||
newHint="Create page"
|
||||
completePrefix={completePrefix}
|
||||
onSelect={(opt) => {
|
||||
|
@ -4,6 +4,7 @@ release.
|
||||
---
|
||||
## Next
|
||||
* The `Alt-q` command is now bound to the new {[Live Queries and Templates: Refresh All]} command refreshing all [[Live Queries]] and [[Live Templates]] on the page. This is to get y’all prepared to move away from directives.
|
||||
* It’s time to get ready for the removal of directives, and convert your entire space over using (one time operation). Please backup your space before you do: {[Directive: Convert Entire Space to Live/Templates]}
|
||||
|
||||
|
||||
---
|
||||
@ -505,8 +506,8 @@ Besides these architectural changes, a few other breaking changes were made to s
|
||||
## 0.0.31
|
||||
|
||||
* Update to the query language: the `render` clause now uses page reference
|
||||
syntax `[[page]]`. For example `render [[template/task]]` rather than
|
||||
`render "template/task"`. The old syntax still works, but is deprecated,
|
||||
syntax `[[page]]`. For example `render [[template/tasks/task]]` rather than
|
||||
`render "template/tasks/task"`. The old syntax still works, but is deprecated,
|
||||
completion for the old syntax has been removed.
|
||||
* Updates to templates:
|
||||
* For the `Template: Instantiate Page` command, the page meta value `$name` is
|
||||
|
@ -48,10 +48,10 @@ The following query shows all attributes available for tasks:
|
||||
```query
|
||||
upnext
|
||||
```
|
||||
Although you may want to render it using a template such as [[template/task]] instead:
|
||||
Although you may want to render it using a template such as [[template/tasks/task] instead:
|
||||
|
||||
```query
|
||||
upnext render [[template/task]]
|
||||
upnext render [[template/tasks/task]]
|
||||
```
|
||||
|
||||
## taskstate
|
||||
|
43
website/Template Sets.md
Normal file
43
website/Template Sets.md
Normal file
@ -0,0 +1,43 @@
|
||||
This is an attempt at collecting useful, reusable templates so you don’t have to reinvent the wheel.
|
||||
|
||||
The most convenient ways to use them is using [[Federation]]. This will synchronize these templates into your space and make them available for use instantly.
|
||||
|
||||
To set this up, add this to your [[SETTINGS]]:
|
||||
|
||||
```yaml
|
||||
federate:
|
||||
- uri: silverbullet.md/template
|
||||
```
|
||||
|
||||
If you don’t want to sync _all_ these templates, you can use more specific URIs, e.g.
|
||||
```yaml
|
||||
federate:
|
||||
- uri: silverbullet.md/template/tasks
|
||||
```
|
||||
to just get the `tasks` stuff.
|
||||
|
||||
To reference a template, use the federation syntax, e.g. `[[!silverbullet.md/template/tasks/task]]`.
|
||||
|
||||
## Maintenance
|
||||
```query
|
||||
template where name =~ /^template\/maintenance/
|
||||
order by order
|
||||
render [[template/documented-template]]
|
||||
```
|
||||
## Pages
|
||||
```query
|
||||
template
|
||||
where name =~ /^template\/pages/
|
||||
order by order
|
||||
render [[template/documented-template]]
|
||||
```
|
||||
## Tasks
|
||||
```query
|
||||
template where name =~ /^template\/tasks/
|
||||
order by order
|
||||
render [[template/documented-template]]
|
||||
```
|
||||
## Debugging
|
||||
```query
|
||||
template where name =~ /^template\/debug/ render [[template/documented-template]]
|
||||
```
|
12
website/template/debug/debug.md
Normal file
12
website/template/debug/debug.md
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
tags: template
|
||||
description: |
|
||||
Renders its object value in a `key: value` format
|
||||
usage: |
|
||||
Can be used by passing in a YAML object in a template via `value` or in a `render` clause of a query
|
||||
---
|
||||
{{#each .}}
|
||||
{{@key}}: {{.}}
|
||||
{{/each}}
|
||||
|
||||
---
|
4
website/template/documented-template.md
Normal file
4
website/template/documented-template.md
Normal file
@ -0,0 +1,4 @@
|
||||
* [[{{ref}}|{{ref}}]] {{description}}
|
||||
{{#if usage}}
|
||||
* **Usage:** {{usage}}
|
||||
{{/if}}
|
9
website/template/maintenance/conflicts.md
Normal file
9
website/template/maintenance/conflicts.md
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
tags: template
|
||||
description: Lists all pages with ".conflicted" in the name, created as a result of a synchronization conflict.
|
||||
---
|
||||
|
||||
### Conflicting pages
|
||||
```query
|
||||
page where name =~ /\.conflicted/ render [[template/pages/page]]
|
||||
```
|
6
website/template/pages/page.md
Normal file
6
website/template/pages/page.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
tags: template
|
||||
description: A page reference link as a list item
|
||||
---
|
||||
|
||||
* [[{{name}}]]
|
@ -1,4 +1,4 @@
|
||||
#template
|
||||
```query
|
||||
task where tags = "{{.}}" and done = false render [[template/task]]
|
||||
task where tags = "{{.}}" and done = false render [[template/tasks/task]]
|
||||
```
|
10
website/template/tasks/incoming.md
Normal file
10
website/template/tasks/incoming.md
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
tags: template
|
||||
description: |
|
||||
Shows all tasks that reference (tag) the current page. For instance a task that references `[[John]]` in its name, would appear on the `John` page if it would use this [[sets/tasks/incoming]] template.
|
||||
order: 2
|
||||
---
|
||||
|
||||
```query
|
||||
task where name =~ /\[\[{{escapeRegexp @page.name}}\]\]/ where done = false render [[template/tasks/task]]
|
||||
```
|
10
website/template/tasks/tagged.md
Normal file
10
website/template/tasks/tagged.md
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
tags: template
|
||||
description: Queries all tasks tagged with a specific tag.
|
||||
usage: Pass in the tag to filter on as the `value` of this template
|
||||
order: 2
|
||||
---
|
||||
|
||||
```query
|
||||
task where tags = "{{.}}" and done = false render [[template/tasks/task]]
|
||||
```
|
7
website/template/tasks/task.md
Normal file
7
website/template/tasks/task.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
tags: template
|
||||
description: generic task template that supports updating the status back in the origin page
|
||||
order: 1
|
||||
---
|
||||
|
||||
* [{{state}}] [[{{ref}}]] {{name}}
|
@ -42,12 +42,12 @@ task where page = "{{@page.name}}"
|
||||
```
|
||||
|
||||
## Rendering
|
||||
There is a [[!silverbullet.md/template/task]] template you can use to render tasks nicely rather than using the default table (as demonstrated above). When you use this template, you can even cycle through the states of the task by click on its state _inside_ the rendered query, and it will update the state of the _original_ task automatically (although not yet in reverse) — this works across pages.
|
||||
There is a [[!silverbullet.md/template/tasks/task]] template you can use to render tasks nicely rather than using the default table (as demonstrated above). When you use this template, you can even cycle through the states of the task by click on its state _inside_ the rendered query, and it will update the state of the _original_ task automatically (although not yet in reverse) — this works across pages.
|
||||
|
||||
Try it (by clicking on the checkbox inside of the directive):
|
||||
|
||||
```query
|
||||
task where page = "{{@page.name}}" and name = "Remote toggle me" render [[template/task]]
|
||||
task where page = "{{@page.name}}" and name = "Remote toggle me" render [[template/tasks/task]]
|
||||
```
|
||||
|
||||
* [ ] Remote toggle me
|
||||
|
Loading…
Reference in New Issue
Block a user