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 /app/tags | |
| parent | fix all pages (diff) | |
| download | mmm-727f04aac784382e7ecb18b817830d145355b735.tar.gz mmm-727f04aac784382e7ecb18b817830d145355b735.zip | |
switch to self-rendering lua code
Diffstat (limited to 'app/tags')
| -rw-r--r-- | app/tags/init.moon | 146 |
1 files changed, 74 insertions, 72 deletions
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 '' +), ... |
