Browse code

Added customized SVG support

Jaidyn Lev authored on 2018-06-19 16:28:23
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+(in-package :doormat)
2
+
3
+(translate:define-language `en)
4
+(translate:define-language `eo)
5
+(translate:add-single-translation `en "default msg" "~d people've visited this page!")
6
+(translate:add-single-translation `eo "default msg" "~d homoj vizitis ĉi paĝon!")
... ...
@@ -2,11 +2,18 @@
2 2
 
3 3
 (defun init ()
4 4
   "Init function for use directly in CGI scripts."
5
+  (cl-cgi:populate-environment)
5 6
 
6
-  (cl-cgi:populate-environment))
7
+  (let ((*standard-output* (make-broadcast-streaM)))
8
+    (translate:define-language `en)
9
+    (translate:define-language `eo)
10
+    (translate:add-single-translation `en
11
+                                      "default" "~d people've visited this page!")
12
+    (translate:add-single-translation `eo
13
+                                      "default" "~d homoj vizitis ĉi paĝon!")))
7 14
 
8 15
 
9
-(defun dm-txt ()
16
+(defun dm-txt (&optional (message (get-default-message)))
10 17
   "Prints out/creates visitor-count for the requested URL in plain-text."
11 18
 
12 19
   (format t "Content-Type: text/plain~%~%")
... ...
@@ -21,7 +28,7 @@
21 28
       (format t "1"))))
22 29
 
23 30
 
24
-(defun dm-html ()
31
+(defun dm-html (&optional (message (get-default-message)))
25 32
   "Prints out/creates visitor-count for the requested URL in HTML."
26 33
 
27 34
   (format t "Content-Type: text/html~%~%")
... ...
@@ -40,12 +47,15 @@
40 47
                          " visitors! :)</p></div>"))))
41 48
 
42 49
 
43
-(defun dm-svg ()
50
+(defun dm-svg (&optional (svg "res/svg/default.svg")
51
+                         (message (get-default-message))
44 52
   "Prints out/creates visitor-count for the requesed URL in SVG."
45 53
   
46 54
   (format t "Content-Type: image/svg+xml~%~%")
47 55
 
48
-  (let ((visitors (doormat:fetch-visitors cl-cgi:*query-string*)))
56
+  (let ((visitors (doormat:fetch-visitors cl-cgi:*query-string*))
57
+        (svg-data ""))
58
+
49 59
     (if visitors
50 60
       (doormat:increment-visitors cl-cgi:*query-string*)
51 61
       (doormat:create-entry cl-cgi:*query-string*))
... ...
@@ -53,16 +63,10 @@
53 63
     (if (not visitors)
54 64
       (setq visitors 1))
55 65
 
56
-    (format t
57
-            "<!DOCTYPE svg PUBLIC
58
-            \"-//W3C//DTD SVG 1.1//EN\"
59
-            \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">
60
-            <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"
61
-            xmlns:xlink=\"http://www.w3.org/1999/xlink\"
62
-            xml:space=\"preserve\">
63
-
64
-            <text x=\"0\" y=\"15\" fill=\"red\">
65
-              ~A people've visited this page! :)
66
-            </text>
67
-            </svg>" visitors)))
68 66
 
67
+    (setq svg-data (uiop:read-file-string svg))
68
+
69
+    (format t "~A"
70
+            (cl-strings:replace-all
71
+              (cl-strings:replace-all svg-data "~A" message)
72
+              "~d" (format nil "~A" visitors)))))
69 73
new file mode 100644
... ...
@@ -0,0 +1,151 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+
4
+<svg
5
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
6
+   xmlns:cc="http://creativecommons.org/ns#"
7
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8
+   xmlns:svg="http://www.w3.org/2000/svg"
9
+   xmlns="http://www.w3.org/2000/svg"
10
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
11
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
12
+   width="300"
13
+   height="35"
14
+   viewBox="0 0 79.374996 9.2604169"
15
+   version="1.1"
16
+   id="svg8"
17
+   inkscape:version="0.92.2 2405546, 2018-03-11"
18
+   sodipodi:docname="drawing.svg">
19
+  <defs
20
+     id="defs2" />
21
+  <sodipodi:namedview
22
+     id="base"
23
+     pagecolor="#ffffff"
24
+     bordercolor="#666666"
25
+     borderopacity="1.0"
26
+     inkscape:pageopacity="0.0"
27
+     inkscape:pageshadow="2"
28
+     inkscape:zoom="1.979899"
29
+     inkscape:cx="147.25539"
30
+     inkscape:cy="-6.3248194"
31
+     inkscape:document-units="mm"
32
+     inkscape:current-layer="layer1"
33
+     showgrid="false"
34
+     units="px"
35
+     inkscape:window-width="826"
36
+     inkscape:window-height="966"
37
+     inkscape:window-x="-1"
38
+     inkscape:window-y="15"
39
+     inkscape:window-maximized="0" />
40
+  <metadata
41
+     id="metadata5">
42
+    <rdf:RDF>
43
+      <cc:Work
44
+         rdf:about="">
45
+        <dc:format>image/svg+xml</dc:format>
46
+        <dc:type
47
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
48
+        <dc:title></dc:title>
49
+      </cc:Work>
50
+    </rdf:RDF>
51
+  </metadata>
52
+  <g
53
+     inkscape:label="Tavolo 1"
54
+     inkscape:groupmode="layer"
55
+     id="layer1"
56
+     transform="translate(0,-287.73955)">
57
+    <text
58
+       xml:space="preserve"
59
+       style="font-style:normal;font-weight:normal;font-size:5.29166651px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
60
+       x="3.3074603"
61
+       y="293.85956"
62
+       id="text3756"><tspan
63
+         sodipodi:role="line"
64
+         id="tspan3754"
65
+         x="3.3074603"
66
+         y="293.85956"
67
+         style="font-size:4.58611107px;stroke-width:0.26458332">~A</tspan></text>
68
+    <path
69
+       sodipodi:type="star"
70
+       style="fill:#808080;stroke-width:0.26458332"
71
+       id="path3758"
72
+       sodipodi:sides="5"
73
+       sodipodi:cx="2.9399648"
74
+       sodipodi:cy="289.11551"
75
+       sodipodi:r1="1.442389"
76
+       sodipodi:r2="0.72119451"
77
+       sodipodi:arg1="1.3370531"
78
+       sodipodi:arg2="1.9653717"
79
+       inkscape:flatsided="false"
80
+       inkscape:rounded="0"
81
+       inkscape:randomized="0"
82
+       d="m 3.2740517,290.51867 -0.6113258,-0.73738 -0.9540118,0.0856 0.5123868,-0.80927 -0.3761778,-0.88088 0.9279982,0.23723 0.7215211,-0.62998 0.061148,0.95589 0.8221024,0.49154 -0.8902069,0.35354 z"
83
+       inkscape:transform-center-x="-0.090315706"
84
+       inkscape:transform-center-y="0.034053915"
85
+       transform="matrix(0.87482592,0,0,0.95113403,-1.4948274,20.677769)" />
86
+    <path
87
+       sodipodi:type="star"
88
+       style="fill:#808080;stroke-width:0.26458332"
89
+       id="path3758-3"
90
+       sodipodi:sides="5"
91
+       sodipodi:cx="2.9399648"
92
+       sodipodi:cy="289.11551"
93
+       sodipodi:r1="1.442389"
94
+       sodipodi:r2="0.72119451"
95
+       sodipodi:arg1="1.3370531"
96
+       sodipodi:arg2="1.9653717"
97
+       inkscape:flatsided="false"
98
+       inkscape:rounded="0"
99
+       inkscape:randomized="0"
100
+       d="m 3.2740517,290.51867 -0.6113258,-0.73738 -0.9540118,0.0856 0.5123868,-0.80927 -0.3761778,-0.88088 0.9279982,0.23723 0.7215211,-0.62998 0.061148,0.95589 0.8221024,0.49154 -0.8902069,0.35354 z"
101
+       inkscape:transform-center-x="-0.090315706"
102
+       inkscape:transform-center-y="0.034053915"
103
+       transform="matrix(0.87482593,0,0,0.95113404,75.505173,20.677767)" />
104
+    <path
105
+       sodipodi:type="star"
106
+       style="fill:#808080;stroke-width:0.26458332"
107
+       id="path3758-2"
108
+       sodipodi:sides="5"
109
+       sodipodi:cx="2.9399648"
110
+       sodipodi:cy="289.11551"
111
+       sodipodi:r1="1.442389"
112
+       sodipodi:r2="0.72119451"
113
+       sodipodi:arg1="1.3370531"
114
+       sodipodi:arg2="1.9653717"
115
+       inkscape:flatsided="false"
116
+       inkscape:rounded="0"
117
+       inkscape:randomized="0"
118
+       d="m 3.2740517,290.51867 -0.6113258,-0.73738 -0.9540118,0.0856 0.5123868,-0.80927 -0.3761778,-0.88088 0.9279982,0.23723 0.7215211,-0.62998 0.061148,0.95589 0.8221024,0.49154 -0.8902069,0.35354 z"
119
+       inkscape:transform-center-x="-0.090315706"
120
+       inkscape:transform-center-y="0.034053915"
121
+       transform="matrix(0.87482593,0,0,0.95113404,-1.42801,13.892776)" />
122
+    <path
123
+       sodipodi:type="star"
124
+       style="fill:#808080;stroke-width:0.26458332"
125
+       id="path3758-2-1"
126
+       sodipodi:sides="5"
127
+       sodipodi:cx="2.9399648"
128
+       sodipodi:cy="289.11551"
129
+       sodipodi:r1="1.442389"
130
+       sodipodi:r2="0.72119451"
131
+       sodipodi:arg1="1.3370531"
132
+       sodipodi:arg2="1.9653717"
133
+       inkscape:flatsided="false"
134
+       inkscape:rounded="0"
135
+       inkscape:randomized="0"
136
+       d="m 3.2740517,290.51867 -0.6113258,-0.73738 -0.9540118,0.0856 0.5123868,-0.80927 -0.3761778,-0.88088 0.9279982,0.23723 0.7215211,-0.62998 0.061148,0.95589 0.8221024,0.49154 -0.8902069,0.35354 z"
137
+       inkscape:transform-center-x="-0.090315706"
138
+       inkscape:transform-center-y="0.034053915"
139
+       transform="matrix(0.87482593,0,0,0.95113404,75.505173,13.892767)" />
140
+    <path
141
+       style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
142
+       d="M 2.4017089,288.99058 77.448248,288.82527"
143
+       id="path3831"
144
+       inkscape:connector-curvature="0" />
145
+    <path
146
+       style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
147
+       d="m 2.3348915,295.77557 75.1133565,-0.1653"
148
+       id="path3835"
149
+       inkscape:connector-curvature="0" />
150
+  </g>
151
+</svg>
0 152
new file mode 100755
... ...
@@ -0,0 +1,6 @@
1
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
2
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
3
+     <text x="0" y="15" fill="red">
4
+          ~A
5
+      </text>
6
+</svg>