diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-11-08 06:17:17 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-11-08 06:17:17 +0000 |
| commit | d11441884740d394f73f1a145b502e270482a2d2 (patch) | |
| tree | 8ce1258d8f66a65945b611b6a2836eadd5861889 | |
| parent | add $order mechanism (diff) | |
| download | mmm-d11441884740d394f73f1a145b502e270482a2d2.tar.gz mmm-d11441884740d394f73f1a145b502e270482a2d2.zip | |
recursive tup stuff
| -rw-r--r-- | Tupfile | 29 | ||||
| -rw-r--r-- | Tuprules.lua | 3 | ||||
| -rw-r--r-- | Tuprules.tup | 3 | ||||
| -rw-r--r-- | bundle.moon | 56 | ||||
| -rw-r--r-- | bundle_fileder.moon | 96 | ||||
| -rw-r--r-- | mmm/Tupdefault | 4 | ||||
| -rw-r--r-- | root/Tupdefault.lua | 23 | ||||
| -rw-r--r-- | root/articles/mmmfs/gallery.moon | 49 | ||||
| -rw-r--r-- | root/articles/mmmfs/gallery/image_1/URL -> image$png | 1 | ||||
| -rw-r--r-- | root/articles/mmmfs/gallery/image_1/preview: URL -> image$png | 1 | ||||
| -rw-r--r-- | root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon | 16 | ||||
| -rw-r--r-- | root/articles/mmmfs/gallery/slideshow: text$moonscript -> fn -> mmm$component.moon | 19 | ||||
| -rw-r--r-- | root/articles/mmmfs/gallery/text$moonscript -> fn -> mmm$dom.moon | 12 | ||||
| -rw-r--r-- | root/articles/mmmfs/gallery/title: text$plain | 1 | ||||
| -rw-r--r-- | tup.moon | 25 |
15 files changed, 238 insertions, 100 deletions
@@ -1,4 +1,4 @@ -.gitignore +include_rules !download = |> ^ DOWNLOAD %O^ curl -L https://github.com/fengari-lua/fengari-web/releases/download/@(FENGARI_VERSION)/`basename %o` > %o |> !sassc = |> ^ SCSS %b^ sassc -mauto %f %o |> | %o.map @@ -11,30 +11,9 @@ # render stylesheet : scss/main.scss |> !sassc |> dist/main.css -# preload full mmmfs tree -preload root -preload root/articles -preload root/articles/mmmfs -preload root/articles/mmmfs/empty -preload root/articles/mmmfs/image -preload root/articles/mmmfs/markdown -preload root/articles/realities -preload root/animations -preload root/animations/twisted -preload root/animations/koch -preload root/experiments -preload root/experiments/center_of_mass -preload root/experiments/tags -preload root/meta -preload root/meta/mmm.dom -preload root/meta/test_mmm.component -preload root/meta/todo - -# preload all of mmm -preload mmm -preload mmm/dom -preload mmm/mmmfs -preload mmm/component +# bundle for client loading +: mmm/.bundle.lua | <modules> |> ^ WRAP %d^ moon bundle.moon %o --wrap %f |> dist/mmm.bundle.lua +: root/$bundle.lua | <children> |> ^ WRAP %d^ cp '%f' '%o' |> dist/root.lua # render static content and compile sources run moon tup.moon diff --git a/Tuprules.lua b/Tuprules.lua new file mode 100644 index 0000000..77b1ed8 --- /dev/null +++ b/Tuprules.lua @@ -0,0 +1,3 @@ +tup.creategitignore() + +root = tup.nodevariable '.' diff --git a/Tuprules.tup b/Tuprules.tup new file mode 100644 index 0000000..3c408e7 --- /dev/null +++ b/Tuprules.tup @@ -0,0 +1,3 @@ +.gitignore + +&root = . diff --git a/bundle.moon b/bundle.moon index 5d855ea..8e277c7 100644 --- a/bundle.moon +++ b/bundle.moon @@ -2,23 +2,51 @@ output_name = assert arg[1], "please specify the output directory" escape = (str) -> string.format '%q', str +readfile = (name) -> + file = io.open name, 'r' + with file\read '*all' + file\close + with io.open output_name, 'w' - \write "local p = package.preload\n" + -- final wrap mode + if arg[2] == '--wrap' + assert #arg == 3, "too many arguments for 'wrap' mode" + bundle = arg[3] + + bundle = dofile bundle + \write "local p = package.preload\n" + for { :module, :file, :source } in *bundle + module = escape module + \write "if not p[#{module}] then p[#{module}] = load(#{escape source}, #{escape file}) end\n" - for i=2, #arg - file_name = arg[i] + -- iterative bundling mode + else + \write "return {\n" - file = io.open file_name, 'r' - code = file\read '*all' - file\close! + for i=2, #arg + file = arg[i] - module = file_name\gsub '/', '.' - module = module\gsub '%.lua$', '' - module = module\gsub '%.init$', '' - module = module\match '^dist%.(.*)' + if dirname = file\match '^([%w-_]+)/%.bundle%.lua$' + bundle = dofile file + for { :module, :file, :source } in *bundle + \write " +{ + module = #{escape dirname .. '.' .. module}, + file = #{escape dirname .. '/' .. file}, + source = #{escape source}, +}, + " + else + module = file\gsub '%.lua$', '' + module = module\gsub '%.init$', '' + \write " +{ + module = #{escape module}, + file = #{escape file}, + source = #{escape readfile file}, +}, + " - file_name = escape file_name - code = escape code - module = escape module + \write "}" - \write "if not p[#{module}] then p[#{module}] = load(#{code}, #{file_name}) end\n" + \close! diff --git a/bundle_fileder.moon b/bundle_fileder.moon new file mode 100644 index 0000000..7c0fb26 --- /dev/null +++ b/bundle_fileder.moon @@ -0,0 +1,96 @@ +package.moonpath = './?.server.moon;./?/init.server.moon;' .. package.moonpath +require 'mmm.init' +import Key from require 'mmm.mmmfs' +import load_fileder, load_property from require 'mmm.mmmfs.fs' +import to_lua from require 'moonscript.base' + +-- usage: +-- moon bundle_fileder.moon <dirname> <facets>... -- <children>... +{ dirname } = arg + +assert dirname, "please specify the fileder dirname" + +facets = {} +children_bundles = {} + +do + addto = facets + for file in *arg[2,] + if file == '--' + addto = children_bundles + continue + table.insert addto, file + +-- 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, root=false) -> + code = "Fileder {" + + for key, val in pairs fileder.props + code ..= "\n[#{escape key}] = #{escape val}," + + if root and key.type\match '^text/moonscript %->' + newkey = Key key.name, key.type\gsub '^text/moonscript %-> (.*)', 'text/lua -> %1' + code ..= "\n[fromcache(#{escape newkey}, #{escape key})] = #{compile key, newkey, val}," + + for child in *fileder.children + code ..= "\n#{_dump child}," + + code ..= "\n}" + 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, true} + " + +import Fileder from require 'mmm.mmmfs.fileder' +import opairs from require 'mmm.ordered' + +with io.open '$bundle.lua', 'w' + \write dump_fileder with Fileder 'name: alpha': dirname + order = nil + children = {} + + for facet in *facets + if facet == '$order' + order = [line for line in io.lines facet] + continue + key, value = load_property '', facet + .props[key] = value + + for child in *children_bundles + -- @BUG: child bundles are malformed due to Tup bug ($ symbol) + child = child\gsub '/%.lua$', '/$bundle.lua' + + dirname = assert child\match '^([%w-_%.]+)/%$bundle%.lua$' + children[dirname] = dofile child + + if order + -- order from order file + for i, name in pairs order + child = assert children[name], "child in $order but not fs: #{name} of #{path}" + table.insert .children, child + children[name] = nil + + -- sort remainder alphabeticalally + for name, child in opairs children + table.insert .children, child + warn "child #{name} of #{path} not in $order!" if order + + \close! diff --git a/mmm/Tupdefault b/mmm/Tupdefault new file mode 100644 index 0000000..1b4dde6 --- /dev/null +++ b/mmm/Tupdefault @@ -0,0 +1,4 @@ +include_rules + +: foreach *.moon |> ^ MOON %f^ moonc -o %o %f 2>/dev/null |> %B.lua <modules> +: <modules> |> ^ BNDL %d^ moon &(root)/bundle.moon %o %<modules> |> .bundle.lua ../<modules> diff --git a/root/Tupdefault.lua b/root/Tupdefault.lua new file mode 100644 index 0000000..b6cf700 --- /dev/null +++ b/root/Tupdefault.lua @@ -0,0 +1,23 @@ +facets = tup.glob '*' +inputs = '' +for i, file in ipairs(facets) do + inputs = inputs .. " '" .. file .. "'" +end + +LUA_PATH = {} +LUA_PATH += root .. '/?.lua' +LUA_PATH += root .. '/?.server.lua' +LUA_PATH += root .. '/?/init.lua' +LUA_PATH += root .. '/?/init.server.lua' +LUA_PATH = 'LUA_PATH="' .. table.concat(LUA_PATH, ';') .. '"' + +exec = LUA_PATH .. ' moon ' .. root .. '/bundle_fileder.moon' + +facets += '<children>' +facets += root .. '/<modules>' + +tup.rule( + facets, + '^ BNDL %d^ ' .. exec .. ' %d ' .. inputs .. ' -- %<children>', + { '$bundle.lua', '../<children>' } +) diff --git a/root/articles/mmmfs/gallery.moon b/root/articles/mmmfs/gallery.moon deleted file mode 100644 index 4713101..0000000 --- a/root/articles/mmmfs/gallery.moon +++ /dev/null @@ -1,49 +0,0 @@ -import define_fileders from require 'mmm.mmmfs' -import div, h1, a, img, br from require 'mmm.dom' - -Fileder = define_fileders ... - -with Fileder { - 'name: alpha': 'gallery', - 'title: text/plain': "A Gallery of 25 random pictures, come in!", - 'preview: fn -> mmm/dom': => div { - 'the first pic as a little taste:', - br!, - img src: @children[1]\get 'preview', 'URL -> image/png' - } - 'fn -> mmm/dom': => - link = (child) -> a { - href: '#', - onclick: -> BROWSER\navigate child.path - img src: child\gett 'preview', 'URL -> image/png' - } - - content = [link child for child in *@children] - table.insert content, 1, h1 'gallery index' - div content - - 'slideshow: fn -> mmm/dom': => - import ReactiveVar, text, elements from require 'mmm.component' - - index = ReactiveVar 1 - - prev = (i) -> math.max 1, i - 1 - next = (i) -> math.min #@children, i + 1 - - e = elements - e.div { - e.div { - e.a 'prev', href: '#', onclick: -> index\transform prev - index\map (i) -> text " image ##{i} " - e.a 'next', href: '#', onclick: -> index\transform next - }, - index\map (i) -> img src: @children[i]\gett nil, 'URL -> image/png' - } - } - for i=1,25 - id = 120 + i - .children[i] = Fileder { - 'name: alpha': "image#{id}" - 'URL -> image/png': "https://picsum.photos/600/600/?image=#{id}" - 'preview: URL -> image/png': "https://picsum.photos/200/200/?image=#{id}" - } diff --git a/root/articles/mmmfs/gallery/image_1/URL -> image$png b/root/articles/mmmfs/gallery/image_1/URL -> image$png new file mode 100644 index 0000000..7cf76ff --- /dev/null +++ b/root/articles/mmmfs/gallery/image_1/URL -> image$png @@ -0,0 +1 @@ +https://picsum.photos/600/600/?image=101 diff --git a/root/articles/mmmfs/gallery/image_1/preview: URL -> image$png b/root/articles/mmmfs/gallery/image_1/preview: URL -> image$png new file mode 100644 index 0000000..2b2233b --- /dev/null +++ b/root/articles/mmmfs/gallery/image_1/preview: URL -> image$png @@ -0,0 +1 @@ +https://picsum.photos/200/200/?image=101 diff --git a/root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon b/root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon new file mode 100644 index 0000000..83aa7d4 --- /dev/null +++ b/root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon @@ -0,0 +1,16 @@ +import div, img, br from require 'mmm.dom' + +=> div { + 'the first pic as a little taste:', + br!, + img src: @children[1]\get 'preview', 'URL -> image/png' +} + } + +-- for i=1,25 +-- id = 120 + i +-- .children[i] = Fileder { +-- 'name: alpha': "image#{id}" +-- 'URL -> image/png': "https://picsum.photos/600/600/?image=#{id}" +-- 'preview: URL -> image/png': "https://picsum.photos/200/200/?image=#{id}" +-- } diff --git a/root/articles/mmmfs/gallery/slideshow: text$moonscript -> fn -> mmm$component.moon b/root/articles/mmmfs/gallery/slideshow: text$moonscript -> fn -> mmm$component.moon new file mode 100644 index 0000000..0178ac2 --- /dev/null +++ b/root/articles/mmmfs/gallery/slideshow: text$moonscript -> fn -> mmm$component.moon @@ -0,0 +1,19 @@ +import ReactiveVar, text, elements from require 'mmm.component' +import div, a, img from elements + +=> + index = ReactiveVar 1 + + prev = (i) -> math.max 1, i - 1 + next = (i) -> math.min #@children, i + 1 + + div { + div { + a 'prev', href: '#', onclick: -> index\transform prev + index\map (i) -> text " image ##{i} " + a 'next', href: '#', onclick: -> index\transform next + }, + index\map (i) -> + child = assert @children[i], "image not found!" + img src: @children[i]\gett 'URL -> image/png' + } diff --git a/root/articles/mmmfs/gallery/text$moonscript -> fn -> mmm$dom.moon b/root/articles/mmmfs/gallery/text$moonscript -> fn -> mmm$dom.moon new file mode 100644 index 0000000..9bdac54 --- /dev/null +++ b/root/articles/mmmfs/gallery/text$moonscript -> fn -> mmm$dom.moon @@ -0,0 +1,12 @@ +import div, h1, a, img, br from require 'mmm.dom' + +=> + link = (child) -> a { + href: '#', + onclick: -> BROWSER\navigate child.path + img src: child\gett 'preview', 'URL -> image/png' + } + + content = [link child for child in *@children] + table.insert content, 1, h1 'gallery index' + div content diff --git a/root/articles/mmmfs/gallery/title: text$plain b/root/articles/mmmfs/gallery/title: text$plain new file mode 100644 index 0000000..ad74eec --- /dev/null +++ b/root/articles/mmmfs/gallery/title: text$plain @@ -0,0 +1 @@ +A Gallery of 25 random pictures, come on in! @@ -20,22 +20,23 @@ enum_dir = do coroutine.wrap -> yieldtree dir -- COMPILE MOONSCRIPT -for file in enum_dir 'mmm' - continue if file\match '%.server%.moon$' - basename = assert file\match '(.*)%.moon$' - basename = (file\match '(.*)%.client') or basename - print ": #{file} |> ^ MOON %b > %o^ moonc -o %o %f |> dist/#{basename}.lua {mmm_src}" - --- GENERATE BUNDLES -print ": {mmm_src} |> ^ BUNDLE mmm^ moon bundle.moon %o %f |> dist/mmm.bundle.lua" +-- for file in enum_dir 'mmm' +-- continue if file\match '%.server%.moon$' +-- basename = assert file\match '(.*)%.moon$' +-- basename = (file\match '(.*)%.client') or basename +-- print ": #{file} |> ^ MOON %b > %o^ moonc -o %o %f |> dist/#{basename}.lua {mmm_src}" +-- +-- -- GENERATE BUNDLES +-- print ": {mmm_src} |> ^ BUNDLE mmm^ moon bundle.moon %o %f |> dist/mmm.bundle.lua" -- COMPILE AND DUMP TREE -print ": |> ^ DUMP root^ moon dump_tree.moon %o |> dist/root.lua" +-- print ": |> ^ DUMP root^ moon dump_tree.moon %o |> dist/root.lua" -- PRE-RENDER TREE -import load_fileder from require 'mmm.mmmfs.fs' - -root = load_fileder! +-- import load_fileder from require 'mmm.mmmfs.fs' +-- +-- root = load_fileder! +root = dofile 'root/$bundle.lua' root\mount! for fileder in coroutine.wrap root\iterate |
