diff options
Diffstat (limited to 'root/$mmm/plugins/code')
| -rw-r--r-- | root/$mmm/plugins/code/converts: text$lua -> table.lua | 121 | ||||
| -rw-r--r-- | root/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua | 12 |
2 files changed, 133 insertions, 0 deletions
diff --git a/root/$mmm/plugins/code/converts: text$lua -> table.lua b/root/$mmm/plugins/code/converts: text$lua -> table.lua new file mode 100644 index 0000000..c578a69 --- /dev/null +++ b/root/$mmm/plugins/code/converts: text$lua -> table.lua @@ -0,0 +1,121 @@ +local pre, div, button +do + local _obj_0 = require('mmm.dom') + pre, div, button = _obj_0.pre, _obj_0.div, _obj_0.button +end +local languages +languages = require('mmm.highlighting').languages +local Editor +do + local _class_0 + local o + local _base_0 = { + EDITOR = true, + change = function(self) + self.timeout = nil + local doc = self.cm:getDoc() + if self.lastPreview and doc:isClean(self.lastPreview) then + return + end + self.lastPreview = doc:changeGeneration() + local value = doc:getValue() + self.fileder.facets[self.key] = value + return BROWSER:refresh() + end, + save = function(self, e) + e:preventDefault() + local doc = self.cm:getDoc() + self.fileder:set(self.key, doc:getValue()) + self.lastSave = doc:changeGeneration(true) + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self, value, mode, fileder, key) + self.fileder, self.key = fileder, key + self.node = div({ + class = 'editor' + }) + do + local _with_0 = button('save') + _with_0.disabled = true + _with_0.onclick = function(_, e) + return self:save(e) + end + self.saveBtn = _with_0 + end + self.cm = window:CodeMirror(self.node, o({ + value = value, + mode = mode, + lineNumber = true, + lineWrapping = true, + autoRefresh = true, + theme = 'hybrid' + })) + self.lastSave = self.cm:getDoc():changeGeneration(true) + return self.cm:on('changes', function(_, mirr) + local doc = self.cm:getDoc() + self.saveBtn.disabled = doc:isClean(self.lastSave) + if self.timeout then + window:clearTimeout(self.timeout) + end + self.timeout = window:setTimeout((function() + return self:change() + end), 300) + end) + end, + __base = _base_0, + __name = "Editor" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({}, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + local self = _class_0 + if MODE == 'CLIENT' then + local mkobj = window:eval("(function () { return {}; })") + o = function(tbl) + do + local obj = mkobj() + for k, v in pairs(tbl) do + obj[k] = v + end + return obj + end + end + end + Editor = _class_0 +end +local _ = [[ editors: if MODE == 'CLIENT' then { + { + inp: 'text/([^ ]*).*' + out: 'mmm/dom' + cost: 0 + transform: (value, fileder, key) => + mode = @from\match @convert.inp + Editor value, mode, fileder, key + } + { + inp: 'URL.*' + out: 'mmm/dom' + cost: 0 + transform: (value, fileder, key) => + Editor value, nil, fileder, key + } + } +]] +return { + { + inp = 'text/([^ ]*).*', + out = 'mmm/dom', + cost = 5, + transform = function(self, val) + local lang = self.from:match(self.convert.inp) + return pre(languages[lang](val)) + end + } +} diff --git a/root/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua b/root/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua new file mode 100644 index 0000000..87a182f --- /dev/null +++ b/root/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua @@ -0,0 +1,12 @@ +local tourl +tourl = (require('mmm.mmmfs.util'))({ }).tourl +return function(self) + return "\n <link rel=\"stylesheet\" type=\"text/css\" href=\"" .. tostring(self:gett('style: URL -> text/css')) .. "\" />" .. [[<!-- + <link rel="stylesheet" type="text/css" href="//unpkg.com/codemirror@5.49.2/lib/codemirror.css" /> + <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/lib/codemirror.js"></script> + <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/mode/lua/lua.js"></script> + <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/mode/markdown/markdown.js"></script> + <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/addon/display/autorefresh.js"></script> +--> + ]] +end |
