From: Haris Bogdanovi� on
Hi.

How to set bgcolor within (cl-who) :td tag:

(:td :onclick (ps (setf bgcolor "blue")))

or something like this to get

<td onclick='this.bgcolor="blue"' </td> ?

Thanks


From: Jorge Gajon on
On 2010-06-20, Haris Bogdanovi� <fbogdanovic(a)xnet.hr> wrote:
> Hi.
>
> How to set bgcolor within (cl-who) :td tag:
>
> (:td :onclick (ps (setf bgcolor "blue")))
>
> or something like this to get
>
><td onclick='this.bgcolor="blue"' </td> ?
>

Hello Haris,

First, the inline JavaScript code you want is this:

<td onclick="this.style.backgroundColor='blue';">...</td>

To create that bit of JavaScript with parenscript you need need this
form:

(ps (setf this.style.background-color "blue"))

But, if you try to mix it with CL-WHO like in the following line, it
won't work because some characters like `=` makes it go crazy.

(:td :onclick (ps (setf this.style.background-color "blue")) "blah")

See the generated html code.

To fix it you simply need to escape the string with the function
`escape-string` which is also part of CL-WHO:

(:td :onclick (escape-string
(ps (setf this.style.background-color "blue")))
"blah")


From: Olof-Joachim Frahm on
Jorge Gajon <gajon(a)gajon.org> writes:

> On 2010-06-20, Haris Bogdanoviæ <fbogdanovic(a)xnet.hr> wrote:
> To fix it you simply need to escape the string with the function
> `escape-string` which is also part of CL-WHO:
>
> (:td :onclick (escape-string
> (ps (setf this.style.background-color "blue")))
> "blah")

Since that naming convention isn't supported anymore[1], you'd probably
rewrite it this way:

(:td :onclick (ps-inline (setf (@ this style background-color) "blue")))

Also, parenscript has PS-INLINE, which takes care of correct escaping

Cheers,
Olof

[1]:
> ; caught WARNING:
> ; (in macroexpansion of (PS-INLINE (SETF THIS.BGCOLOR "blue")))
> ; (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
> ; Symbol THIS.BGCOLOR contains one of '.[]' - this compound naming
> ; convention is no longer supported by Parenscript!

--
The world is burning. Run.
From: Haris Bogdanovic on
Thanks, it works now as I intended.
How do I transform javascript expressions to one for use with lisp:
this.style.backgroundColor becomes
this.style.background-color ?
Are there other examples/rules ?


From: Jorge Gajon on
On 2010-06-20, Olof-Joachim Frahm <Olof.Frahm(a)web.de> wrote:
> Jorge Gajon <gajon(a)gajon.org> writes:
>
>> On 2010-06-20, Haris Bogdanovi� <fbogdanovic(a)xnet.hr> wrote:
>> To fix it you simply need to escape the string with the function
>> `escape-string` which is also part of CL-WHO:
>>
>> (:td :onclick (escape-string
>> (ps (setf this.style.background-color "blue")))
>> "blah")
>
> Since that naming convention isn't supported anymore[1], you'd probably
> rewrite it this way:
>
> (:td :onclick (ps-inline (setf (@ this style background-color) "blue")))
>
> Also, parenscript has PS-INLINE, which takes care of correct escaping
>
> Cheers,
> Olof
>
> [1]:
>> ; caught WARNING:
>> ; (in macroexpansion of (PS-INLINE (SETF THIS.BGCOLOR "blue")))
>> ; (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
>> ; Symbol THIS.BGCOLOR contains one of '.[]' - this compound naming
>> ; convention is no longer supported by Parenscript!
>


Thank you Olof,

I tried that syntax several times and it didn't work. The problem was
that I was not importing any symbols from parenscript into my current
package, thus I was calling the `ps` macro with it's package qualifier:

CL-USER(2): (parenscript:ps (setf (@ this style backgroundColor) "blue"))

"at(this, style, backgroundcolor) = 'blue';"

Now after some more thought I realize that the problem is that I need to
refer to the `@` symbol in the parenscript package.

CL-USER(3): (parenscript:ps
(setf (parenscript:@ this style backgroundColor) "blue"))

"this.style.backgroundcolor = 'blue';"

I found this a little bit surprising. It should be easier to use
parenscript without importing all its symbols.

I've rarely needed to use parenscript and that's why I didn't care too
much when I encountered this problem and just used the dot notation.

But thank you for pointing out that it is deprecated.


I still have one question though; I couldn't get `ps-inline` to work
with a very simple example:

CL-USER(7): (parenscript:ps-inline
(setf (parenscript:@ foo bar) "baz"))

debugger invoked on a UNBOUND-VARIABLE in thread #<THREAD
"initial thread" RUNNING
{AA026A9}>:
The variable PARENSCRIPT::COMPILE-EXPRESSION? is unbound.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.

((LAMBDA (&REST PARENSCRIPT::WHOLE))
(PARENSCRIPT::PS-ASSIGN (PARENSCRIPT:@ FOO BAR) "baz"))
0]

CL-USER(8): (in-package :ps)

#<PACKAGE "PARENSCRIPT">

PS(9): (ps-inline (setf (@ foo bar) "baz"))

debugger invoked on a UNBOUND-VARIABLE in thread #<THREAD
"initial thread" RUNNING
{AA026A9}>:
The variable COMPILE-EXPRESSION? is unbound.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.

((LAMBDA (&REST WHOLE)) (PS-ASSIGN (@ FOO BAR) "baz"))
0]


Do you know why is this? Is it expecting some context?

Thank you.

--
Jorge Gajon