diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-10-19 04:12:19 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-10-19 04:12:19 +0000 |
| commit | 727f04aac784382e7ecb18b817830d145355b735 (patch) | |
| tree | bede6333759084b40820dc2c4e364f69d84e48cb | |
| parent | fix all pages (diff) | |
| download | mmm-727f04aac784382e7ecb18b817830d145355b735.tar.gz mmm-727f04aac784382e7ecb18b817830d145355b735.zip | |
switch to self-rendering lua code
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Tupfile | 25 | ||||
| -rw-r--r-- | app/index.moon | 70 | ||||
| -rw-r--r-- | app/tags/init.moon | 146 | ||||
| -rw-r--r-- | client.moon | 5 | ||||
| m--------- | dist | 0 | ||||
| -rw-r--r-- | lib/html.client.moon | 5 | ||||
| -rw-r--r-- | lib/html.server.moon | 1 | ||||
| -rw-r--r-- | render.moon | 1 | ||||
| -rw-r--r-- | server.moon | 3 | ||||
| -rw-r--r-- | tup.config | 1 |
11 files changed, 140 insertions, 119 deletions
@@ -1,5 +1,3 @@ -node_modules -dist ##### TUP GITIGNORE ##### ##### Lines below automatically generated by Tup. ##### Do not edit. @@ -1,4 +1,25 @@ .gitignore -: foreach app/* |> moon render.moon %B > %o |> dist/%B.html -: foreach lib/*.client.moon lib/*.shared.moon |> moonc -o %o %f |> dist/lib/%B.lua +!download = |> ^ DOWNLOAD %o^ curl -L https://github.com/fengari-lua/fengari-web/releases/download/@(FENGARI_VERSION)/`basename %o` > %o |> +!moonc = |> ^ CC %o^ moonc -o %o %f |> dist/%f.lua +!render = |> ^ RNDR %o^ moon render.moon %B > %o |> dist/%B.html + +preload app app/tags lib + +CLIENT += app/*.moon +CLIENT += app/tags/*.moon +CLIENT += lib/*.client.moon +CLIENT += lib/*.shared.moon + +PAGES += app/* +PAGES += app/tags + +# download fengari dependencies +: |> !download |> dist/fengari-web.js +: |> !download |> dist/fengari-web.js.map + +# compile client imports +: foreach $(CLIENT) |> !moonc |> + +# render static content +: foreach $(PAGES) |> !render |> diff --git a/app/index.moon b/app/index.moon index 3e79c60..59f7a4f 100644 --- a/app/index.moon +++ b/app/index.moon @@ -1,45 +1,43 @@ -on_client -> - import h1, p, a, br, ul, tt, li from require 'lib.html' +import h1, p, a, br, ul, tt, li from require 'lib.html' - moon = '\xe2\x98\xbd' - demos = - 'twisted': 'canvas animation', - 'todo': 'Todo demo of a simple reactive UI framework', - 'realities': 'draft of a paper on virtual and other realities', - 'center_of_mass': 'aligning characters by their centers of mass', - 'test_component': 'Test suite for the UI framework', - 'tags': 'Playground for Functional Tags', +moon = '\xe2\x98\xbd' +demos = + 'twisted': 'canvas animation', + 'todo': 'Todo demo of a simple reactive UI framework', + 'realities': 'draft of a paper on virtual and other realities', + 'center_of_mass': 'aligning characters by their centers of mass', + 'test_component': 'Test suite for the UI framework', + 'tags': 'Playground for Functional Tags', +on_client -> redirs = 'center-of-mass': 'center_of_mass', 'test-component': 'test_component', 'play-tags': 'tags', - back_button = -> - append p a { '< back', href: '/' } + { :location } = window + if location.search and #location.search > 1 + name = location.search\sub 2 + location.href = "#{redirs[name] or name}.html" - if window.location.search and #window.location.search > 1 - name = window.location.search\sub 2 - window.location.href = "#{redirs[name] or name}.html" - else - append h1 'mmm' - append p { - tt 'mmm' - ' is not the ' - tt 'www' - ', because it runs on ' - a { 'MoonScript', href: 'https://moonscript.org' } - '.' - br! - 'You can find the source code of everything ' - a { 'here', href: 'https://github.com/s-ol/mmm' } - '.' - } - append p 'current demos:' - append ul for name, desc in pairs demos - li (a name, href: "/#{name}.html"), ': ', desc +append h1 'mmm' +append p { + tt 'mmm' + ' is not the ' + tt 'www' + ', because it runs on ' + a { 'MoonScript', href: 'https://moonscript.org' } + '.' + br! + 'You can find the source code of everything ' + a { 'here', href: 'https://github.com/s-ol/mmm' } + '.' +} +append p 'current demos:' +append ul for name, desc in pairs demos + li (a name, href: "/#{name}.html"), ': ', desc - append p { - "made with #{moon} by " - a { 's-ol', href: 'https://twitter.com/S0lll0s' } - } +append p { + "made with #{moon} by " + a { 's-ol', href: 'https://twitter.com/S0lll0s' } +} diff --git a/app/tags/init.moon b/app/tags/init.moon index 9cbe53f..75469ea 100644 --- a/app/tags/init.moon +++ b/app/tags/init.moon @@ -1,86 +1,88 @@ -require = relative ... -import add_tag, rmv_tag, Node, Hierarchy, Toggle, NamespacedToggle from require '.tags' -import ReactiveVar, append, tohtml, text, div, form, span, h3, a, input, textarea, button from require 'lib.component' +on_client ((...) -> + require = relative ... + import add_tag, rmv_tag, Node, Hierarchy, Toggle, NamespacedToggle from require '.tags' + import ReactiveVar, append, tohtml, text, div, form, span, h3, a, input, textarea, button from require 'lib.component' -clone = (set) -> - assert set and 'table' == (type set), 'not a set' - { k,v for k,v in pairs set } -set_append = (val) -> (set) -> - with copy = clone set - copy[val] = val -set_remove = (val) -> (set) -> - with copy = clone set - copy[val] = nil -set_join = (tbl, sep=' ') -> - ret = '' - for tag in pairs tbl - ret ..= (tostring tag) .. sep - ret + clone = (set) -> + assert set and 'table' == (type set), 'not a set' + { k,v for k,v in pairs set } + set_append = (val) -> (set) -> + with copy = clone set + copy[val] = val + set_remove = (val) -> (set) -> + with copy = clone set + copy[val] = nil + set_join = (tbl, sep=' ') -> + ret = '' + for tag in pairs tbl + ret ..= (tostring tag) .. sep + ret -entries = div! -append entries + entries = div! + append entries -class ReactiveNode extends Node - new: (...) => - super ... - @tags = ReactiveVar @tags - @_node = div { - span @name, style: { 'font-weight': 'bold' }, - @tags\map (tags) -> with div! - for tag,_ in pairs tags - \append a (text tag), href: '#', style: { - display: 'inline-block', - margin: '0 5px', - } - } - @node = tohtml @_node + class ReactiveNode extends Node + new: (...) => + super ... + @tags = ReactiveVar @tags + @_node = div { + span @name, style: { 'font-weight': 'bold' }, + @tags\map (tags) -> with div! + for tag,_ in pairs tags + \append a (text tag), href: '#', style: { + display: 'inline-block', + margin: '0 5px', + } + } + @node = tohtml @_node - has: (tag) => @tags\get![tag] - add: (tag) => @tags\transform set_append tag - rmv: (tag) => @tags\transform set_remove tag + has: (tag) => @tags\get![tag] + add: (tag) => @tags\transform set_append tag + rmv: (tag) => @tags\transform set_remove tag -rules = { - Hierarchy 'home', 'sol' - Hierarchy 'sol', 'desktop' - Hierarchy 'desktop', 'vacation' - Hierarchy 'desktop', 'documents' - NamespacedToggle 'documents', 'work', 'personal' - -- Toggle 'work', 'personal' - -- Hierarchy 'documents', 'work' - -- Hierarchy 'documents', 'personal' -} + rules = { + Hierarchy 'home', 'sol' + Hierarchy 'sol', 'desktop' + Hierarchy 'desktop', 'vacation' + Hierarchy 'desktop', 'documents' + NamespacedToggle 'documents', 'work', 'personal' + -- Toggle 'work', 'personal' + -- Hierarchy 'documents', 'work' + -- Hierarchy 'documents', 'personal' + } -pictures = for i=1,10 - with node = ReactiveNode "picture#{i}.jpg" - entries\append node - add_tag node, 'vacation' + pictures = for i=1,10 + with node = ReactiveNode "picture#{i}.jpg" + entries\append node + add_tag node, 'vacation' -pers = ReactiveNode 'mypersonalfile.doc' -entries\append pers + pers = ReactiveNode 'mypersonalfile.doc' + entries\append pers -append div do - yield = coroutine.yield - step = coroutine.wrap -> - yield "mark document" - add_tag pers, 'documents' + append div do + yield = coroutine.yield + step = coroutine.wrap -> + yield "mark document" + add_tag pers, 'documents' - yield "mark personal" - add_tag pers, 'personal' + yield "mark personal" + add_tag pers, 'personal' - yield "mark work" - add_tag pers, 'work' + yield "mark work" + add_tag pers, 'work' - yield "unmark work" - rmv_tag pers, 'work' + yield "unmark work" + rmv_tag pers, 'work' - yield "remove from documents" - rmv_tag pers, 'documents' + yield "remove from documents" + rmv_tag pers, 'documents' - yield false + yield false - next_step = ReactiveVar step! - next_step\map (desc) -> - if desc - button (text desc), onclick: (e) => next_step\set step! - else - text '' + next_step = ReactiveVar step! + next_step\map (desc) -> + if desc + button (text desc), onclick: (e) => next_step\set step! + else + text '' +), ... diff --git a/client.moon b/client.moon index dd2ee12..884d96b 100644 --- a/client.moon +++ b/client.moon @@ -8,10 +8,9 @@ MODE = 'CLIENT' print = window.console\log warn = window.console\warn -print 'path is' +-- package.path = './?.shared.lua;./?.client.lua;' .. package.path print package.path - -package.path = './?.shared.lua;./?.client.lua;' .. package.path +package.path = './?.shared.moon.lua;./?.client.moon.lua;./?.moon.lua;./?/init.moon.lua;./?.lua;./?/init.lua' -- relative imports relative = (...) -> diff --git a/dist b/dist -Subproject 0f5bd1012edd93fce8e4ac737ac01c9ec02f5db +Subproject 19c3c05a3427978d76af70c4656ba082f20af25 diff --git a/lib/html.client.moon b/lib/html.client.moon index 2538f8d..45794da 100644 --- a/lib/html.client.moon +++ b/lib/html.client.moon @@ -1,5 +1,3 @@ -document = js.global.document - element = (element) -> (...) -> children = { ... } @@ -12,7 +10,8 @@ element = (element) -> (...) -> with e = document\createElement element for k,v in pairs attributes - e[k] = v + if 'string' == type k + e[k] = v -- if there is only one argument, -- children can be in attributes table too diff --git a/lib/html.server.moon b/lib/html.server.moon index bbeaa9d..cc68fc7 100644 --- a/lib/html.server.moon +++ b/lib/html.server.moon @@ -10,6 +10,7 @@ element = (element) -> (...) -> b = "<#{element}" for k,v in pairs attributes + continue unless 'string' == type k if 'table' == type v tmp = '' for kk, vv in pairs v diff --git a/render.moon b/render.moon index 79844e1..f56e8b8 100644 --- a/render.moon +++ b/render.moon @@ -13,6 +13,7 @@ load_file = (name) -> print "<!DOCTYPE html> <html> <head> + <meta charset=\"UTF-8\"> <title>MMM: lunar low-gravity scripting playground</title> </head> <body> diff --git a/server.moon b/server.moon index d2bb683..add40ef 100644 --- a/server.moon +++ b/server.moon @@ -26,11 +26,12 @@ import compile, insert_loader from require 'duct_tape' insert_loader! on_client = (fn, ...) -> + args = {...} -- warn code append "<script type=\"application/lua\"> MODE = 'HYBRID' local fn = #{compile fn} - fn(#{table.concat { ... }, ', '}) + fn(#{table.concat [string.format '%q', v for v in *args ], ', '}) </script>" { diff --git a/tup.config b/tup.config new file mode 100644 index 0000000..4cae19b --- /dev/null +++ b/tup.config @@ -0,0 +1 @@ +CONFIG_FENGARI_VERSION=v0.1.2 |
