trying to scribble the js api
This commit is contained in:
parent
13299c0bb0
commit
67645155db
|
@ -5,12 +5,12 @@
|
|||
|
||||
;; insert-break: -> void
|
||||
(define (insert-break)
|
||||
(call ($ "<br/>") "appendTo" body)
|
||||
(call-method ($ "<br/>") "appendTo" body)
|
||||
(void))
|
||||
|
||||
|
||||
(define (write-message msg)
|
||||
(void (call (call (call ($ "<span/>") "text" msg)
|
||||
(void (call-method (call-method (call-method ($ "<span/>") "text" msg)
|
||||
"css" "white-space" "pre")
|
||||
"appendTo"
|
||||
body)))
|
||||
|
@ -18,8 +18,8 @@
|
|||
|
||||
|
||||
;; Set the background green.
|
||||
(void (call body "css" "background-color" "lightgreen"))
|
||||
(void (call ($ "<h1>Hello World</h1>") "appendTo" body))
|
||||
(void (call-method body "css" "background-color" "lightgreen"))
|
||||
(void (call-method ($ "<h1>Hello World</h1>") "appendTo" body))
|
||||
(write-message "Hello, this is a test!")
|
||||
(insert-break)
|
||||
(let loop ([i 0])
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
EXPORTS['alert'] =
|
||||
RUNTIME.makePrimitiveProcedure(
|
||||
'is-color?',
|
||||
'alert',
|
||||
1,
|
||||
function(MACHINE) {
|
||||
var elt = MACHINE.env[MACHINE.env.length - 1];
|
||||
|
@ -20,9 +20,9 @@ EXPORTS['$'] =
|
|||
return $(obj);
|
||||
});
|
||||
|
||||
EXPORTS['call'] =
|
||||
EXPORTS['call-method'] =
|
||||
RUNTIME.makePrimitiveProcedure(
|
||||
'call',
|
||||
'call-method',
|
||||
new RUNTIME.ArityAtLeast(2),
|
||||
function(MACHINE) {
|
||||
var obj = MACHINE.env[MACHINE.env.length - 1];
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
#:javascript ("js-impl.js")
|
||||
#:provided-values (alert
|
||||
body
|
||||
call
|
||||
call-method
|
||||
$))
|
|
@ -1,6 +1,6 @@
|
|||
#lang s-exp "../lang/base.rkt"
|
||||
|
||||
(provide alert body call $)
|
||||
(provide alert body call-method $)
|
||||
|
||||
(define (alert x)
|
||||
(display x)
|
||||
|
@ -8,8 +8,8 @@
|
|||
|
||||
(define body 'blah)
|
||||
|
||||
(define (call object method . args)
|
||||
(define (call-method object method . args)
|
||||
'not-done-yet)
|
||||
|
||||
(define ($ name)
|
||||
'not-done-yet)
|
||||
'not-done-yet)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
planet/resolver
|
||||
scribble/eval
|
||||
racket/sandbox
|
||||
(only-in racket/contract any/c)
|
||||
(for-label racket/base)
|
||||
racket/runtime-path
|
||||
"scribble-helpers.rkt"
|
||||
|
@ -272,15 +273,65 @@ commands to do something interesting...)
|
|||
|
||||
@section{The JavaScript API}
|
||||
|
||||
(This needs to describe what hooks we've got from the JavaScript side of things.
|
||||
@defmodule/this-package[js]{
|
||||
|
||||
In particular, we need to talk about the plt namespace constructed by the runtime,
|
||||
and the major, external bindings, like @tt{plt.runtime.invokeMains})
|
||||
|
||||
This needs to describe what hooks we've got from the JavaScript side
|
||||
of things.
|
||||
|
||||
In particular, we need to talk about the plt namespace constructed by
|
||||
the runtime, and the major, external bindings, like
|
||||
@tt{plt.runtime.invokeMains}.
|
||||
|
||||
The contracts here are not quite right either. I want to use JQuery
|
||||
as the type in several of the bindings here, but don't quite know how
|
||||
to teach Scribble about them yet.
|
||||
|
||||
|
||||
|
||||
@defproc[(alert [msg string?]) void]{
|
||||
|
||||
Displays an alert. Currently implemented using JavaScript's
|
||||
@litchar{alert} function.}
|
||||
|
||||
@defthing[body any/c]{
|
||||
A JQuery-wrapped value representing the body of the DOM.
|
||||
}
|
||||
|
||||
@defproc[(call-method [object javascript-function]
|
||||
[method-name string?]
|
||||
[arg any/c] ...) any/c]{
|
||||
|
||||
Calls theAssuming @racket[object] is a JavaScript value that supports
|
||||
the method call. Returns a raw JavaScript value back.
|
||||
|
||||
For example,
|
||||
@racketblock[(call-method body "css" "background-color")]
|
||||
should return the css color of the body.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@defproc[($ [locator any/c]) -> any/c]{
|
||||
|
||||
Uses JQuery to construct or collect a set of DOM elements, as
|
||||
described in the @link["http://api.jquery.com/jQuery/"]{JQuery
|
||||
documentation}.
|
||||
|
||||
For example, @racketblock[(call-method ($ "<h1>Hello World</h1>")
|
||||
"appendTo" body)] will construct a @tt{h1} header, and append it to
|
||||
the document body.
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@section{Internals}
|
||||
@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Reference in New Issue
Block a user