aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2020-12-09 10:24:37 +0000
committers-ol <s+removethis@s-ol.nu>2020-12-09 11:15:44 +0000
commit2bc1457a710b1cc9dffeec250a623e27aba92e8d (patch)
tree4dc3fcf2f8ba57387de257ff70436f8332b7c53c
parentremove relative import system (diff)
downloadmmm-2bc1457a710b1cc9dffeec250a623e27aba92e8d.tar.gz
mmm-2bc1457a710b1cc9dffeec250a623e27aba92e8d.zip
remove BROWSER.root
-rw-r--r--build/render_all.moon3
-rw-r--r--mmm/mmmfs/fileder.moon29
-rw-r--r--mmm/mmmfs/meta.moon6
-rw-r--r--mmm/mmmfs/util.moon29
4 files changed, 30 insertions, 37 deletions
diff --git a/build/render_all.moon b/build/render_all.moon
index 1135d27..5455446 100644
--- a/build/render_all.moon
+++ b/build/render_all.moon
@@ -15,7 +15,7 @@ require 'mmm'
import Fileder, dir_base from require 'mmm.mmmfs.fileder'
import get_store from require 'mmm.mmmfs.stores'
-export UNSAFE, STATIC, BROWSER
+export UNSAFE, STATIC
UNSAFE = true
STATIC = {
@@ -33,7 +33,6 @@ require 'mmm.mmmfs'
store = get_store store
root = Fileder store
-BROWSER = :root
print "rendering to #{output}"
diff --git a/mmm/mmmfs/fileder.moon b/mmm/mmmfs/fileder.moon
index 2f4f391..6ce8e91 100644
--- a/mmm/mmmfs/fileder.moon
+++ b/mmm/mmmfs/fileder.moon
@@ -53,7 +53,7 @@ inext = (tbl, i) ->
-- * @facets - Facet Map (Key to Value)
-- * @children - Children Array
class Fileder
- new: (@store, @path='') =>
+ new: (@store, @path='', @root=@) =>
@loaded = false
-- lazy-load children,
@@ -70,20 +70,13 @@ class Fileder
__index: (t, k) ->
@load! unless @loaded
-
- if 'string' == type k
+ if 'string' == type(k) and '$' != k\sub(1,1)
@walk "#{@path}/#{k}"
- else
- rawget t, k
__newindex: (t, k, child) ->
rawset t, k, child
return if child.path
-
- if @path == '/'
- child\mount '/'
- elseif @path
- child\mount @path .. '/'
+ child\mount @path .. '/'
}
-- lazy-load facets,
@@ -167,12 +160,12 @@ class Fileder
index or= @store\get_index @path
for path_or_index in *index.children
- child = Fileder @store, path_or_index
+ child = Fileder @store, path_or_index, @root
name = child\get 'name: alpha'
if '$' != name\sub 1, 1
table.insert @children, child
- elseif name == '$mmm'
- @meta = child
+ else
+ @children[name] = child
for key in *index.facets
key = Key key
@@ -201,13 +194,15 @@ class Fileder
-- gotcha
return @ if #path == #@path
+ @load! unless @loaded
+
+ if match = @children['$mmm'] and @children['$mmm']\walk path
+ return match
+
for child in *@children
if match = child\walk path
return match
- if match = @meta and @meta\walk path
- return match
-
-- recursively mount fileder and children at path
-- * path - the path to mount at
-- * mount_as - dont append own name to path
@@ -316,7 +311,7 @@ class Fileder
-- add a child fileder with given name
add_child: (name) =>
new_path = @store\create_fileder @path, name
- with new_child = Fileder @store, new_path
+ with new_child = Fileder @store, new_path, @root
table.insert @children, new_child
-- remove a child with given index
diff --git a/mmm/mmmfs/meta.moon b/mmm/mmmfs/meta.moon
index 35a2254..ce3f4a1 100644
--- a/mmm/mmmfs/meta.moon
+++ b/mmm/mmmfs/meta.moon
@@ -15,8 +15,6 @@ yield_ancestors = do
(path) => coroutine.wrap -> step @, path
get_meta = (fileder, path) ->
- assert BROWSER.root
-
if path
path = "$mmm/#{path}"
else
@@ -28,9 +26,11 @@ get_meta = (fileder, path) ->
max_path = closest
guard_self = true
+ assert fileder.root, "'#{fileder}' has no root!"
+
coroutine.wrap ->
-- search until closest non-meta ancestor
- for ancestor in yield_ancestors BROWSER.root, max_path
+ for ancestor in yield_ancestors fileder.root, max_path
break if guard_self and ancestor.path == max_path
if result = ancestor\walk path
diff --git a/mmm/mmmfs/util.moon b/mmm/mmmfs/util.moon
index cd93196..86a6c3c 100644
--- a/mmm/mmmfs/util.moon
+++ b/mmm/mmmfs/util.moon
@@ -16,26 +16,25 @@ tourl = (path, _view) ->
(elements) ->
import a, div, span, sup, b, pre from elements
- find_fileder = (fileder, origin) ->
- if 'string' == type fileder
- if fileder == ''
+ find_fileder = (path, origin) ->
+ if 'string' == type path
+ if path == ''
assert origin, "cannot resolve empty path without origin!"
return origin
- if '/' ~= fileder\sub 1, 1
- assert origin, "cannot resolve relative path '#{fileder}' without origin!"
- fileder = "#{origin.path}/#{fileder}"
+ if '/' ~= path\sub 1, 1
+ assert origin, "cannot resolve relative path '#{path}' without origin!"
+ path = "#{origin.path}/#{path}"
- while fileder\match '/([^/]-)/%.%./'
- fileder = fileder\gsub '/([^/]-)/%.%./', '/'
+ while path\match '/([^/]-)/%.%./'
+ path = path\gsub '/([^/]-)/%.%./', '/'
- if origin.path == fileder\sub 1, #origin.path
- assert (origin\walk fileder), "couldn't resolve path '#{fileder}' from #{origin}"
+ if origin.path == path\sub 1, #origin.path
+ assert (origin\walk path), "couldn't resolve path '#{path}' from #{origin}"
else
- assert BROWSER and BROWSER.root, "cannot resolve absolute path '#{fileder}' without BROWSER and root set!"
- assert (BROWSER.root\walk fileder), "couldn't resolve path '#{fileder}'"
+ assert (origin.root\walk path), "couldn't resolve path '#{path}'"
else
- assert fileder, "no fileder passed."
+ assert path, "no path passed."
navigate_to = (path, name, opts={}) ->
opts.href = tourl path
@@ -62,7 +61,7 @@ tourl = (path, _view) ->
interactive_link = (text, view=':text/html+interactive') ->
assert MODE == 'SERVER'
- path = BROWSER.path
+ path = BROWSER.path -- @TODO
path = table.concat path, '/' if 'table' == type BROWSER.path
a text, href: tourl path, view
@@ -72,7 +71,7 @@ tourl = (path, _view) ->
assert not opts.wrap, "raw and wrap cannot both be set on embed"
opts.wrap = 'raw'
opts.wrap or= 'well'
-
+
fileder = find_fileder fileder, origin
-- node = fileder\gett name, 'mmm/dom'