diff options
| author | s-ol <s+removethis@s-ol.nu> | 2020-12-04 15:58:35 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2020-12-04 16:06:48 +0000 |
| commit | a3fe7576d677fe02f8f82244df19a1299ea4e15f (patch) | |
| tree | b88ba1d22c3bfd57997743e66727a6245a839c5f | |
| parent | add editorconfig (diff) | |
| download | mmm-a3fe7576d677fe02f8f82244df19a1299ea4e15f.tar.gz mmm-a3fe7576d677fe02f8f82244df19a1299ea4e15f.zip | |
move meta handling into mmm.mmmfs.meta
| -rw-r--r-- | mmm/mmmfs/conversion.moon | 22 | ||||
| -rw-r--r-- | mmm/mmmfs/fileder.moon | 13 | ||||
| -rw-r--r-- | mmm/mmmfs/layout.moon | 20 | ||||
| -rw-r--r-- | mmm/mmmfs/meta.moon | 48 |
4 files changed, 66 insertions, 37 deletions
diff --git a/mmm/mmmfs/conversion.moon b/mmm/mmmfs/conversion.moon index 2d25793..80a4537 100644 --- a/mmm/mmmfs/conversion.moon +++ b/mmm/mmmfs/conversion.moon @@ -1,6 +1,7 @@ require = relative ..., 1 refs = require 'mmm.refs' import Queue from require '.queue' +import get_plugins from require '.meta' count = (base, pattern='->') -> select 2, base\gsub pattern, '' escape_pattern = (inp) -> @@ -55,26 +56,11 @@ class MermaidDebugger get_converts = (fileder) -> assert PLUGINS - assert BROWSER.root converts = [c for c in *PLUGINS.converts] - -- search until closest non-meta ancestor - local guard_self - max_path = fileder.path - if closest = max_path\match('(.-)/$mmm') - max_path = closest - guard_self = true - - for ancestor in coroutine.wrap -> BROWSER.root\walk_co max_path - if guard_self and ancestor.path == max_path - break - - ancestor\load! if not ancestor.loaded - - if meta = ancestor.meta - for plugin in *meta\walk('plugins').children - for c in *(plugin\get('converts: table') or {}) - table.insert converts, c + for plugin in get_plugins fileder + for c in *(plugin\get('converts: table') or {}) + table.insert converts, c converts diff --git a/mmm/mmmfs/fileder.moon b/mmm/mmmfs/fileder.moon index 4dcc60b..27d5610 100644 --- a/mmm/mmmfs/fileder.moon +++ b/mmm/mmmfs/fileder.moon @@ -209,19 +209,6 @@ class Fileder if match = @meta and @meta\walk path return match - -- like :walk but yield all ancestors of path - -- * path - the path to walk to - walk_co: (path) => - path = "#{@path}/#{path}" if '/' != path\sub 1, 1 - - return unless @path == path\sub 1, #@path - return if #path == #@path - - coroutine.yield @ - - for child in *@children - child\walk_co path - -- recursively mount fileder and children at path -- * path - the path to mount at -- * mount_as - dont append own name to path diff --git a/mmm/mmmfs/layout.moon b/mmm/mmmfs/layout.moon index a1960f1..7c9df96 100644 --- a/mmm/mmmfs/layout.moon +++ b/mmm/mmmfs/layout.moon @@ -1,6 +1,6 @@ -require = relative ..., 1 import header, aside, footer, div, svg, script, g, circle, h1, span, b, a, img from require 'mmm.dom' import navigate_to from (require 'mmm.mmmfs.util') require 'mmm.dom' +import get_plugins from require 'mmm.mmmfs.meta' pick = (...) -> num = select '#', ... @@ -83,7 +83,7 @@ footer = footer { } } -get_meta = => +get_header_tags = => title = (@get 'title: text/plain') or @gett 'name: alpha' l = (str) -> @@ -113,9 +113,17 @@ get_meta = => meta +get_scripts = => + scripts = '' + for plugin in get_plugins @ + if snippet = plugin\get 'scripts: text/html+frag' + scripts ..= snippet + + scripts + render = (content, fileder, opts={}) -> - opts.meta or= get_meta fileder - opts.scripts or= PLUGINS.scripts + opts.meta or= get_header_tags fileder + opts.scripts or= get_scripts fileder unless opts.noview content = [[ @@ -133,7 +141,7 @@ render = (content, fileder, opts={}) -> buf ..= if STATIC then STATIC.style else [[<link rel="stylesheet" type="text/css" href="/static/style/:text/css" />]] buf ..= [[<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600" />]] buf ..= " - #{get_meta fileder} + #{opts.meta} </head> <body> #{gen_header!} @@ -146,7 +154,7 @@ render = (content, fileder, opts={}) -> <script type="text/javascript">hljs.initHighlighting()</script>]] buf ..= opts.scripts - buf ..= if STATIC then STATIC.scripts else '' + buf ..= STATIC.scripts if STATIC buf ..= " </body> </html>" diff --git a/mmm/mmmfs/meta.moon b/mmm/mmmfs/meta.moon new file mode 100644 index 0000000..35a2254 --- /dev/null +++ b/mmm/mmmfs/meta.moon @@ -0,0 +1,48 @@ +-- like Fileder:walk but yield all ancestors of path +-- * path - the path to walk to +yield_ancestors = do + step = (path) => + path = "#{@path}/#{path}" if '/' != path\sub 1, 1 + + return unless @path == path\sub 1, #@path + return if #path == #@path + + coroutine.yield @ + + for child in *@children + step child, path + + (path) => coroutine.wrap -> step @, path + +get_meta = (fileder, path) -> + assert BROWSER.root + + if path + path = "$mmm/#{path}" + else + path = '$mmm' + + local guard_self + max_path = fileder.path + if closest = max_path\match('(.-)/$mmm') + max_path = closest + guard_self = true + + coroutine.wrap -> + -- search until closest non-meta ancestor + for ancestor in yield_ancestors BROWSER.root, max_path + break if guard_self and ancestor.path == max_path + + if result = ancestor\walk path + coroutine.yield result + +get_plugins = (fileder) -> + coroutine.wrap -> + for plugins in get_meta fileder, 'plugins' + for plugin in *plugins.children + coroutine.yield plugin + +{ + :get_meta + :get_plugins +} |
