~technomancy/fennel-lang.org

fennel-lang.org/survey/survey.fnl -rw-r--r-- 3.1 KiB
25a294adPhil Hagelberg Remove the bit about submitting fennelconf 2021 talks. a day 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
66
67
68
69
70
71
72
73
74
75
76
(local html (require :html))
(local foot (require :foot))
(local questions (require :questions))
(local year 2021)

;; this function is a tacky workaround for the fact that fennel-lang.org is
;; generated using the current stable (at the time of this writing, 0.10.0)
;; version of fennel which does not have the :into clause for
;; icollect. replace it with :into once the next version is released!
(fn prepend [tbl pre]
  (while (. pre 1)
    (table.insert tbl 1 (table.remove pre))))

;; each type of question gets its own HTML representation. section headers are
;; "questions" for the purposes of the data even though they don't have answers.
;; or questions.
(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}
              ;; every checkbox gets an "other" text input
              (if (= "Other" answer)
                  [:input {:type :text :name (.. i "-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}]])

;; again, not a question, but represented as such.
(fn submit-html [{: question}]
  [:input {:type :submit :value question}])

(local out [:html {:lang "en"}
            [:head {}
             [:meta {:charset "UTF-8"}]
             [: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}]]))
             [:hr {}]
             [:p {} "The survey is closed now; thanks for participating!"
              "You can see" [:a {:href "2021"} "the results"] "now."]
             foot]])

(print (html out))