From 2e454714a19c044577b6c24e06f86cf43226fe6a Mon Sep 17 00:00:00 2001 From: s-ol Date: Wed, 9 Dec 2020 12:16:29 +0100 Subject: remove legacy PLUGINS --- build/render_all.moon | 8 +- build/server.moon | 14 +- mmm/mmmfs/browser.moon | 3 +- mmm/mmmfs/builtins.moon | 353 +++++++++++++++++++++ mmm/mmmfs/conversion.moon | 4 +- mmm/mmmfs/init.moon | 2 - mmm/mmmfs/layout.moon | 3 +- mmm/mmmfs/plugins/code.moon | 86 ----- mmm/mmmfs/plugins/gltf.moon | 6 - mmm/mmmfs/plugins/init.moon | 337 -------------------- mmm/mmmfs/plugins/markdown.moon | 5 - mmm/mmmfs/plugins/mermaid.moon | 5 - .../json/converts: text$moonscript -> table.moon | 54 ---- .../static/converts: text$moonscript -> table.moon | 59 ++-- 14 files changed, 403 insertions(+), 536 deletions(-) create mode 100644 mmm/mmmfs/builtins.moon delete mode 100644 mmm/mmmfs/init.moon delete mode 100644 mmm/mmmfs/plugins/code.moon delete mode 100644 mmm/mmmfs/plugins/gltf.moon delete mode 100644 mmm/mmmfs/plugins/init.moon delete mode 100644 mmm/mmmfs/plugins/markdown.moon delete mode 100644 mmm/mmmfs/plugins/mermaid.moon delete mode 100644 root/$mmm/plugins/json/converts: text$moonscript -> table.moon diff --git a/build/render_all.moon b/build/render_all.moon index 5455446..0e2aa78 100644 --- a/build/render_all.moon +++ b/build/render_all.moon @@ -11,10 +11,6 @@ add '?/init.server' -- moon render_all.moon [STORE] [output] [URL-prefix] { store, output, prefix } = arg -require 'mmm' -import Fileder, dir_base from require 'mmm.mmmfs.fileder' -import get_store from require 'mmm.mmmfs.stores' - export UNSAFE, STATIC UNSAFE = true @@ -29,7 +25,9 @@ STATIC = { root: prefix } -require 'mmm.mmmfs' +require 'mmm' +import Fileder, dir_base from require 'mmm.mmmfs.fileder' +import get_store from require 'mmm.mmmfs.stores' store = get_store store root = Fileder store diff --git a/build/server.moon b/build/server.moon index 5d6864a..d14b0b4 100644 --- a/build/server.moon +++ b/build/server.moon @@ -9,6 +9,9 @@ add '?/init.server' require 'mmm' +export UNSAFE +UNSAFE = true + import dir_base, Key, Fileder from require 'mmm.mmmfs.fileder' import convert, MermaidDebugger from require 'mmm.mmmfs.conversion' import get_store from require 'mmm.mmmfs.stores' @@ -38,9 +41,8 @@ class Server if @flags.unsafe == nil @flags.unsafe = not @flags.rw or opts.host == 'localhost' or opts.host == '127.0.0.1' - export UNSAFE + -- @TODO: fix UNSAFE! UNSAFE = @flags.unsafe - require 'mmm.mmmfs' listen: => assert @server\listen! @@ -56,13 +58,12 @@ class Server root = Fileder @store browser = Browser root, fileder.path, facet.name - render browser\todom!, fileder, noview: true, scripts: PLUGINS.scripts .. " + render browser\todom!, fileder, noview: true, scripts: " - - - - ]] -} diff --git a/mmm/mmmfs/plugins/gltf.moon b/mmm/mmmfs/plugins/gltf.moon deleted file mode 100644 index 129a291..0000000 --- a/mmm/mmmfs/plugins/gltf.moon +++ /dev/null @@ -1,6 +0,0 @@ -{ - scripts: [[ - - - ]] -} diff --git a/mmm/mmmfs/plugins/init.moon b/mmm/mmmfs/plugins/init.moon deleted file mode 100644 index 57acbfe..0000000 --- a/mmm/mmmfs/plugins/init.moon +++ /dev/null @@ -1,337 +0,0 @@ -import div, pre, code, img, video, span, source from require 'mmm.dom' -import find_fileder, link_to, embed from (require 'mmm.mmmfs.util') require 'mmm.dom' -import render from require 'mmm.mmmfs.layout' -import tohtml from require 'mmm.component' - --- fix JS null values -js_fix = if MODE == 'CLIENT' - (arg) -> - return if arg == js.null - return if arg == '' - arg - --- fix JS bool values -js_bool = if MODE == 'CLIENT' - (arg) -> - return nil if arg == js.null - return false if arg == 'false' - true - --- limit function to one argument -single = (func) -> (val) => func val - --- load a chunk using a specific 'load'er -loadwith = (_load) -> (val, fileder, key) => - func = assert _load val, "#{fileder}##{key}" - func! - -string.yieldable_gsub = (str, pat, f) -> - -- escape percent signs - str = str\gsub '%%', '%%|' - - matches = {} - str, cnt = str\gsub pat, (...) -> - table.insert matches, { ... } - "%#{#matches}" - - for match in *matches - match.replacement = f table.unpack match - - str = str\gsub '%%(%d+)', (i) -> - i = tonumber i - matches[i].replacement - - -- unescape escaped percent signs - str = str\gsub '%%|', '%%' - str, cnt - --- list of converts, editors, scripts --- converts each have --- * inp - input type. can capture subtypes using `(.+)` --- * out - output type. can substitute subtypes from inp with %1, %2 etc. --- * cost - conversion cost --- * transform - function (val: inp, fileder) => val: out --- @convert, @from, @to contain the convert and the concrete types -editors = {} -scripts = '' -converts = { - { - inp: 'fn -> (.+)', - out: '%1', - cost: 1 - transform: (val, fileder) => val fileder - } - { - inp: 'mmm/component', - out: 'mmm/dom', - cost: 3 - transform: single tohtml - } - { - inp: 'mmm/dom', - out: 'text/html+frag', - cost: 3 - transform: (node) => if MODE == 'SERVER' then node else node.outerHTML - } - { - -- inp: 'text/html%+frag', - -- @TODO: this doesn't feel right... maybe mmm/dom has to go? - inp: 'mmm/dom', - out: 'text/html', - cost: 3 - transform: (html, fileder) => render html, fileder - } - { - inp: 'text/html%+frag', - out: 'mmm/dom', - cost: 0.1 - transform: if MODE == 'SERVER' - (html, fileder) => - html = html\yieldable_gsub '(.-)', (attrs, text) -> - text = nil if #text == 0 - path = '' - while attrs and attrs != '' - key, val, _attrs = attrs\match '^(%w+)="([^"]-)"%s*(.*)' - if not key - key, _attrs = attrs\match '^(%w+)%s*(.*)$' - val = true - - attrs = _attrs - - switch key - when 'path' then path = val - else warn "unkown attribute '#{key}=\"#{val}\"' in " - - link_to path, text, fileder - - html = html\yieldable_gsub '(.-)', (attrs, desc) -> - path, facet = '', '' - opts = {} - if #desc != 0 - opts.desc = desc - - while attrs and attrs != '' - key, val, _attrs = attrs\match '^(%w+)="([^"]-)"%s*(.*)' - if not key - key, _attrs = attrs\match '^(%w+)%s*(.*)$' - val = true - - attrs = _attrs - - switch key - when 'path' then path = val - when 'facet' then facet = val - when 'wrap' then opts.wrap = val - when 'style' then opts.style = val - when 'nolink' then opts.nolink = true - when 'inline' then opts.inline = true - - when 'raw' then opts.raw = true -- deprecated - - else warn "unkown attribute '#{key}=\"#{val}\"' in " - - embed path, facet, fileder, opts - - html - else - (html, fileder) => - parent = with document\createElement 'div' - .innerHTML = html - - -- copy to iterate safely, HTMLCollections update when nodes are GC'ed - embeds = \getElementsByTagName 'mmm-embed' - embeds = [embeds[i] for i=0, embeds.length - 1] - for element in *embeds - path = js_fix element\getAttribute 'path' - facet = js_fix element\getAttribute 'facet' - wrap = js_fix element\getAttribute 'wrap' - style = js_fix element\getAttribute 'style' - nolink = js_bool element\getAttribute 'nolink' - inline = js_bool element\getAttribute 'inline' - desc = js_fix element.innerText - desc = nil if desc == '' - - raw = js_bool element\getAttribute 'raw' -- deprecated - - opts = :wrap, :style, :nolink, :inline, :desc, :raw - element\replaceWith embed path or '', facet or '', fileder, opts - - embeds = \getElementsByTagName 'mmm-link' - embeds = [embeds[i] for i=0, embeds.length - 1] - for element in *embeds - text = js_fix element.innerText - path = js_fix element\getAttribute 'path' - - element\replaceWith link_to path or '', text, fileder - - assert 1 == parent.childElementCount, "text/html with more than one child!" - parent.firstElementChild - } - { - inp: 'mmm/tpl -> (.+)', - out: '%1', - cost: 1 - transform: (source, fileder) => - source\yieldable_gsub '{{(.-)}}', (expr) -> - path, facet = expr\match '^([%w%-_%./]*)%+(.*)' - assert path, "couldn't match TPL expression '#{expr}'" - - (find_fileder path, fileder)\gett facet - } - { - inp: 'time/iso8601-date', - out: 'time/unix', - cost: 0.5 - transform: (val) => - year, _, month, day = val\match '^%s*(%d%d%d%d)(%-?)([01]%d)%2([0-3]%d)%s*$' - assert year, "failed to parse ISO 8601 date: '#{val}'" - os.time :year, :month, :day - } - { - inp: 'URL -> image/.+', - out: 'mmm/dom', - cost: -4 - transform: (src, fileder) => img :src - } - { - inp: 'URL -> video/.+%+gif', - out: 'mmm/dom', - cost: -4.01 - transform: (src) => - video (source :src), controls: 'auto', loop: true, autoplay: true, muted: true - } - { - inp: 'URL -> video/.+', - out: 'mmm/dom', - cost: -4 - transform: (src) => - -- @TODO: add parsed MIME type - video (source :src), controls: true, loop: true - } - { - inp: 'text/plain', - out: 'mmm/dom', - cost: 2 - transform: (val) => span val - } - { - inp: 'alpha', - out: 'mmm/dom', - cost: 2 - transform: single code - } - { - inp: 'URL -> (.+)', - out: '%1', - cost: 4, - transform: do - if MODE == 'CLIENT' - (uri) => - request = js.new js.global.XMLHttpRequest - request\open 'GET', uri, false - request\send js.null - - assert request.status == 200, "unexpected status code: #{request.status}" - request.responseText - else - (uri) => - request = require 'http.request' - req = request.new_from_uri uri - req.headers\upsert 'origin', 'null' - headers, stream = assert req\go 8 - assert stream\get_body_as_string! - } - { - inp: 'table', - out: 'mmm/dom', - cost: 5 - transform: do - deep_tostring = (tbl, space='') -> - buf = space .. tostring tbl - - return buf unless 'table' == type tbl - - buf = buf .. ' {\n' - for k,v in pairs tbl - buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' '}\n" - buf = buf .. "#{space}}" - buf - - (tbl) => pre code deep_tostring tbl - } -} - -if MODE == 'CLIENT' or UNSAFE - table.insert converts, { - inp: 'text/lua -> (.+)', - out: '%1', - cost: 0.5 - transform: loadwith load or loadstring - } - -add_plugin = (module) -> - ok, plugin = pcall require, "mmm.mmmfs.plugins.#{module}" - - if not ok - print "[Plugins] couldn't load plugins.#{module}: #{plugin}" - return - - print "[Plugins] loaded plugins.#{module}" - - if plugin.converts - for convert in *plugin.converts - table.insert converts, convert - - if plugin.editors - for editor in *plugin.editors - table.insert editors, editor - - if plugin.scripts - scripts ..= plugin.scripts - -add_plugin 'code' -add_plugin 'markdown' -add_plugin 'mermaid' -add_plugin 'gltf' - -if not STATIC - table.insert converts, { - inp: '(.+)', - out: 'URL -> %1', - cost: 5 - transform: (_, fileder, key) => "#{fileder.path}/#{key.name}:#{@from}" - } - -if MODE == 'SERVER' - ok, moon = pcall require, 'moonscript.base' - if ok - _load = moon.load or moon.loadstring - if UNSAFE - table.insert converts, { - inp: 'text/moonscript -> (.+)', - out: '%1', - cost: 1 - transform: loadwith moon.load or moon.loadstring - } - - table.insert converts, { - inp: 'text/moonscript -> (.+)', - out: 'text/lua -> %1', - cost: 2 - transform: single moon.to_lua - } -else - table.insert converts, { - inp: 'text/javascript -> (.+)', - out: '%1', - cost: 1 - transform: (source) => - f = js.new window.Function, source - f! - } - -{ - :converts - :editors - :scripts -} diff --git a/mmm/mmmfs/plugins/markdown.moon b/mmm/mmmfs/plugins/markdown.moon deleted file mode 100644 index c5a8f96..0000000 --- a/mmm/mmmfs/plugins/markdown.moon +++ /dev/null @@ -1,5 +0,0 @@ -{ - scripts: [[ - - ]] -} diff --git a/mmm/mmmfs/plugins/mermaid.moon b/mmm/mmmfs/plugins/mermaid.moon deleted file mode 100644 index c076e7b..0000000 --- a/mmm/mmmfs/plugins/mermaid.moon +++ /dev/null @@ -1,5 +0,0 @@ -{ - scripts: [[ - - ]] -} diff --git a/root/$mmm/plugins/json/converts: text$moonscript -> table.moon b/root/$mmm/plugins/json/converts: text$moonscript -> table.moon deleted file mode 100644 index 7b150a5..0000000 --- a/root/$mmm/plugins/json/converts: text$moonscript -> table.moon +++ /dev/null @@ -1,54 +0,0 @@ -encode = (obj) -> - switch type obj - when 'string' - string.format '%q', obj - when 'table' - if obj[1] or not next obj - "[#{table.concat [encode c for c in *obj], ','}]" - else - "{#{table.concat ["#{encode k}: #{encode v}" for k,v in pairs obj], ', '}}" - when 'number' - tostring obj - when 'boolean' - tostring obj - when 'nil' - 'null' - else - error "unknown type '#{type obj}'" - -decode = if MODE == 'CLIENT' - import Array, Object, JSON from js.global - - fix = (val) -> - switch type val - when 'userdata' - if Array\isArray val - [fix x for x in js.of val] - else - {(fix e[0]), (fix e[1]) for e in js.of Object\entries(val)} - else - val - - encode - decode = (str) -> fix JSON\parse str -else if cjson = require 'cjson' - cjson.decode -else - warn 'only partial JSON support, please install cjson' - - -{ - { - inp: 'table', - out: 'text/json', - cost: 2 - transform: (val) => encode val - } - if decode - { - inp: 'text/json' - out: 'table' - cost: 1 - transform: (val) => decode val - } -} diff --git a/root/$mmm/plugins/static/converts: text$moonscript -> table.moon b/root/$mmm/plugins/static/converts: text$moonscript -> table.moon index e230856..b3c6182 100644 --- a/root/$mmm/plugins/static/converts: text$moonscript -> table.moon +++ b/root/$mmm/plugins/static/converts: text$moonscript -> table.moon @@ -1,34 +1,41 @@ -if not STATIC - return +if STATIC + extensions = { + 'image/jpeg': 'jpg' + 'image/png': 'png' + 'image/svg+xml': 'svg' -extensions = { - 'image/jpeg': 'jpg' - 'image/png': 'png' - 'image/svg+xml': 'svg' + 'video/webm': 'webm' + 'video/mp4': 'mp4' - 'video/webm': 'webm' - 'video/mp4': 'mp4' + 'text/javascript': 'js' + 'text/css': 'css' - 'text/javascript': 'js' - 'text/css': 'css' - - 'model/gltf-binary': 'glb' -} + 'model/gltf-binary': 'glb' + } -{ { - inp: '(.+)', - out: 'URL -> %1', - cost: 5 - transform: (val, fileder, key) => - escaped_from = @from\gsub '/', '_' - if ext = extensions[@from] - escaped_from ..= ".#{ext}" + { + inp: '(.+)', + out: 'URL -> %1', + cost: 5 + transform: (val, fileder, key) => + escaped_from = @from\gsub '/', '_' + if ext = extensions[@from] + escaped_from ..= ".#{ext}" - prefix = STATIC.root or '' + prefix = STATIC.root or '' - prefix .. with url = "#{fileder.path}/#{key.name}:#{escaped_from}" - print " rendering asset #{url}" - STATIC.spit url, val + prefix .. with url = "#{fileder.path}/#{key.name}:#{escaped_from}" + print " rendering asset #{url}" + STATIC.spit url, val + } + } +else + { + { + inp: '(.+)', + out: 'URL -> %1', + cost: 5 + transform: (_, fileder, key) => "#{fileder.path}/#{key.name}:#{@from}" + } } -} -- cgit v1.2.3