aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnonymized <anonymous@example.com>2018-01-20 01:07:34 +0100
committerAnonymized <anonymous@example.com>2018-01-20 01:07:34 +0100
commitc64725e90096c7902a3978fa83903264feffd2d6 (patch)
tree9ea2473dc0a9402be1185b568a67ca7cedfc5bd7
parent39c8f053beccdbed5f926313d3c95f68997a13da (diff)
downloadgnunet-guile2-c64725e90096c7902a3978fa83903264feffd2d6.tar.gz
gnunet-guile2-c64725e90096c7902a3978fa83903264feffd2d6.zip
c3b2: create topics locally
-rw-r--r--prototypes/c3b2/static/main.css71
-rwxr-xr-xprototypes/c3b2/web.scm64
2 files changed, 95 insertions, 40 deletions
diff --git a/prototypes/c3b2/static/main.css b/prototypes/c3b2/static/main.css
index 8a39fc8..3efd2b4 100644
--- a/prototypes/c3b2/static/main.css
+++ b/prototypes/c3b2/static/main.css
@@ -21,48 +21,47 @@ p {
21} 21}
22 22
23a:link, 23a:link,
24a:visited,
25a:active { 24a:active {
26 color: white; 25 color: rgb(200, 10, 10);
27 text-decoration: none; 26 text-decoration: none;
28} 27}
29 28
30body > div { 29a:visited {
31 background: hsla(0, 0%, 0%, 0.3); 30 color: gray;
32 background: linear-gradient(0deg, hsla(0, 0%, 0%, 0.1) 5px, hsla(0, 0%, 100%, 0.1)); 31 text-decoration: none;
33 border-bottom: 1px solid hsla(0, 0%, 0%, 1);
34 border-radius: 3px;
35 border-right: 1px solid hsla(0, 0%, 0%, 1);
36 box-shadow: -1px -1px 0px hsla(0, 0%, 100%, 0.3), 1px 1px 2px black;
37 display: block;
38 margin: auto;
39 margin-bottom: 15px;
40 max-width: 500px;
41 padding: 15px;
42 text-align: justify;
43} 32}
44 33
45/* #container .repositories a { 34a:hover {
46 display: block; 35 color: pink;
47 padding: 30px; 36}
48 border-bottom: 1px solid hsla(0, 0%, 0%, 0.7);
49 background: linear-gradient(0deg, hsla(0, 0%, 0%, 0.1) 5px, hsla(0, 0%, 100%, 0.1));
50 }
51 37
52 #container .repositories a:last-child { 38body > div, body textarea, body input, body h2 {
53 border-bottom: none; 39 background: hsla(0, 0%, 0%, 0.3);
54 } 40 background: linear-gradient(0deg, hsla(0, 0%, 0%, 0.1) 5px, hsla(0, 0%, 100%, 0.1));
41 border-bottom: 1px solid hsla(0, 0%, 0%, 1);
42 border-radius: 3px;
43 border-right: 1px solid hsla(0, 0%, 0%, 1);
44 box-shadow: -1px -1px 0px hsla(0, 0%, 100%, 0.3), 1px 1px 2px black;
45 display: block;
46 margin: auto;
47 margin-bottom: 15px;
48 max-width: 500px;
49 padding: 15px;
50 text-align: justify;
51 box-sizing: border-box;
52}
55 53
56 #container .repositories a p { 54hr {
57 margin-top: 10px; 55 max-width: 500px;
58 } 56 margin-bottom: 15px;
57}
59 58
60 .branches { 59textarea, input {
61 padding: 15px; 60 width: 500px;
62 background: linear-gradient(0deg, hsla(0, 0%, 0%, 0.1) 5px, hsla(0, 0%, 100%, 0.1)); 61 border: 0px;
63 } 62 color: white;
63}
64 64
65 .branches > ul { 65input {
66 list-style: outside none none; 66 cursor: pointer;
67 padding-left: 10px; 67}
68 } */
diff --git a/prototypes/c3b2/web.scm b/prototypes/c3b2/web.scm
index c7694e6..0f72aa0 100755
--- a/prototypes/c3b2/web.scm
+++ b/prototypes/c3b2/web.scm
@@ -41,25 +41,81 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
41 41
42(setlocale LC_ALL "") 42(setlocale LC_ALL "")
43 43
44;;; helpers
45;;
46;; until we have real messages backend by wt and gnunet
47;;
48
49(define %loremipsum (string-split "Suspendisse potenti. Quisque ac orci sed metus molestie ornare. Nam in neque magna. Proin vel consectetur nisl, a suscipit est. Ut eget lectus maximus, scelerisque felis non, gravida leo. Pellentesque nisi risus, posuere vitae elit eget, efficitur euismod risus. Cras pulvinar, nisl vitae tincidunt hendrerit, dui nulla pellentesque libero, vel maximus erat arcu sed dui. Mauris porta dui nec arcu auctor, quis tristique massa dictum. Etiam consequat leo quis tortor vulputate, vitae eleifend lorem tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque a enim scelerisque, tristique turpis sed, accumsan velit. Proin eleifend, augue sit amet efficitur volutpat, magna ipsum consequat elit, vel tempor est nulla et sem. Cras faucibus odio ac est vestibulum varius. Sed lobortis fringilla egestas. Vestibulum pulvinar est vel mauris malesuada, at dapibus nibh rutrum. Etiam pellentesque lacus nec sapien pharetra, quis ultrices lorem condimentum!" #\space))
50
51(define (choice lst)
52 (list-ref lst (random (length lst))))
53
54(define (loremipsum length)
55 (string-join (map (lambda _ (choice %loremipsum)) (iota length)) " "))
56
57(define (make-message body parent)
58 `((parent . ,parent)
59 (body . ,body)))
60
61(define (make-random-topic)
62 (make-message (loremipsum 99) #f))
63
44;;; 64;;;
45 65
66(define %topics (map (lambda _ (make-random-topic)) (iota 0)))
67
68(define (c3b2/topics)
69 "Return vertices of topics ie. messages without parent"
70 (map get (fs:find 'parent #f)))
71
72(define (c3b2/topic-add! body)
73 (let ((new-topic `((kind . message)
74 (body . ,body)
75 (parent . #f))))
76 (save (create-vertex new-topic))))
77
78;;; web
79
46(define (template body-class body) 80(define (template body-class body)
47 `((doctype "html") 81 `((doctype "html")
48 (html 82 (html
49 (head 83 (head
50 (meta (@ (charset "utf-8"))) 84 (meta (@ (charset "utf-8")))
51 (title "guile-web boilerplate") 85 (title "c3b2")
52 (link (@ (rel "stylesheet") (href "/static/normalize.css"))) 86 (link (@ (rel "stylesheet") (href "/static/normalize.css")))
53 (link (@ (rel "stylesheet") (href "/static/main.css")))) 87 (link (@ (rel "stylesheet") (href "/static/main.css"))))
54 (body 88 (body
55 (div (h1 (a (@ (href "/")) "c3b2"))) 89 (div (h1 (a (@ (href "/")) "c3b2")))
56 ,body)))) 90 ,body))))
57 91
92(define (template/topic topic)
93 `(div (p ,(vertex-ref topic 'body))
94 (a (@ (href ,(string-append "/replies/" (vertex-uid topic))))
95 "[replies]")))
96
97(define (template/index topics)
98 `(,(map template/topic topics)
99 (hr)
100 (form (@ (method "POST")
101 (action "/"))
102 (h2 "Create a new topic")
103 (textarea (@ (name "body")))
104 (input (@ (type "submit")
105 (value "publish"))))))
106
107(define (route/index/get)
108 (render-html (template "index" (template/index (c3b2/topics)))))
109
110(define (route/index/post body)
111 (c3b2/topic-add! (assoc-ref (decode body) "body"))
112 (redirect "/"))
58 113
59(define (handler request body) 114(define (router request body)
60 (with-context* 115 (with-context*
61 (match (cons (request-method request) (request-path-components request)) 116 (match (cons (request-method request) (request-path-components request))
62 (('GET) (render-html (template "index" '(div "Héllo Guilers")))) 117 (('GET) (route/index/get))
118 (('POST) (route/index/post body))
63 (('GET "static" path ...) (render-static-asset path)) 119 (('GET "static" path ...) (render-static-asset path))
64 (_ (not-found (uri->string (request-uri request))))))) 120 (_ (not-found (uri->string (request-uri request)))))))
65 121
@@ -67,4 +123,4 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
67(define-public (main _) 123(define-public (main _)
68 (format #t "Server running @ http://localhost:8080\n") 124 (format #t "Server running @ http://localhost:8080\n")
69 (with-env (env-open* "wt" (list *feature-space*) "create,log=(enabled=true)") 125 (with-env (env-open* "wt" (list *feature-space*) "create,log=(enabled=true)")
70 (run-server handler))) 126 (run-server router)))