diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-11-06 07:19:59 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-11-06 07:19:59 +0000 |
| commit | a7e539c272ffcd9e14fb58f8c24714cdff8e7c17 (patch) | |
| tree | 404f92906bd402b1c394f7b521508b5138e76d98 /dump_tree.moon | |
| parent | inspect mode wip (diff) | |
| parent | add metadata for compilation (diff) | |
| download | mmm-a7e539c272ffcd9e14fb58f8c24714cdff8e7c17.tar.gz mmm-a7e539c272ffcd9e14fb58f8c24714cdff8e7c17.zip | |
Merge branch 'tru-fs' into inspect-mode
Diffstat (limited to 'dump_tree.moon')
| -rw-r--r-- | dump_tree.moon | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/dump_tree.moon b/dump_tree.moon new file mode 100644 index 0000000..a35a223 --- /dev/null +++ b/dump_tree.moon @@ -0,0 +1,61 @@ +package.moonpath = './?.server.moon;./?/init.server.moon;' .. package.moonpath +require 'mmm.init' +import Key from require 'mmm.mmmfs' +import load_fileder from require 'mmm.mmmfs.fs' +import to_lua from require 'moonscript.base' + +-- usage: +-- moon render.moon <output> [fileder_path] +{ output_name, path } = arg + +assert output_name, "please specify the output filename as an argument" +path or= '/' + +root = load_fileder 'root' .. path +root\mount path + +-- dump a fileder subtree as Lua source +dump_fileder = do + escape = (str) -> string.format '%q', tostring str + + compile = (old, new, val) -> escape " +-- this property has been transpiled from '#{old}' +-- to '#{new}' for execution in the browser. +-- refer to the original property as the source. +#{to_lua val}" + + _dump = (fileder) -> + code = "Fileder {" + + for key, val in pairs fileder.props + code ..= " + [#{escape key}] = #{escape val}," + + if key.type\match '^text/moonscript %->' + newkey = Key key.name, key.type\gsub '^text/moonscript %-> (.*)', 'text/lua -> %1' + code ..= " + [fromcache(#{escape newkey}, #{escape key})] = #{compile key, newkey, val}," + + for child in *fileder.children + code ..= " + #{_dump child}," + + code ..= " + }" + code + + + (fileder) -> " + local mmmfs = require 'mmm.mmmfs' + local Key, Fileder = mmmfs.Key, mmmfs.Fileder + local function fromcache(str, orig) + local key = Key(str) + key.original = Key(orig) + return key + end + + return #{_dump fileder} + " + +with io.open output_name, 'w' + \write dump_fileder root |
