Slight reorganization of std library
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#meta
|
||||
|
||||
Implements useful embeds
|
||||
|
||||
# Youtube
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#meta
|
||||
|
||||
Editor support for Lua, implemented in Lua. Of course.
|
||||
Basic editor support for Space Lua, implemented in Space Lua.
|
||||
|
||||
Features:
|
||||
|
||||
* Basic code completion for globals, e.g. `string.gm` will be completed
|
||||
* Navigation to global symbols implemented in Lua by Cmd-clicking (Mac) or Ctrl-clicking (other OSes)
|
||||
|
||||
# Code complete support
|
||||
```space-lua
|
||||
|
||||
+8
-1
@@ -1,11 +1,18 @@
|
||||
#meta
|
||||
|
||||
This page compiles some useful stats about your space and may also be useful for debugging.
|
||||
This page compiles some useful stats about your space. You may also like the [[^Library/Std/Pages/Maintenance]] page.
|
||||
|
||||
# Stats
|
||||
**Total pages:** ${#query[[from index.tag "page" select name]]}
|
||||
**Total documents:** ${#query[[from index.tag "document" select name]]}
|
||||
|
||||
# Active Plugs
|
||||
These are all the plugs currently active in your space:
|
||||
${query[[
|
||||
from space.listPlugs()
|
||||
select {name=string.gsub(_.name, "_plug/([^.]+).plug.js", "%1")}
|
||||
]]}
|
||||
|
||||
# Active Space Lua
|
||||
These are all Space Lua scripts and the order in which they are loaded:
|
||||
${template.each(query[[
|
||||
@@ -34,7 +34,6 @@ templates.tagItem = template.new([==[
|
||||
]==])
|
||||
```
|
||||
|
||||
|
||||
# Examples
|
||||
`template.pageItem`:
|
||||
${template.each(query[[from index.tag "page" limit 3]], templates.pageItem)}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#meta
|
||||
|
||||
Implements utilities for working with Markdown tables
|
||||
|
||||
# Table
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#meta
|
||||
|
||||
Implements a tag page, that renders when navigating to a hashtag: #meta based on the `tag:` prefix, by piggy backing on the `editor:pageCreating` event that triggers for non-existing pages.
|
||||
|
||||
```space-lua
|
||||
-- priority: 10
|
||||
pageEventHandlers = pageEventHandlers or {}
|
||||
|
||||
pageEventHandlers.tagPage = function(e)
|
||||
if not e.data.name:startsWith("tag:") then
|
||||
return
|
||||
end
|
||||
-- Extract the tag name from the page name
|
||||
local tagName = e.data.name:sub(#"tag:" + 1)
|
||||
local text = "# Objects tagged with " .. tagName .. "\n"
|
||||
local taggedPages = query[[
|
||||
from index.tag "page"
|
||||
order by ref
|
||||
where table.includes(_.tags, tagName)
|
||||
]]
|
||||
if #taggedPages > 0 then
|
||||
text = text .. "## Pages\n"
|
||||
.. template.each(taggedPages, templates.pageItem)
|
||||
end
|
||||
local taggedTasks = query[[
|
||||
from index.tag "task"
|
||||
order by ref
|
||||
where table.includes(_.tags, tagName)
|
||||
]]
|
||||
if #taggedTasks > 0 then
|
||||
text = text .. "## Tasks\n"
|
||||
.. template.each(taggedTasks, templates.taskItem)
|
||||
end
|
||||
local taggedItems = query[[
|
||||
from index.tag "item"
|
||||
order by ref
|
||||
where table.includes(_.tags, tagName)
|
||||
]]
|
||||
if #taggedItems > 0 then
|
||||
text = text .. "## Items\n"
|
||||
.. template.each(taggedItems, templates.itemItem)
|
||||
end
|
||||
local taggedParagraphs = query[[
|
||||
from index.tag "paragraph"
|
||||
order by ref
|
||||
where table.includes(_.tags, tagName)
|
||||
]]
|
||||
if #taggedParagraphs > 0 then
|
||||
text = text .. "## Paragraphs\n"
|
||||
.. template.each(taggedParagraphs, templates.paragraphItem)
|
||||
end
|
||||
return {
|
||||
text = text,
|
||||
-- Read only page
|
||||
perm = "ro"
|
||||
}
|
||||
end
|
||||
|
||||
event.listen {
|
||||
name = "editor:pageCreating",
|
||||
run = function(e) return pageEventHandlers.tagPage(e) end,
|
||||
}
|
||||
```
|
||||
@@ -1,62 +1,21 @@
|
||||
#meta
|
||||
|
||||
Implements a tag page, that renders when navigating to a hashtag: #meta based on the `tag:` prefix, by piggy backing on the `editor:pageCreating` event that triggers for non-existing pages.
|
||||
Implements convenience functions for accessing tag objects.
|
||||
|
||||
Currently:
|
||||
|
||||
* `tags.someTag` is an alias for `index.tag "someTag`
|
||||
|
||||
Example:
|
||||
|
||||
${#query[[from tags.page]]}
|
||||
|
||||
# Implementation
|
||||
|
||||
```space-lua
|
||||
-- priority: 10
|
||||
pageEventHandlers = pageEventHandlers or {}
|
||||
pageEventHandlers.tagPage = function(e)
|
||||
if not e.data.name:startsWith("tag:") then
|
||||
return
|
||||
end
|
||||
-- Extract the tag name from the page name
|
||||
local tagName = e.data.name:sub(#"tag:" + 1)
|
||||
local text = "# Objects tagged with " .. tagName .. "\n"
|
||||
local taggedPages = query[[
|
||||
from index.tag "page"
|
||||
order by ref
|
||||
where table.includes(_.tags, tagName)
|
||||
]]
|
||||
if #taggedPages > 0 then
|
||||
text = text .. "## Pages\n"
|
||||
.. template.each(taggedPages, templates.pageItem)
|
||||
end
|
||||
local taggedTasks = query[[
|
||||
from index.tag "task"
|
||||
order by ref
|
||||
where table.includes(_.tags, tagName)
|
||||
]]
|
||||
if #taggedTasks > 0 then
|
||||
text = text .. "## Tasks\n"
|
||||
.. template.each(taggedTasks, templates.taskItem)
|
||||
end
|
||||
local taggedItems = query[[
|
||||
from index.tag "item"
|
||||
order by ref
|
||||
where table.includes(_.tags, tagName)
|
||||
]]
|
||||
if #taggedItems > 0 then
|
||||
text = text .. "## Items\n"
|
||||
.. template.each(taggedItems, templates.itemItem)
|
||||
end
|
||||
local taggedParagraphs = query[[
|
||||
from index.tag "paragraph"
|
||||
order by ref
|
||||
where table.includes(_.tags, tagName)
|
||||
]]
|
||||
if #taggedParagraphs > 0 then
|
||||
text = text .. "## Paragraphs\n"
|
||||
.. template.each(taggedParagraphs, templates.paragraphItem)
|
||||
end
|
||||
return {
|
||||
text = text,
|
||||
-- Read only page
|
||||
perm = "ro"
|
||||
}
|
||||
tags = setmetatable({}, {
|
||||
__index = function(self, tag)
|
||||
return index.tag(tag)
|
||||
end
|
||||
|
||||
event.listen {
|
||||
name = "editor:pageCreating",
|
||||
run = function(e) return pageEventHandlers.tagPage(e) end,
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
@@ -12,7 +12,7 @@ These are changes live on the edge builds:
|
||||
* Fixed docker user and group creation issues
|
||||
* Removed `file:deleted` triggering when checking for `getFileMeta` (causing an infinite indexing loop in SilverSearch)
|
||||
* Server: HTTP Gzip compression is now enabled for sensible content types
|
||||
|
||||
* Nicer syntax to query tag objects from the index: `tags.page` becomes an alias for `index.tag "page"` (implemented here: [[^Library/Std/Tag]])
|
||||
|
||||
## 2.1.2
|
||||
This is a major architectural overhaul compared to 2.0. Please — as always — make sure you regularly backup your space files to avoid any data loss. Nothing should happen, but better be safe than sorry!
|
||||
|
||||
+6
-11
@@ -34,7 +34,7 @@ It is possible to control load order of space lua scripts using the special `--
|
||||
|
||||
Scripts are loaded in _reverse priority_ order. When you set no priority (the default) your scripts will be run last.
|
||||
|
||||
The order used is determined by this [[Space Lua/Lua Integrated Query|query]] (also part of your [[^Library/Std/Space Overview]]) page:
|
||||
The order used is determined by this [[Space Lua/Lua Integrated Query|query]] (also part of your [[^Library/Std/Pages/Space Overview]]) page:
|
||||
|
||||
query[[
|
||||
from index.tag "space-lua"
|
||||
@@ -53,11 +53,9 @@ Here are the conventions used by the [[Library/Std]] library:
|
||||
> All your space-lua scripts are loaded on boot, to reload them without reloading the page, simply run the ${widgets.commandButton("System: Reload")} (Ctrl-Alt-r) command.
|
||||
|
||||
# Expressions
|
||||
A new syntax introduced with Space Lua is the `${lua expression}` syntax that you can use in your pages. This syntax will [[Live Preview]] to the evaluation of that expression.
|
||||
A SilveBullet specific [[Markdown]] [[Markdown/Extensions]] is the `${lua expression}` syntax that you can use in your pages. This syntax will [[Live Preview]] to the evaluation of that Lua expression.
|
||||
|
||||
For example: 10 + 2 = ${adder(10, 2)} (Alt-click, or select to see the expression) is using the just defined `adder` function to this rather impressive calculation.
|
||||
|
||||
Note that you can have the text {lua expression} in your page and it won't be evaluated. So writing `${"$"}{lua expression}` can be used to “delay” evaluation by one pass, for example to escape expressions in templated content.
|
||||
For example: 10 + 2 = ${adder(10, 2)} (Alt-click, or select to see the expression) is using the just defined `adder` function.
|
||||
|
||||
## Queries
|
||||
Space Lua has a feature called [[Space Lua/Lua Integrated Query]], which integrate SQL-like queries into Lua. Here’s a small example querying the last 3 modifies pages:
|
||||
@@ -69,11 +67,11 @@ ${query[[
|
||||
limit 3
|
||||
]]}
|
||||
|
||||
[[Space Lua/Widgets]]
|
||||
## Widgets
|
||||
See [[Space Lua/Widgets]]
|
||||
|
||||
## Commands
|
||||
|
||||
Custom commands can be defined using [[API/command#command.define(commandDef)]]:
|
||||
Custom commands can be defined using [[API/command#command.define(commandDef)]]:
|
||||
|
||||
```space-lua
|
||||
command.define {
|
||||
@@ -88,7 +86,6 @@ command.define {
|
||||
Try it: ${widgets.commandButton("Hello World")}
|
||||
|
||||
## Slash commands
|
||||
|
||||
Custom slash commands can be defined using [[API/slashCommand#slashCommand.define(spec)]]:
|
||||
|
||||
```space-lua
|
||||
@@ -101,7 +98,6 @@ slashCommand.define {
|
||||
```
|
||||
|
||||
## Event listeners
|
||||
|
||||
You can listen to events using [[API/event#event.listen(listenerDef)]]:
|
||||
|
||||
```space-lua
|
||||
@@ -115,7 +111,6 @@ event.listen {
|
||||
```
|
||||
|
||||
# Space Lua Extensions
|
||||
|
||||
Space Lua introduces a few new features on top core Lua:
|
||||
|
||||
1. [[Space Lua/Lua Integrated Query]], embedding a query language into Lua itself
|
||||
|
||||
Reference in New Issue
Block a user