diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/index.moon | 70 | ||||
| -rw-r--r-- | app/tags/init.moon | 146 |
2 files changed, 108 insertions, 108 deletions
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 '' +), ... |
