aboutsummaryrefslogtreecommitdiffstats
path: root/app/init.moon
blob: e1f7a75ebb7f8cc0589057b11c0ee03fe036f1b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require = relative ...

patch_redirs = ->
  redirs =
    'center-of-mass': 'center_of_mass',
    'test-component': 'test_component',
    'play-tags': 'tags',

  { :location } = window
  if (not location.search\find '=') and #location.search > 1
    name = location.search\sub 2
    location.href = redirs[name] or name

client_goto = ->
  { :location } = window
  if module = location.search\match 'client=([%w_]+)'
    document.body.innerHTML = ''
    require 'app.' .. module

experiments = {
  {
    name: 'twisted'
    desc: 'pseudo 3d animation'
  },
  {
    name: 'koch'
    desc: "lil' fractal thing"
  },
  {
    name: 'realities'
    desc: 'a paper on virtual and other realities'
  },
  {
    name: 'center_of_mass'
    desc: 'aligning characters by their centers of mass'
  },
  {
    name: 'todo'
    desc: 'Todo MVC with the mmm UI framework'
  },
  {
    name: 'test_component'
    desc: 'test suite for the mmm reactive UI framework'
  },
  {
    name: 'tags'
    desc: 'organizing files with Functional Tags'
  },
  {
    name: 'mmmfs'
    desc: 'an operating, file- and living system'
  },
}

routes = [x for x in *experiments]

table.insert routes, {
  name: 'index'
  route: ''
  dest: 'index.html'
  render: =>
    import h1, p, a, br, ul, tt, li from require 'lib.html'
    import opairs from require 'lib.ordered'

    moon = '\xe2\x98\xbd'

    -- redirects for old-style URIs
    on_client patch_redirs

    -- menu
    append h1 'mmm'
    append p {
      tt 'mmm'
      ' is not the '
      tt 'www'
      ', because it runs on '
      a { 'MoonScript', href: 'https://moonscript.org' }
      '.'
      br!
      'You can find the source code of everything '
      a { 'here', href: 'https://github.com/s-ol/mmm' }
      '.'
    }
    append p 'current demos:'
    append ul for { :name, :desc, :route } in *experiments
      li (a name, href: route), ': ', desc

    append p {
      "made with #{moon} by "
      a { 's-ol', href: 'https://twitter.com/S0lll0s' }
    }

    on_client client_goto
}

destify = (route) -> with route
  .route or= .name
  .dest or= "#{.route}/index.html"
  .render or= -> require '.' .. .name

routes = [ destify route for route in *routes ]
{
  :routes,
  indexed: { r.name, r for r in *routes }
  render: (name) -> require ".#{name}"
}