diff --git a/examples/mathjax-script.js b/examples/mathjax-script.js new file mode 100644 index 0000000..1a0890a --- /dev/null +++ b/examples/mathjax-script.js @@ -0,0 +1,21 @@ + + + diff --git a/examples/mathjax.rkt b/examples/mathjax.rkt new file mode 100644 index 0000000..7d7e5cd --- /dev/null +++ b/examples/mathjax.rkt @@ -0,0 +1,22 @@ +#lang planet dyoo/whalesong +(require (planet dyoo/whalesong/web-world)) + +;;; This demonstrates how to use MathJax to write equations. +;;; Use --include-script mathjax-script.js to include the MathJax. +;;; racket whalesong.rkt build --include-script mathjax-script.js mathjax.rkt + +;; tick: world view -> world +(define (tick n view) + (add1 n)) + +;; draw: world view -> view +(define (draw n view) + (->view + (xexp->dom `(p "This equation has no integer solutions: " + ,(let ([n (number->string n)]) + (format "$$ x^~a + y^~a = z^~a $$" n n n)))))) + +(big-bang 3 + (initial-view (xexp->dom '(html (head) (body)))) + (on-tick tick 5) + (to-draw draw)) \ No newline at end of file diff --git a/js-assembler/package.rkt b/js-assembler/package.rkt index 132d4a0..f15521f 100644 --- a/js-assembler/package.rkt +++ b/js-assembler/package.rkt @@ -444,7 +444,7 @@ M.modules[~s] = ;; package-standalone-xhtml: X output-port -> void (define (package-standalone-xhtml source-code op) - (display *header* op) + (display (get-header) op) (display (quote-cdata (string-append (get-runtime) (get-inert-code source-code @@ -513,11 +513,18 @@ M.modules[~s] = (force *the-runtime*)) +(define (append-text-files paths) + (string-join (map (λ (p) (if (file-exists? p) + (bytes->string/utf-8 (call-with-input-file p port->bytes)) + "")) + paths) + "\n")) -;; *header* : string -(define *header* +;; get-header : -> string +(define (get-header) + (format #< @@ -525,11 +532,12 @@ M.modules[~s] = + ~a \n" js)) js-files) diff --git a/parameters.rkt b/parameters.rkt index ce04423..f2c625f 100644 --- a/parameters.rkt +++ b/parameters.rkt @@ -25,7 +25,7 @@ current-one-module-per-file? current-with-cache? current-with-legacy-ie-support? - + current-header-scripts current-report-port current-timing-port @@ -103,6 +103,9 @@ (define current-with-legacy-ie-support? (make-parameter #t)) +;; Keeps list of Javascript files to be included in the header. +(: current-header-scripts (Parameterof (Listof Path))) +(define current-header-scripts (make-parameter '())) (: current-report-port (Parameterof Output-Port)) diff --git a/whalesong-cmd.rkt b/whalesong-cmd.rkt index b1aeb0b..8b86882 100644 --- a/whalesong-cmd.rkt +++ b/whalesong-cmd.rkt @@ -105,6 +105,12 @@ [("--as-standalone-xhtml") ("Write single standalone xhtml file") (as-standalone-html? #t)] + #:multi + [("--include-script") + script-path + ("Include a Javascript file in the header.") + (current-header-scripts (cons (string->path script-path) (current-header-scripts)))] + #:args (path) (maybe-with-profiling