Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Split content generation procedures into support module |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
082f8c0d5b746a0cd8ce9c20f5f031af |
User & Date: | murphy 2018-08-31 14:42:20.077 |
Context
2018-08-31
| ||
16:33 | Content generation tests check-in: 62c9140a13 user: murphy tags: trunk | |
14:42 | Split content generation procedures into support module check-in: 082f8c0d5b user: murphy tags: trunk | |
14:08 | Green threads support check-in: b7e378098a user: murphy tags: trunk | |
Changes
Added content.scm.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | ;; ;; MIT License ;; ;; Copyright (c) 2018 Thomas Chust ;; ;; Permission is hereby granted, free of charge, to any person obtaining a copy ;; of this software and associated documentation files (the "Software"), to deal ;; in the Software without restriction, including without limitation the rights ;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ;; copies of the Software, and to permit persons to whom the Software is ;; furnished to do so, subject to the following conditions: ;; ;; The above copyright notice and this permission notice shall be included in ;; all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. ;; (define alist:js-escape '((#\' . #\') (#\" . #\") (#\\ . #\\) (#\backspace . #\b) (#\tab . #\t) (#\newline . #\n) (#\return . #\r))) (define char-set:no-js-escape (char-set-difference (char-set-union unicode-char-set:alphabetic char-set:digit char-set:punctuation char-set:symbol char-set:blank) (list->char-set (map car alist:js-escape)))) (define (write-js s #!optional [port (current-output-port)] [quotes #\"]) (let ([n (utf8-string-length s)]) (cond [quotes => (cut utf8-display <> port)]) (do ([i 0 (fx+ i 1)]) ((fx>= i n)) (let ([c (utf8-string-ref s i)]) (cond [(char-set-contains? char-set:no-js-escape c) (utf8-display c port)] [(assv c alist:js-escape) => (lambda (r) (utf8-display #\\ port) (utf8-display (cdr r) port))] [else (utf8-display "\\u" port) (utf8-display (string-pad (number->string (char->integer c) 16) 4 #\0) port)]))) (cond [quotes => (cut utf8-display <> port)]))) (define html-tag-rule (let ([tag-rules (make-hash-table eq? symbol-hash)]) (case-lambda [(tag) (hash-table-ref/default tag-rules tag 'normal)] [(tag rule) (cond [(not (memq rule '(void raw normal))) (error 'html-tag-rule "invalid tag rule" tag rule)] [(eq? rule 'normal) (hash-table-delete! tag-rules tag) (void)] [else (hash-table-set! tag-rules tag rule)])]))) (for-each (lambda (tag&rule) (html-tag-rule (car tag&rule) (cdr tag&rule))) '([area . void] [base . void] [br . void] [col . void] [command . void] [embed . void] [hr . void] [img . void] [input . void] [keygen . void] [link . void] [meta . void] [param . void] [source . void] [track . void] [wbr . void] [script . raw] [style . raw])) (define write-html (letrec ([write-escaped (lambda (s port) (let ([n (string-length s)]) (do ([i 0 (fx+ i 1)]) ((fx>= i n)) (let ([c (string-ref s i)]) (display (case c [(#\") """] [(#\&) "&"] [(#\<) "<"] [(#\>) ">"] [else c]) port)))))] [write-element (lambda (elt port) (unless (and (pair? elt) (symbol? (car elt)) (list? (cdr elt))) (error 'write-html "not a proper element" elt)) (let ([tag (car elt)] [attributes&contents (cdr elt)]) (when (eq? tag 'html) (display "<!DOCTYPE html>" port) (newline port)) (display #\< port) (display tag port) (let-values ([(rule) (html-tag-rule tag)] [(attributes contents) (cond [(null? attributes&contents) (values '() '())] [(and (list? (car attributes&contents)) (every pair? (car attributes&contents))) (values (car attributes&contents) (cdr attributes&contents))] [else (values '() attributes&contents)])]) (for-each (cut write-attribute <> port) attributes) (display #\> port) (case rule [(normal) (for-each (cut write-content #t <> port) contents)] [(raw) (for-each (cut write-content #f <> port) contents)] [(void) (unless (null? contents) (error 'write-html "void elements cannot have contents" elt))]) (case rule [(normal raw) (display "</" port) (display tag port) (display #\> port)])) (when (eq? tag 'html) (newline port))))] [write-attribute (lambda (attr port) (unless (and (pair? attr) (symbol? (car attr))) (error 'write-html "not a proper attribute" attr)) (let ([key (car attr)] [v (cdr attr)]) (cond [(not v) (void)] [(boolean? v) (display #\space port) (display key port)] [else (display #\space port) (display key port) (display "=\"" port) (if (list? v) (for-each (cut write-content #f <> port) v) (write-content #f v port)) (display #\" port)])))] [write-content (lambda (allow-elements? v port) (cond [(symbol? v) (display #\& port) (display v port) (display #\; port)] [(and (integer? v) (positive? v)) (display "&#" port) (display v port) (display #\; port)] [(string? v) (write-escaped v port)] [allow-elements? (write-element v port)] [else (error 'write-html "element not allowed in this context" v)]))]) (lambda (html #!optional [port (current-output-port)]) (write-element html port)))) ;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;; |
Added main.scm.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | ;; ;; MIT License ;; ;; Copyright (c) 2018 Thomas Chust ;; ;; Permission is hereby granted, free of charge, to any person obtaining a copy ;; of this software and associated documentation files (the "Software"), to deal ;; in the Software without restriction, including without limitation the rights ;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ;; copies of the Software, and to permit persons to whom the Software is ;; furnished to do so, subject to the following conditions: ;; ;; The above copyright notice and this permission notice shall be included in ;; all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. ;; (define (type-error location message . arguments) (abort (make-composite-condition (make-property-condition 'exn 'location location 'message message 'arguments arguments) (make-property-condition 'type)))) (define tag:webview (gensym 'webview)) (define webview? (cut tagged-pointer? <> tag:webview)) (define-foreign-type webview (c-pointer "webview_t") (lambda (v) (and v (if (webview? v) v (type-error 'webview "bad argument type" v)))) (lambda (v) (and v (tag-pointer v tag:webview)))) (define-foreign-type nonnull-webview (nonnull-c-pointer "webview_t") (lambda (v) (if (webview? v) v (type-error 'webview "bad argument type" v))) (lambda (v) (tag-pointer v tag:webview))) (define webview-callbacks (make-mutex 'webview-callbacks)) (mutex-specific-set! webview-callbacks (make-hash-table equal? equal?-hash)) (define-external (on_webview_external_invoke [nonnull-webview view] [(const c-string) data]) void (mutex-lock! webview-callbacks) (let ([proc (hash-table-ref (mutex-specific webview-callbacks) view)]) (mutex-unlock! webview-callbacks) (when proc (handle-exceptions exn (webview-log (string-trim (call-with-output-string (cut print-error-message exn <> "Callback Error")))) (proc view data))))) (define (webview title proc #!key [url #f] [width 800] [height 600] [resizable? #t] [debug? #f] [yield! #f]) (letrec ([view ((foreign-lambda webview "webview_new" nonnull-c-string c-string int int bool bool) title url width height resizable? debug?)] [loop (lambda () (when (zero? ((foreign-safe-lambda int "webview_loop" nonnull-webview bool) view (not yield!))) (cond [(number? yield!) (thread-sleep! yield!)] [yield! (thread-yield!)]) (loop)))]) (if view (set-finalizer! view (foreign-lambda void "webview_destroy" nonnull-webview)) (error 'webview "initialization failed")) (when proc (mutex-lock! webview-callbacks) (hash-table-set! (mutex-specific webview-callbacks) view proc) (mutex-unlock! webview-callbacks) ((foreign-lambda* void ([nonnull-webview view]) "webview_set_external_invoke_cb(view, on_webview_external_invoke);") view)) (loop))) (define webview-terminate! (foreign-safe-lambda void "webview_terminate" nonnull-webview)) (define webview-title-set! (foreign-safe-lambda void "webview_set_title" nonnull-webview nonnull-c-string)) (define webview-fullscreen-set! (foreign-safe-lambda void "webview_set_fullscreen" nonnull-webview bool)) (define (webview-eval view script) (unless (zero? ((foreign-safe-lambda int "webview_eval" nonnull-webview nonnull-c-string) view script)) (error 'webview-eval "JavaScript evaluation failed"))) (define (webview-inject view id html) (webview-eval view (call-with-output-string (lambda (port) (display "document.getElementById(" port) (write-js id port) (display ").innerHTML = " port) (write-js (call-with-output-string (cut write-html html <>)) port) (display ";" port))))) (define (webview-dialog view title #!optional value #!rest type) (let ([type (cond [(memq #:open type) (foreign-value "WEBVIEW_DIALOG_TYPE_OPEN" int)] [(memq #:save type) (foreign-value "WEBVIEW_DIALOG_TYPE_SAVE" int)] [else (foreign-value "WEBVIEW_DIALOG_TYPE_ALERT" int)])] [flags (bitwise-ior (if (memq #:directory type) (foreign-value "WEBVIEW_DIALOG_FLAG_DIRECTORY" int) (foreign-value "WEBVIEW_DIALOG_FLAG_FILE" int)) (cond [(memq #:error type) (foreign-value "WEBVIEW_DIALOG_FLAG_ERROR" int)] [(memq #:warning type) (foreign-value "WEBVIEW_DIALOG_FLAG_WARNING" int)] [else (foreign-value "WEBVIEW_DIALOG_FLAG_INFO" int)]))] [buf (make-string 4096 #\nul)]) ((foreign-safe-lambda void "webview_dialog" nonnull-webview int int nonnull-c-string c-string scheme-pointer size_t) view type flags title value buf (string-length buf)) (let scan ([pos 0]) (if (or (fx>= pos (string-length buf)) (eqv? (string-ref buf pos) #\nul)) (and (fx> pos 0) (substring buf 0 (fx- pos 1))) (scan (fx+ pos 1)))))) (define webview-log (foreign-lambda void "webview_print_log" nonnull-c-string)) ;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;; |
Changes to webview.egg.
︙ | ︙ | |||
8 9 10 11 12 13 14 | srfi-13 srfi-18 srfi-69 utf8) (components (extension webview (custom-build "build-webview") | | > > > > > | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | srfi-13 srfi-18 srfi-69 utf8) (components (extension webview (custom-build "build-webview") (source-dependencies "content.scm" "main.scm" "webview.h" "webview.impl.c") (modules webview-content webview)))) ;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;; |
Changes to webview.scm.
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 | ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. ;; (module webview (webview? webview webview-terminate! webview-title-set! webview-fullscreen-set! | > > > > > > > > > > > > > > > | < < | | | | | | | | | | < < | < < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < | < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 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 | ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. ;; (module webview-content (char-set:no-js-escape write-js html-tag-rule write-html) (import scheme (chicken base) (chicken fixnum) (only srfi-1 every) (prefix (only utf8 string-length string-ref display) utf8-) (only srfi-13 string-pad) utf8-srfi-14 (prefix unicode-char-sets unicode-) srfi-69) (include "content.scm")) (module webview (webview? webview webview-terminate! webview-title-set! webview-fullscreen-set! webview-eval webview-inject webview-dialog webview-log) (import scheme (chicken base) (chicken condition) (chicken fixnum) (chicken bitwise) (chicken foreign) (only (chicken port) call-with-output-string) (only (chicken memory) tagged-pointer? tag-pointer) (only (chicken gc) set-finalizer!) (only srfi-13 string-trim) srfi-18 srfi-69 webview-content) (foreign-declare "#include <webview.h>") (include "main.scm")) ;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;; |
Changes to webview.wiki.
︙ | ︙ | |||
117 118 119 120 121 122 123 124 125 126 127 128 129 130 | (webview-log MESSAGE) ⇒ VOID </nowiki></tt></h3> Outputs a message using a platform-specific logging mechanism. <h2>Content Generation</h2> <h3><tt><nowiki> char-set:no-js-escape </nowiki></tt></h3> A SRFI-14 set of characters that do not need to be escaped inside a JavaScript string. | > > > > > > > | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | (webview-log MESSAGE) ⇒ VOID </nowiki></tt></h3> Outputs a message using a platform-specific logging mechanism. <h2>Content Generation</h2> <h3><tt><nowiki> (import webview-content) </nowiki></tt></h3> This support module contains procedures that write JavaScript strings and HTML document trees with proper escaping. <h3><tt><nowiki> char-set:no-js-escape </nowiki></tt></h3> A SRFI-14 set of characters that do not need to be escaped inside a JavaScript string. |
︙ | ︙ |