aboutsummaryrefslogtreecommitdiffstats
path: root/app/mmmfs/init.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-10-27 07:31:37 +0000
committers-ol <s-ol@users.noreply.github.com>2018-10-27 07:31:37 +0000
commit9a68eccca995ee5b4dc0ffd2698a7a6eb039f6de (patch)
tree266b2a74f25564bba469b32332bb520bcec40a49 /app/mmmfs/init.moon
parentrename to mmmfs, add canvas on client (diff)
downloadmmm-9a68eccca995ee5b4dc0ffd2698a7a6eb039f6de.tar.gz
mmm-9a68eccca995ee5b4dc0ffd2698a7a6eb039f6de.zip
comment mmmfs
Diffstat (limited to 'app/mmmfs/init.moon')
-rw-r--r--app/mmmfs/init.moon46
1 files changed, 34 insertions, 12 deletions
diff --git a/app/mmmfs/init.moon b/app/mmmfs/init.moon
index 0808aee..d6ed9fe 100644
--- a/app/mmmfs/init.moon
+++ b/app/mmmfs/init.moon
@@ -1,10 +1,9 @@
export ^
+-- list of interps
+-- interp signature is (fileder, value) -> value
interps = {
- {
- name: 'moon',
- transform: (method) => method @
- },
+ moon: (method) => method @
}
split = (str, delim='->') ->
@@ -14,7 +13,14 @@ split = (str, delim='->') ->
interp, rest = str\match ' *(%w+) *-> *(.*)'
{ interp }, rest
+-- Key of a Fileder Property
+-- contains:
+-- * @name - key name or '' for main content
+-- * @type - final type after interps
+-- * @interps - array describing interp chain
class Key
+ -- instantiate from table w/ keys described above
+ -- or string like 'name: interp -> interp -> type' (name + interps optional)
new: (opts) =>
if 'string' == type opts
@name, rest = opts\match '(%w+): *(.+)'
@@ -29,8 +35,10 @@ class Key
else
error 'wrong argument type'
- -- get a function that interpretes thi type according to @interps
- get_interp: (overrides) =>
+ -- get a function that interpretes a raw value according to @interps
+ -- and returns a value of @type
+ -- overrides is a map of interp overrides
+ get_interp: (overrides={}) =>
return ((val) => val) if #@interps == 0
assert #@interps == 1, 'not supported rn' -- @TODO
@@ -38,12 +46,13 @@ class Key
return overrides[_name] if overrides and overrides[_name]
- for { :name, :transform } in *interps
- if name == _name
- return transform
-
- error "interp not found: '#{_name}'"
+ assert overrides[_name] or interps[_name], "interp not found: '#{_name}'"
+-- list of converts
+-- converts each have
+-- * inp - input type
+-- * out - output type
+-- * transform - function (inp) -> out
converts = {
{
inp: 'mmm/dom',
@@ -108,7 +117,14 @@ do
.innerHTML = markdown md
}
+-- Fileder itself
+-- contains:
+-- * @props - Property Map (Key to Value)
+-- * @children - Children Array
class Fileder
+ -- instantiate from props and children tables
+ -- or mix in one table (numeric keys are children, remainder props)
+ -- prop-keys are passed to Key constructor
new: (props, @children) =>
if not @children
@children = for i, child in ipairs props
@@ -117,7 +133,10 @@ class Fileder
@props = { (Key k), v for k, v in pairs props }
- gett: (...) => assert @get ...
+ -- get property according to criteria, crash if no value or conversion path
+ -- * name - property name (optional: defaults to main content)
+ -- * type - wanted result type
+ -- * overrides - map of interp overrides (optional)
get: (name='', type, overrides) =>
if not type
type = name
@@ -143,6 +162,9 @@ class Fileder
nil, "node doesn't have value for #{name}:#{type}"
+ -- like get, throw if no value or conversion path
+ gett: (...) => assert @get ...
+
require = relative ...
root = require '.tree'