aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-11-24 07:28:05 +0000
committers-ol <s-ol@users.noreply.github.com>2018-11-24 07:28:05 +0000
commit977c1cc840f9d88283a7c5faa7b5fe77409a0871 (patch)
tree934e0afac2693a411894234f7bbd04f376d211ee
parentfix hyphens in fileder names (diff)
downloadmmm-977c1cc840f9d88283a7c5faa7b5fe77409a0871.tar.gz
mmm-977c1cc840f9d88283a7c5faa7b5fe77409a0871.zip
relative Fileder\walk
-rw-r--r--mmm/mmmfs/conversion.moon4
-rw-r--r--mmm/mmmfs/fileder.moon46
-rw-r--r--mmm/mmmfs/util.moon2
-rw-r--r--root/text$moonscript -> fn -> mmm$dom.moon4
4 files changed, 34 insertions, 22 deletions
diff --git a/mmm/mmmfs/conversion.moon b/mmm/mmmfs/conversion.moon
index 4df3497..8edccbb 100644
--- a/mmm/mmmfs/conversion.moon
+++ b/mmm/mmmfs/conversion.moon
@@ -68,8 +68,8 @@ converts = {
path, facet = expr\match '^([%w%-_%./]*)%+(.*)'
assert path, "couldn't match TPL expression '#{expr}'"
- target = fileder\walk "#{fileder.path}/#{path}"
- assert target, "couldn't resolve rpath '#{path}' relative to #{fileder}"
+ target = fileder\walk path
+ assert target, "couldn't resolve path '#{path}' relative to #{fileder}"
target\gett facet
},
diff --git a/mmm/mmmfs/fileder.moon b/mmm/mmmfs/fileder.moon
index 019a814..c07fe7a 100644
--- a/mmm/mmmfs/fileder.moon
+++ b/mmm/mmmfs/fileder.moon
@@ -48,12 +48,19 @@ class Fileder
child
-- automatically mount children on insert
- @children = setmetatable {}, __newindex: (t, k, child) ->
- rawset t, k, child
- if @path == '/'
- child\mount '/'
- elseif @path
- child\mount @path .. '/'
+ @children = setmetatable {}, {
+ __index: (t, k) ->
+ return rawget t, k unless 'string' == type k
+
+ @walk "#{@path}/#{k}"
+
+ __newindex: (t, k, child) ->
+ rawset t, k, child
+ if @path == '/'
+ child\mount '/'
+ elseif @path
+ child\mount @path .. '/'
+ }
-- copy children
for i, child in ipairs children
@@ -71,6 +78,10 @@ class Fileder
-- recursively walk to and return the fileder with @path == path
-- * path - the path to walk to
walk: (path) =>
+ -- fix relative paths
+ if path != '' and '/' != path\sub 1, 1
+ path = "#{@path}/#{path}"
+
-- early-out if we are outside of the path already
return unless @path == path\sub 1, #@path
@@ -78,26 +89,21 @@ class Fileder
return @ if #path == #@path
for child in *@children
- result = child\walk path
- return result if result
+ if match = child\walk path
+ return match
-- recursively mount fileder and children at path
- -- * path - the path to mount at (default: '/')
+ -- * path - the path to mount at
-- * mount_as - dont append own name to path
- mount: (path='/', mount_as=false) =>
+ mount: (path, mount_as) =>
assert not @path, "mounted twice: #{@path} and now #{path}"
- if mount_as
- @path = path
- else
- @path = path .. @gett 'name: alpha'
+ @path = path
+ if not mount_as
+ @path ..= @gett 'name: alpha'
- if @path == '/'
- for child in *@children
- child\mount '/'
- else
- for child in *@children
- child\mount @path .. '/'
+ for child in *@children
+ child\mount @path .. '/'
-- recursively iterate all children (coroutine)
-- * depth - depth to stop after; 1 = yield only self (default: infinite)
diff --git a/mmm/mmmfs/util.moon b/mmm/mmmfs/util.moon
index 1737d89..80d1dd2 100644
--- a/mmm/mmmfs/util.moon
+++ b/mmm/mmmfs/util.moon
@@ -2,6 +2,8 @@
import a from elements
link_to = (fileder, name) ->
+ assert fileder, "no fileder passed"
+
name or= fileder\get 'title: mmm/dom'
name or= fileder\gett 'name: alpha'
diff --git a/root/text$moonscript -> fn -> mmm$dom.moon b/root/text$moonscript -> fn -> mmm$dom.moon
index 7841095..c036c80 100644
--- a/root/text$moonscript -> fn -> mmm$dom.moon
+++ b/root/text$moonscript -> fn -> mmm$dom.moon
@@ -1,4 +1,5 @@
import article, h1, h3, div, b, p, a, br, ul, tt, li, img from require 'mmm.dom'
+import link_to from (require 'mmm.mmmfs.util') require 'mmm.dom'
=>
append, finish = do
@@ -18,6 +19,9 @@ import article, h1, h3, div, b, p, a, br, ul, tt, li, img from require 'mmm.dom'
'You can find the source code of everything '
a { 'here', href: 'https://github.com/s-ol/mmm' }
'.'
+ br!
+ 'Most of the inner-workings of this page are documented in ',
+ link_to @walk 'articles/mmmfs'
}
for child in *@children