aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-11-22 11:07:24 +0000
committers-ol <s-ol@users.noreply.github.com>2018-11-22 11:07:24 +0000
commite98c5becba67d642b5fd5c6e4a206d79749e8953 (patch)
tree34965a21413107e089a77da8886dd85022c9e651
parentmove glitch cube, torus4d to experiments (diff)
downloadmmm-e98c5becba67d642b5fd5c6e4a206d79749e8953.tar.gz
mmm-e98c5becba67d642b5fd5c6e4a206d79749e8953.zip
bundle binary files as URLs
-rw-r--r--Tupfile2
-rw-r--r--Tuprules.lua10
-rw-r--r--Tuprules.tup1
-rw-r--r--build/bundle_fileder.moon (renamed from bundle_fileder.moon)75
-rw-r--r--build/bundle_module.moon (renamed from bundle.moon)0
-rw-r--r--build/render_fileder.moon (renamed from render.moon)15
-rw-r--r--build/util.moon16
-rw-r--r--mmm/Tupdefault3
-rw-r--r--mmm/mmmfs/browser.moon4
-rw-r--r--mmm/mmmfs/fileder.moon1
-rw-r--r--root/Tupdefault.lua14
-rw-r--r--root/articles/mmmfs/gallery/actual_image/image$png.pngbin0 -> 678429 bytes
-rw-r--r--root/articles/mmmfs/gallery/actual_image/preview: image$png.pngbin0 -> 31880 bytes
-rw-r--r--root/games/vision_training_kit/description: text$plain (renamed from root/games/vision-training-kit/description: text$plain)0
-rwxr-xr-xroot/games/vision_training_kit/icon: image$png.pngbin0 -> 16412 bytes
15 files changed, 93 insertions, 48 deletions
diff --git a/Tupfile b/Tupfile
index 30ea402..c955a33 100644
--- a/Tupfile
+++ b/Tupfile
@@ -12,4 +12,4 @@ include_rules
: scss/main.scss |> !sassc |> root/main.css
# bundle for client loading
-: mmm/.bundle.lua | <modules> |> ^ WRAP %d^ moon bundle.moon %o --wrap %f |> root/mmm.bundle.lua
+: mmm/.bundle.lua | <modules> |> ^ WRAP %d^ moon &(build)/bundle_module.moon %o --wrap %f |> root/mmm.bundle.lua
diff --git a/Tuprules.lua b/Tuprules.lua
index 77b1ed8..cd711a5 100644
--- a/Tuprules.lua
+++ b/Tuprules.lua
@@ -1,3 +1,13 @@
tup.creategitignore()
root = tup.nodevariable '.'
+build = tup.nodevariable 'build'
+
+function lua_path()
+ local LUA_PATH = {}
+ LUA_PATH += root .. '/?.lua'
+ LUA_PATH += root .. '/?.server.lua'
+ LUA_PATH += root .. '/?/init.lua'
+ LUA_PATH += root .. '/?/init.server.lua'
+ return 'LUA_PATH="' .. table.concat(LUA_PATH, ';') .. '"'
+end
diff --git a/Tuprules.tup b/Tuprules.tup
index 3c408e7..eec602c 100644
--- a/Tuprules.tup
+++ b/Tuprules.tup
@@ -1,3 +1,4 @@
.gitignore
&root = .
+&build = build
diff --git a/bundle_fileder.moon b/build/bundle_fileder.moon
index 7bccf53..c9f8c35 100644
--- a/bundle_fileder.moon
+++ b/build/bundle_fileder.moon
@@ -1,21 +1,23 @@
require 'mmm'
+import get_path from require 'build.util'
import Fileder, Key from require 'mmm.mmmfs.fileder'
import opairs from require 'mmm.ordered'
import to_lua from require 'moonscript.base'
-require 'lfs'
-- usage:
--- moon bundle_fileder.moon <dirname> <facets>... -- <children>...
-{ dirname } = arg
+-- moon bundle_fileder.moon <path_to_root> <dirname> <facets>... -- <children>...
+{ path_to_root, dirname } = arg
+assert path_to_root, "please specify the relative root path"
assert dirname, "please specify the fileder dirname"
+path = get_path path_to_root
facets = {}
children_bundles = {}
do
addto = facets
- for file in *arg[2,]
+ for file in *arg[3,]
continue if file == 'Tupdefault.lua'
if file == '--'
@@ -27,8 +29,9 @@ do
load_facet = (filename) ->
key = (filename\match '(.*)%.%w+') or filename
key = Key key\gsub '%$', '/'
+ key.filename = filename
- file = io.open filename, 'r'
+ file = assert (io.open filename, 'r'), "couldn't open facet file '#{filename}'"
value = file\read '*all'
file\close!
@@ -37,18 +40,6 @@ load_facet = (filename) ->
-- escape a string for lua aparser
escape = (str) -> string.format '%q', tostring str
--- compile a moonscript facet to lua
-compile = (old, new, val) ->
- lua, err = to_lua val
-
- if not lua
- error "Error compiling #{old}: #{err}"
-
- "-- this facet has been transpiled from '#{old}'
--- to '#{new}' for execution in the browser.
--- refer to the original facet as the source.
-#{lua}"
-
-- dump a fileder subtree as Lua source
dump_fileder = do
_dump = (fileder, root=false) ->
@@ -80,8 +71,37 @@ end
return #{_dump fileder, true}
"
+renders = {
+ {
+ inp: '^text/moonscript %-> (.*)'
+ out: 'text/lua -> %1'
+ render: (val, fileder, old, new) ->
+ lua, err = to_lua val
+
+ if not lua
+ error "Error compiling #{old}: #{err}"
+
+ "-- this moonscript facet has been transpiled to
+-- '#{new}' for execution in the browser.
+-- refer to the original facet as the source.
+#{lua}"
+ },
+ {
+ inp: '^image/'
+ out: 'URL -> %0'
+ render: (val, fileder, old, new) -> "#{fileder.path}/#{old.filename}", "[binary removed]"
+ },
+ {
+ inp: '^video/'
+ out: 'URL -> %0'
+ render: (val, fileder, old, new) -> "#{fileder.path}/#{old.filename}", "[binary removed]"
+ },
+}
+
with io.open '$bundle.lua', 'w'
- \write dump_fileder with Fileder 'name: alpha': dirname
+ \write dump_fileder with fileder = Fileder 'name: alpha': dirname
+ \mount path, true
+
order = nil
children = {}
@@ -94,12 +114,21 @@ with io.open '$bundle.lua', 'w'
extra_facets = {}
for key, value in pairs .facets
- continue unless key.type\match '^text/moonscript %->'
- built_key = Key key.name, key.type\gsub '^text/moonscript %-> (.*)', 'text/lua -> %1'
- built_key.original = key
+ for { :inp, :out, :render } in *renders
+ continue unless key.type\match inp
+
+ built_key = Key key.name, key.type\gsub inp, out
+ built_key.original = key
+
+ -- dont overwrite existing keys
+ continue if \has built_key
+
+ rendered, replace = render value, fileder, key, built_key
+
+ extra_facets[built_key] = rendered
+ .facets[key] = replace if replace
- continue if \has built_key
- extra_facets[built_key] = compile key, built_key, value
+ break
for k,v in pairs extra_facets
.facets[k] = v
diff --git a/bundle.moon b/build/bundle_module.moon
index 1c6b5f6..1c6b5f6 100644
--- a/bundle.moon
+++ b/build/bundle_module.moon
diff --git a/render.moon b/build/render_fileder.moon
index 4998452..d76d162 100644
--- a/render.moon
+++ b/build/render_fileder.moon
@@ -1,20 +1,13 @@
require 'mmm'
import render from require 'mmm.mmmfs'
+import get_path from require 'build.util'
-- usage:
-- moon render.moon <path_to_root>
-{ root } = arg
+{ path_to_root } = arg
-assert root, "please specify the relative root path as an argument"
-
-require 'lfs'
-cwd = lfs.currentdir!
-path = ''
-
-while root\find '^%.%./'
- root = root\match '^%.%./(.*)'
- cwd, trimmed = cwd\match '(.*)(/[^/]+)$'
- path = trimmed .. path
+assert path_to_root, "please specify the relative root path"
+path = get_path path_to_root
root = dofile '$bundle.lua'
assert root, "couldn't load $bundle.lua"
diff --git a/build/util.moon b/build/util.moon
new file mode 100644
index 0000000..b9c9613
--- /dev/null
+++ b/build/util.moon
@@ -0,0 +1,16 @@
+require 'lfs'
+
+get_path = (root) ->
+ cwd = lfs.currentdir!
+ path = ''
+
+ while root\find '^%.%./'
+ root = root\match '^%.%./(.*)'
+ cwd, trimmed = cwd\match '(.*)(/[^/]+)$'
+ path = trimmed .. path
+
+ path
+
+{
+ :get_path
+}
diff --git a/mmm/Tupdefault b/mmm/Tupdefault
index b827c36..3a0783f 100644
--- a/mmm/Tupdefault
+++ b/mmm/Tupdefault
@@ -1,4 +1,5 @@
include_rules
+
: foreach *.moon |> ^ MOON %f^ moonc -p > %o %f |> %B.lua <modules>
-: <modules> |> ^ BNDL %d^ moon &(root)/bundle.moon %o %d %<modules> |> .bundle.lua ../<modules>
+: <modules> |> ^ BNDL %d^ moon &(build)/bundle_module.moon %o %d %<modules> |> .bundle.lua ../<modules>
diff --git a/mmm/mmmfs/browser.moon b/mmm/mmmfs/browser.moon
index f654074..5038a3a 100644
--- a/mmm/mmmfs/browser.moon
+++ b/mmm/mmmfs/browser.moon
@@ -98,7 +98,7 @@ class Browser
current = @facet\get!
current = current and current.name
with select :onchange, disabled: not fileder
- has_main = fileder\find current.name, '.*'
+ has_main = fileder and fileder\find current.name, '.*'
\append option '(main)', value: '', disabled: not has_main, selected: current == ''
if fileder
for i, value in ipairs fileder\get_facets!
@@ -150,7 +150,7 @@ class Browser
-- (re)set to match when @facet changes
@inspect_prop = @facet\map (prop) ->
active = @active\get!
- key = active\find prop
+ key = active and active\find prop
key = key.original if key and key.original
key
diff --git a/mmm/mmmfs/fileder.moon b/mmm/mmmfs/fileder.moon
index 559e08b..114ec75 100644
--- a/mmm/mmmfs/fileder.moon
+++ b/mmm/mmmfs/fileder.moon
@@ -20,6 +20,7 @@ class Key
@name = opts.name
@type = opts.type
@original = opts.original
+ @filename = opts.filename
else
error "wrong argument type: #{type opts}, #{type second}"
diff --git a/root/Tupdefault.lua b/root/Tupdefault.lua
index 5cd45a9..039edf0 100644
--- a/root/Tupdefault.lua
+++ b/root/Tupdefault.lua
@@ -1,12 +1,6 @@
-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, ';') .. '"'
-
-bundle = LUA_PATH .. ' moon ' .. root .. '/bundle_fileder.moon'
-render = LUA_PATH .. ' moon ' .. root .. '/render.moon'
+local LUA_PATH = lua_path()
+bundle = LUA_PATH .. ' moon ' .. build .. '/bundle_fileder.moon'
+render = LUA_PATH .. ' moon ' .. build .. '/render_fileder.moon'
-- @TODO: whish there was a better glob for this?
facets = tup.glob '*$*'
@@ -20,7 +14,7 @@ facets += root .. '/<modules>'
tup.rule(
facets,
- '^ BNDL %d^ ' .. bundle .. ' %d ' .. inputs .. ' -- %<children>',
+ '^ BNDL %d^ ' .. bundle .. ' ' .. root .. ' %d ' .. inputs .. ' -- %<children>',
{ '$bundle.lua', '../<children>' }
)
diff --git a/root/articles/mmmfs/gallery/actual_image/image$png.png b/root/articles/mmmfs/gallery/actual_image/image$png.png
new file mode 100644
index 0000000..b499413
--- /dev/null
+++ b/root/articles/mmmfs/gallery/actual_image/image$png.png
Binary files differ
diff --git a/root/articles/mmmfs/gallery/actual_image/preview: image$png.png b/root/articles/mmmfs/gallery/actual_image/preview: image$png.png
new file mode 100644
index 0000000..f9dbfad
--- /dev/null
+++ b/root/articles/mmmfs/gallery/actual_image/preview: image$png.png
Binary files differ
diff --git a/root/games/vision-training-kit/description: text$plain b/root/games/vision_training_kit/description: text$plain
index 0511e77..0511e77 100644
--- a/root/games/vision-training-kit/description: text$plain
+++ b/root/games/vision_training_kit/description: text$plain
diff --git a/root/games/vision_training_kit/icon: image$png.png b/root/games/vision_training_kit/icon: image$png.png
new file mode 100755
index 0000000..ef73861
--- /dev/null
+++ b/root/games/vision_training_kit/icon: image$png.png
Binary files differ