From e5491bc7fbd867812500c845db99b55b35db0666 Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 29 Oct 2018 19:37:40 +1100 Subject: rename lib.html to lib.dom --- app/center_of_mass.moon | 2 +- app/init.moon | 2 +- app/mmmfs/conversion.moon | 2 +- app/mmmfs/tree/gallery.moon | 2 +- app/mmmfs/tree/init.moon | 6 +++--- app/test_component.moon | 2 +- lib/canvasapp.client.moon | 2 +- lib/component.client.moon | 1 - lib/dom.client.moon | 32 ++++++++++++++++++++++++++++++++ lib/dom.server.moon | 33 +++++++++++++++++++++++++++++++++ lib/html.client.moon | 32 -------------------------------- lib/html.server.moon | 33 --------------------------------- 12 files changed, 74 insertions(+), 75 deletions(-) create mode 100644 lib/dom.client.moon create mode 100644 lib/dom.server.moon delete mode 100644 lib/html.client.moon delete mode 100644 lib/html.server.moon diff --git a/app/center_of_mass.moon b/app/center_of_mass.moon index 845dd97..ecfee2a 100644 --- a/app/center_of_mass.moon +++ b/app/center_of_mass.moon @@ -1,7 +1,7 @@ on_client -> import CanvasApp from require 'lib.canvasapp' import rgb from require 'lib.color' - import h1, p, div, span, input, button from require 'lib.html' + import h1, p, div, span, input, button from require 'lib.dom' fast = true center = true diff --git a/app/init.moon b/app/init.moon index 5d5f18a..5e38966 100644 --- a/app/init.moon +++ b/app/init.moon @@ -84,7 +84,7 @@ index = { route: '' dest: 'index.html' render: => - import h1, h3, div, b, p, a, br, ul, tt, li, img from require 'lib.html' + import h1, h3, div, b, p, a, br, ul, tt, li, img from require 'lib.dom' import opairs from require 'lib.ordered' moon = '\xe2\x98\xbd' diff --git a/app/mmmfs/conversion.moon b/app/mmmfs/conversion.moon index a670e2e..b204ff8 100644 --- a/app/mmmfs/conversion.moon +++ b/app/mmmfs/conversion.moon @@ -1,4 +1,4 @@ -import text, code from require 'lib.html' +import text, code from require 'lib.dom' import tohtml from require 'lib.component' -- limit function to one argument diff --git a/app/mmmfs/tree/gallery.moon b/app/mmmfs/tree/gallery.moon index 93ca58d..86478d3 100644 --- a/app/mmmfs/tree/gallery.moon +++ b/app/mmmfs/tree/gallery.moon @@ -1,4 +1,4 @@ -import div, h1, a, img, br from require 'lib.html' +import div, h1, a, img, br from require 'lib.dom' children = for i=1,100 id = math.floor math.random! * 200 diff --git a/app/mmmfs/tree/init.moon b/app/mmmfs/tree/init.moon index 1d6a116..d30afc9 100644 --- a/app/mmmfs/tree/init.moon +++ b/app/mmmfs/tree/init.moon @@ -6,7 +6,7 @@ Fileder { -- uses the 'moon' interp to execute the lua/moonscript function on get -- resolves to a value of type mmm/dom 'moon -> mmm/dom': () => - html = require 'lib.html' + html = require 'lib.dom' import article, h1, h2, h3, p, div, a, sup, ol, li, span, code, pre, br from html code = do @@ -192,7 +192,7 @@ Fileder { 'title: text/plain': "Hey I'm like a link to picture or smth", 'URL -> image/png': 'https://picsum.photos/200?random', 'preview: moon -> mmm/dom': => - import img from require 'lib.html' + import img from require 'lib.dom' img src: @gett nil, -- look for: main content 'image/png', -- with image type, and URL: (url) => url -- override URL interp to get raw URL @@ -223,7 +223,7 @@ If you are reading this in the source, then c'mon, just scroll past and give me -- preview is a lua/moonscript function that neturns an mmm/dom value 'preview: moon -> mmm/dom': => - import img from require 'lib.html' + import img from require 'lib.dom' img src: @gett nil, 'URL -> image/png' -- look for main content with 'URL to png' type } diff --git a/app/test_component.moon b/app/test_component.moon index 9e3a0ed..d3f1489 100644 --- a/app/test_component.moon +++ b/app/test_component.moon @@ -1,5 +1,5 @@ on_client -> - import div, h1, ul, li, pre from require 'lib.html' + import div, h1, ul, li, pre from require 'lib.dom' last = nil test_group = (name) -> diff --git a/lib/canvasapp.client.moon b/lib/canvasapp.client.moon index 38cc307..71ffa59 100644 --- a/lib/canvasapp.client.moon +++ b/lib/canvasapp.client.moon @@ -1,7 +1,7 @@ window = js.global js = require 'js' -import a, canvas, div, button, script from require 'lib.html' +import a, canvas, div, button, script from require 'lib.dom' class CanvasApp width: 500 diff --git a/lib/component.client.moon b/lib/component.client.moon index af0b38a..617deb5 100644 --- a/lib/component.client.moon +++ b/lib/component.client.moon @@ -102,7 +102,6 @@ class ReactiveElement @node.style[k] = v return - print "setting attr #{attr}" @node[attr] = value append: (child, last) => diff --git a/lib/dom.client.moon b/lib/dom.client.moon new file mode 100644 index 0000000..b8f2bd5 --- /dev/null +++ b/lib/dom.client.moon @@ -0,0 +1,32 @@ +element = (element) -> (...) -> + children = { ... } + + -- attributes are last arguments but mustn't be a ReactiveVar + attributes = children[#children] + if 'table' == (type attributes) and not attributes.node + table.remove children + else + attributes = {} + + with e = document\createElement element + for k,v in pairs attributes + if k == 'style' and 'table' == type v + for kk,vv in pairs v + e.style[kk] = vv + elseif 'string' == type k + e[k] = v + + -- if there is only one argument, + -- children can be in attributes table too + if #children == 0 + children = attributes + + for child in *children + if 'string' == type child + e.innerHTML ..= child + else + e\appendChild child + +setmetatable {}, __index: (name) => + with val = element name + @[name] = val diff --git a/lib/dom.server.moon b/lib/dom.server.moon new file mode 100644 index 0000000..3a7b537 --- /dev/null +++ b/lib/dom.server.moon @@ -0,0 +1,33 @@ +import opairs from require 'lib.ordered' + +element = (element) -> (...) -> + children = { ... } + + -- attributes are last arguments but mustn't be a ReactiveVar + attributes = children[#children] + if 'table' == (type attributes) and not attributes.node + table.remove children + else + attributes = {} + + b = "<#{element}" + for k,v in opairs attributes + if k == 'style' and 'table' == type v + tmp = '' + for kk, vv in opairs v + tmp ..= "#{kk}: #{vv}; " + v = tmp + b ..= " #{k}=\"#{v}\"" + + -- if there is only one argument, + -- children can be in attributes table too + if #children == 0 + children = attributes + + b ..= ">" .. table.concat children, '' + b ..= "" + b + +setmetatable {}, __index: (name) => + with val = element name + @[name] = val diff --git a/lib/html.client.moon b/lib/html.client.moon deleted file mode 100644 index b8f2bd5..0000000 --- a/lib/html.client.moon +++ /dev/null @@ -1,32 +0,0 @@ -element = (element) -> (...) -> - children = { ... } - - -- attributes are last arguments but mustn't be a ReactiveVar - attributes = children[#children] - if 'table' == (type attributes) and not attributes.node - table.remove children - else - attributes = {} - - with e = document\createElement element - for k,v in pairs attributes - if k == 'style' and 'table' == type v - for kk,vv in pairs v - e.style[kk] = vv - elseif 'string' == type k - e[k] = v - - -- if there is only one argument, - -- children can be in attributes table too - if #children == 0 - children = attributes - - for child in *children - if 'string' == type child - e.innerHTML ..= child - else - e\appendChild child - -setmetatable {}, __index: (name) => - with val = element name - @[name] = val diff --git a/lib/html.server.moon b/lib/html.server.moon deleted file mode 100644 index 3a7b537..0000000 --- a/lib/html.server.moon +++ /dev/null @@ -1,33 +0,0 @@ -import opairs from require 'lib.ordered' - -element = (element) -> (...) -> - children = { ... } - - -- attributes are last arguments but mustn't be a ReactiveVar - attributes = children[#children] - if 'table' == (type attributes) and not attributes.node - table.remove children - else - attributes = {} - - b = "<#{element}" - for k,v in opairs attributes - if k == 'style' and 'table' == type v - tmp = '' - for kk, vv in opairs v - tmp ..= "#{kk}: #{vv}; " - v = tmp - b ..= " #{k}=\"#{v}\"" - - -- if there is only one argument, - -- children can be in attributes table too - if #children == 0 - children = attributes - - b ..= ">" .. table.concat children, '' - b ..= "" - b - -setmetatable {}, __index: (name) => - with val = element name - @[name] = val -- cgit v1.2.3