~technomancy/fennel-lang.org

ref: 3bed58d0007ac8f9616486ef20094cffc2c10562 fennel-lang.org/survey/survey.fnl -rw-r--r-- 2.5 KiB
3bed58d0Phil Hagelberg Improve accessibility of SVG by adding <desc> element. 19 days ago
                                                                                
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
(local html (require :html))
(local questions (require :questions))
(local year 2021)

(fn prepend [tbl pre]
  (while (. pre 1)
    (table.insert tbl 1 (table.remove pre))))

(fn section-html [{: question}]
  [:h2 {} question])

(fn checkbox-html [{: question : answers} i]
  [:div {:class :checks}
   [:p {} question]
   (doto (icollect [ia answer (ipairs answers)]
           (let [id (.. i "-" ia)]
             [:li {:class :answer}
              (if (= "Other" answer)
                  [:input {:type :text :name (.. id "-other")
                           :placeholder "Other"}]
                  [:input {:type :checkbox :value answer :id id :name question}])
              (if (not= "Other" answer)
                  [:label {:for id} answer])]))
     (prepend [:ul {}]))])

(fn textarea-html [{: question} i]
  [:div {}
   [:textarea {:name question :rows 6 :cols 60 :id i}]
   [:p {:style "margin-top: 0em"} [:label {:for i} question]]])

(fn text-html [{: question} i]
  [:div {}
   [:label {:for i} question]
   [:input {:name question :type :text}]])

(fn submit-html [{: question}]
  [:input {:type :submit :value question}])

(local out [:html {:lang "en"}
            [:head {}
             [:meta {:charset "UTF-8"}]
             ;; [:script {:src "/fengari-web.js"}]
             ;; [:script {:type "application/lua" :src "/init.lua" :async true}]
             [:link {:rel "stylesheet" :href "/fennel.css"}]
             [:link {:rel "stylesheet"
                     :href "https://code.cdn.mozilla.net/fonts/fira.css"}]
             [:title {} "the Fennel programming language survey"]]
            [:body {}
             [:h1 {} (.. "The Fennel Survey: " year)]
             [:p {} "Fennel just had its fifth birthday! We don't know much"
              "about how people use it beyond what's discussed in chat, so we"
              "want to hear your thoughts to help make Fennel better for you!"]
             [:p {} "All questions are optional!"]
             (doto (icollect [i q (ipairs questions)]
                     (match q.type
                       :section (section-html q i)
                       :checkbox (checkbox-html q i)
                       :text (text-html q i)
                       :number (text-html q i)
                       :textarea (textarea-html q i)
                       :submit (submit-html q i)))
               (prepend [:form {:action "/survey/save.cgi" :method :post}
                         [:input {:type :hidden :name :year :value year}]]))]])

(print (html out))