diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-03-03 16:22:01 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-03-05 10:36:33 +0000 |
| commit | ec683e448958fbd2e8e0b2f5c9e90d5ce9e0b200 (patch) | |
| tree | cb8016679fe6018879ba98756e78cd5cbc39330d /extra | |
| parent | add doc generator (diff) | |
| download | alive-ec683e448958fbd2e8e0b2f5c9e90d5ce9e0b200.tar.gz alive-ec683e448958fbd2e8e0b2f5c9e90d5ce9e0b200.zip | |
add index and guide pages
Diffstat (limited to 'extra')
| -rw-r--r-- | extra/docs.moon | 75 | ||||
| -rw-r--r-- | extra/dom.moon | 2 | ||||
| -rw-r--r-- | extra/layout.moon | 24 |
3 files changed, 60 insertions, 41 deletions
diff --git a/extra/docs.moon b/extra/docs.moon index a8438cf..9e478e9 100644 --- a/extra/docs.moon +++ b/extra/docs.moon @@ -1,45 +1,66 @@ import Value, Scope from require 'core' -import render, write from require 'extra.layout' +import render, layout from require 'extra.layout' import section, h2, p, ul, li, a, code, r from require 'extra.dom' export OUT { OUT, command } = arg -write switch command +slurp = (file) -> + file = io.open file, 'r' + with file\read '*all' + file\close! + +spit = (file, str) -> + file = io.open file, 'w' + file\write str + file\close! + +spit OUT, switch command when 'module' { _, _, module, name } = arg name or= module module = Scope.from_table require module - title: "#{name} module reference" - body: section { - h2 (code name), ' reference' - ul for key, res in pairs module.values - li render key, res.value - } + layout + title: "#{name} module reference" + body: section { + h2 (code name), ' reference' + ul for key, res in opairs module.values + li render key, res.value + } when 'reference' - title: 'reference index' - body: { - section { - id: 'modules' - h2 a "module index", href: '#modules' - p "These modules can be imported using #{r 'require'}, #{r 'import'} and " .. - "#{r 'import*'}." - ul for file in *arg[3,] - module = file\match '^lib/(.*)%.moon$' - li a (code module), href: "#{module}.html" - } - section { - id: 'builtins' - h2 a "builtins", href: '#builtins' - p "These definitions are automatically loaded into the global Scope of - every alive session." - ul for key, val in pairs require 'core.builtin' - li render key, Value.wrap val + layout + title: 'reference' + body: { + section { + id: 'modules' + h2 a "module index", href: '#modules' + p "These modules can be imported using #{r 'require'}, #{r 'import'} and " .. + "#{r 'import*'}." + ul for file in *arg[3,] + module = file\match '^lib/(.*)%.moon$' + li a (code module), href: "#{module}.html" + } + section { + id: 'builtins' + h2 a "builtins", href: '#builtins' + p "These definitions are automatically loaded into the global Scope of + every alive session." + ul for key, val in opairs require 'core.builtin' + li render key, Value.wrap val + } } - } + + when 'markdown' + import compile from require 'discount' + + { _, _, file } = arg + contents = slurp file + require 'discount' + + layout compile contents, 'githubtags', 'fencedcode' else error "unknown command '#{command}'" diff --git a/extra/dom.moon b/extra/dom.moon index 73dc743..7541fbd 100644 --- a/extra/dom.moon +++ b/extra/dom.moon @@ -1,6 +1,8 @@ -- mmm.dom -- see https://mmm.s-ol.nu/meta/mmm.dom/ +export opairs + -- ordered table iterator, for stable(r) renderers sort = (t, order_fn, only_strings) -> with index = [k for k,v in pairs t when (not only_strings) or 'string' == type k] diff --git a/extra/layout.moon b/extra/layout.moon index 1a4ee7b..71bbfb2 100644 --- a/extra/layout.moon +++ b/extra/layout.moon @@ -7,7 +7,7 @@ render = (name, value, prefix=nil) -> content = switch value.type when 'scope' - ul for k, result in pairs value!.values + ul for k, result in opairs value!.values li render k, result.value, id when 'opdef', 'builtin' p value!.doc @@ -33,16 +33,11 @@ r = (name, page='') -> import a, code from require 'extra.dom' a (code name), href: "#{page}##{name}" -spit = (file, str) -> - file = io.open file, 'w' - file\write str - file\close! - -- layout and write a doc page -- opts: -- - title -- - body -write = (opts) -> +layout = (opts) -> import nav, div, span, b, code, i, a, article from require 'extra.dom' navigation = nav div { @@ -53,16 +48,17 @@ write = (opts) -> a 'reference', href: abs 'reference/index.html' } body = article opts.body + title = if opts.title + "#{opts.title} - alive" + else + "alive documentation" - assert OUT, "OUT needs to be set" - spit OUT, "<!DOCTYPE html> + "<!DOCTYPE html> <html> <head> - <title>#{opts.title} - alive docs</title> + <title>#{title}</title> <link rel=\"stylesheet\" href=\"#{abs 'style.css'}\"> - <style> - - </style> + #{opts.css or ''} </head> <body> #{navigation} @@ -74,5 +70,5 @@ write = (opts) -> { :r :render - :write + :layout } |
