aboutsummaryrefslogtreecommitdiffstats
path: root/extra
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-05 19:00:30 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-05 20:29:57 +0000
commit2c4531c671b5d6cd4bfa93c808f19c38a0d9ebf0 (patch)
tree8fd744424377c7387d136abdc8421667cf751d25 /extra
parentdocs/guide (diff)
downloadalive-2c4531c671b5d6cd4bfa93c808f19c38a0d9ebf0.tar.gz
alive-2c4531c671b5d6cd4bfa93c808f19c38a0d9ebf0.zip
autoref, styling
Diffstat (limited to 'extra')
-rw-r--r--extra/docs.moon17
-rw-r--r--extra/layout.moon24
2 files changed, 30 insertions, 11 deletions
diff --git a/extra/docs.moon b/extra/docs.moon
index b9fe88b..3afa340 100644
--- a/extra/docs.moon
+++ b/extra/docs.moon
@@ -1,5 +1,5 @@
import Value, Scope from require 'core'
-import render, layout from require 'extra.layout'
+import render, layout, autoref from require 'extra.layout'
import section, h2, p, ul, li, a, code, r from require 'extra.dom'
export OUT, require
@@ -30,9 +30,9 @@ spit OUT, switch command
module = Scope.from_table require module
layout
- title: "#{name} module reference"
+ title: "#{name} reference"
body: section {
- h2 (code name), ' reference'
+ h2 (code name), ' module reference'
ul for key, res in opairs module.values
li render key, res.value
}
@@ -44,11 +44,12 @@ spit OUT, switch command
section {
id: 'modules'
h2 a "module index", href: '#modules'
- p "These modules can be imported using #{r 'require'}, #{r 'import'} and " ..
- "#{r 'import*'}."
+ p autoref "These modules can be imported using [require][], " ..
+ "[import][] and [import*][]."
ul for file in *arg[3,]
- module = file\match '^lib/(.*)%.moon$'
- li a (code module), href: "#{module}.html"
+ path = file\match '^lib/(.*)%.moon$'
+ name = path\gsub '/', '.'
+ li a (code name), href: "#{path}.html"
}
section {
id: 'builtins'
@@ -67,7 +68,7 @@ spit OUT, switch command
contents = slurp file
require 'discount'
- layout compile contents, 'githubtags', 'fencedcode'
+ layout compile autoref contents, 'githubtags', 'fencedcode'
else
error "unknown command '#{command}'"
diff --git a/extra/layout.moon b/extra/layout.moon
index e60fd25..3f2024a 100644
--- a/extra/layout.moon
+++ b/extra/layout.moon
@@ -30,10 +30,28 @@ abs = (page) ->
up = string.rep '../', depth
"#{up}#{page}"
+-- generate a link to a reference entry
+-- entry is one of
+-- builtin-name; mod.name/name; mod.name
+link = (ref) ->
+ mod, sym = ref\match '^(.+)/(.*)$'
+ abs "reference/#{mod or 'index'}.html##{sym or ref}"
+
-- link to a reference
-r = (name, page='') ->
+r = (text, ref) ->
import a, code from require 'extra.dom'
- a (code name), href: "#{page}##{name}"
+ href = link ref or text
+ if ref
+ a text, :href
+ else
+ text = text\gsub '/$', ''
+ a (code text), :href
+
+-- substitute markdown-style reference links
+autoref = (str) ->
+ str = str\gsub '%[([^%]]-)%]%[%]', r
+ str = str\gsub '%[([^%]]-)%]%[:(.-):%]', r
+ str
-- layout and write a doc page
-- opts:
@@ -85,7 +103,7 @@ layout = (opts) ->
{
- :r
+ :autoref
:render
:layout
}