aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-10-26 16:02:10 +0000
committers-ol <s-ol@users.noreply.github.com>2018-10-26 16:02:10 +0000
commitae05d51dc1ab9fdd7a03a62443d5341182a03725 (patch)
tree19ec3bbcf8988861b7e7c13eb5baa36f80001294
parentremove submodule (diff)
downloadmmm-ae05d51dc1ab9fdd7a03a62443d5341182a03725.tar.gz
mmm-ae05d51dc1ab9fdd7a03a62443d5341182a03725.zip
like, lots of new stuff 4 tablefs
-rw-r--r--app/tablefs/init.moon136
-rw-r--r--app/tablefs/tablefs.moon35
-rw-r--r--render.moon5
-rw-r--r--tup.moon2
4 files changed, 159 insertions, 19 deletions
diff --git a/app/tablefs/init.moon b/app/tablefs/init.moon
index 5a9a4fd..7eddc7c 100644
--- a/app/tablefs/init.moon
+++ b/app/tablefs/init.moon
@@ -1,4 +1,138 @@
+export ^
+
+interps = {
+ {
+ name: 'moon',
+ transform: (method) => method @
+ },
+ {
+ name: 'http',
+ transform: (...) -> ... -- @TODO
+ },
+}
+
+split = (str, delim='->') ->
+ return {}, str if nil == str\find delim
+
+ -- @TODO interp chain?
+ interp, rest = str\match ' *(%w+) *-> *(.*)'
+ { interp }, rest
+
+class Key
+ new: (opts) =>
+ if 'string' == type opts
+ @name, rest = opts\match '(%w+): *(.+)'
+ if not @name
+ @name = ''
+ rest = opts
+ @interps, @type = split rest, '->'
+ elseif 'table' == type opts
+ @name = opts.name
+ @type = assert opts.type, 'no type given'
+ @interps = opts.interps or {}
+ else
+ error 'wrong argument type'
+
+ -- get a function that interpretes thi type according to @interps
+ get_interp: (overrides) =>
+ return ((val) => val) if #@interps == 0
+
+ assert #@interps == 1, 'not supported rn' -- @TODO
+ _name = @interps[1]
+
+ return overrides[_name] if overrides and overrides[_name]
+
+ for { :name, :transform } in *interps
+ if name == _name
+ return transform
+
+ error "interp not found: '#{_name}'"
+
+transforms = {
+ {
+ inp: 'mmm/dom',
+ out: 'text/html',
+ transform: (node) -> if MODE == 'SERVER' then node else node.outerHTML
+ },
+ {
+ inp: 'mmm/component',
+ out: 'mmm/dom',
+ transform: (...) ->
+ import tohtml from require 'lib.component'
+ tohtml ...
+ },
+ {
+ -- @TODO this chained rule *should* be inferred, but that's way too hot rn
+ inp: 'mmm/component',
+ out: 'text/html',
+ transform: (node) ->
+ import tohtml from require 'lib.component'
+
+ node = tohtml node
+ if MODE == 'SERVER' then node else node.outerHTML
+ },
+}
+
+if MODE == 'SERVER'
+ table.insert transforms, {
+ inp: 'text/html',
+ out: 'mmm/dom',
+ transform: (...) -> ...
+ }
+
+do
+ success, discount = pcall require, 'discount'
+ if success
+ table.insert transforms, {
+ inp: 'text/markdown',
+ out: 'text/html',
+ transform: discount,
+ }
+
+ if MODE == 'SERVER'
+ -- @TODO chained w above
+ table.insert transforms, {
+ inp: 'text/markdown',
+ out: 'mmm/dom',
+ transform: discount,
+ }
+
+class Fileder
+ new: (props, @children) =>
+ if not @children
+ @children = for i, child in ipairs props
+ props[i] = nil
+ child
+
+ @props = { (Key k), v for k, v in pairs props }
+
+ gett: (...) => assert @get ...
+ get: (name='', type, overrides) =>
+ if not type
+ type = name
+ name = ''
+
+ -- first pass, interps only
+ for key, value in pairs @props
+ continue unless key.name == name and key.type == type
+
+ interp = key\get_interp overrides
+
+ return interp @, value
+
+ if not overrides
+ -- second pass, interps + transforms
+ for key, value in pairs @props
+ continue unless key.name == name
+
+ interp = key\get_interp!
+
+ for { :inp, :out, :transform } in *transforms
+ return transform interp @, value if inp == key.type and out == type
+
+ nil, "node doesn't have value for #{name}:#{type}"
+
require = relative ...
root = require '.tablefs'
-append root['moon -> text/html'] root
+append root\gett 'mmm/dom'
diff --git a/app/tablefs/tablefs.moon b/app/tablefs/tablefs.moon
index 08e3084..2dfe033 100644
--- a/app/tablefs/tablefs.moon
+++ b/app/tablefs/tablefs.moon
@@ -1,5 +1,5 @@
-{
- 'moon -> text/html': () =>
+Fileder {
+ 'moon -> mmm/dom': () =>
import article, h1, h3, p, div, a, sup, ol, li, span, code, br from require 'lib.html'
content = {}
@@ -57,13 +57,12 @@
if child[key]
child[key] child
-
title = (text) -> h3 text, style: { margin: 0 }
- append div for child in *@
+ append div for child in *@children
div {
- title child['title: text/plain'],
- mb_render child, 'preview: moon -> text/html',
+ title child\gett 'title', 'text/plain',
+ (child\get 'preview', 'mmm/dom') or span '(no renderable content)', style: { color: 'red' }
style: {
display: 'inline-block',
width: '300px',
@@ -79,21 +78,27 @@
article content
- 'text/markdown': "this is a markdown version or something. I don't really know how this would work, how do you share stuff and shit?"
+ 'text/markdown': "this is a markdown version or something.
+
+There's no content here so switch back to the real one!
+(Assuming there is a switching UI by the time you are reading this, which I am presupposing since you are reading this at all.
+If you are reading this in the source, then c'mon, just scroll past and give me a break.)"
- {
+ Fileder {
'title: text/plain': "Hey I'm an ad-hoc child with no content for shit",
}
- {
+ Fileder {
'title: text/plain': "Hey I'm like a link to picture or smth",
- 'http -> png': 'https://picsum.photos/200?random',
- 'preview: moon -> text/html': =>
+ 'http -> image/png': 'https://picsum.photos/200?random',
+ 'preview: moon -> mmm/dom': =>
import img from require 'lib.html'
- img src: @['http -> png']
+ img src: @gett nil, -- look for: main content
+ 'image/png', -- w/ image type, and
+ http: (...) => ... -- override http interp to get URL
}
- {
+ Fileder {
'title: text/plain': "I'm not even five lines of markdown but i render myself!",
'text/markdown': "See I have like
@@ -101,8 +106,6 @@
- (two things)
and some bold **text** and `code tags` with me.",
- 'preview: moon -> text/html': =>
- compile = require 'discount'
- compile @['text/markdown']
+ 'preview: moon -> text/markdown': => @get 'text/markdown' -- redirect to main content of same type, if exists
}
}
diff --git a/render.moon b/render.moon
index 218e934..54afe9e 100644
--- a/render.moon
+++ b/render.moon
@@ -4,10 +4,12 @@ import flush from require 'lib.init'
import indexed from require 'app'
route_name = assert arg[1], "please specify the route name to build as an argument"
+output_name = assert arg[2], "please specify the output filename as an argument"
route = assert indexed[route_name], "route not found: '#{route_name}'"
route\render!
-print "<!DOCTYPE html>
+with io.open output_name, 'w'
+ \write "<!DOCTYPE html>
<html>
<head>
<meta charset=\"UTF-8\">
@@ -20,3 +22,4 @@ print "<!DOCTYPE html>
#{flush!}
</body>
</html>"
+ \close!
diff --git a/tup.moon b/tup.moon
index a5d47bb..29777ef 100644
--- a/tup.moon
+++ b/tup.moon
@@ -3,4 +3,4 @@ require 'lib.init'
import routes from require 'app'
for { :name, :dest } in *routes
- print ": |> ^ HTML #{name}^ moon render.moon #{name} > %o |> dist/#{dest}"
+ print ": |> ^ HTML #{name}^ moon render.moon #{name} %o |> dist/#{dest}"