render-link doesn't work for me

41 views
Skip to first unread message

Rayslava

unread,
Apr 2, 2012, 5:10:19 AM4/2/12
to weblocks
Hello.
I'm investigating weblocks now and just figured out such a thing:

(defun make-about-page ()
(make-instance 'widget :children
(list
(make-instance 'string-widget :content
"About page"))))

(defun make-test-page ()
(make-instance 'widget :children
(list
(make-instance 'string-widget :content
"test")
(make-instance 'string-widget :content
(with-html (str (render-link (lambda (&rest
args)
(declare (ignore args))
(do-page #'make-test-page))
"test page"
:ajaxp nil))))
(make-instance 'string-widget :content
"test2"))))

(defun/cc make-other-page (k)
(make-instance 'string-widget :content
(with-html (:p "Other Page")
(:p (render-link (lambda (&rest args)
(declare (ignorable args))
(answer k))
"Go Back")))))

(defun make-main-page ()
(make-instance 'widget :children
(list
(make-navigation "Main Menu"
(list "About" (make-about-page) "about")
(list "Companies" (make-test-page) "test")))))

(defun init-user-session (root)
(with-flow root
(yield (make-main-page))))

And "test page" link just doesn't appear.
Running results into

<div class='widget string-widget' id='dom2'>
<p>test</p>
</div>
<div class='widget string-widget' id='dom3'>
<p></p>
</div>
<div class='widget string-widget' id='dom4'>
<p>test2</p>
</div>

The only strange thing is the output when I load the file:

* (load "/home/ray/projects/localsite/src/layout.lisp")
<a href='/about?action=4027%3A9A51E3C66D4DB032E3C3ABE5145C46AD'>test
page</a>
T
* (reset-sessions)
*

That looks like render-page has wrong output stream. Could I do
something with it?

Scott L. Burson

unread,
Apr 2, 2012, 10:20:42 AM4/2/12
to webl...@googlegroups.com
Yes, I had trouble with this when I was first learning Weblocks also.

WITH-HTML doesn't return a string; it writes HTML to the output stream.  So calling it to supply the :CONTENT argument doesn't work.  Similarly for RENDER-LINK.

But you can use functions as widgets; the function will be invoked during rendering, which is the right time to render HTML and links.  So, for example:


  (defun make-test-page ()
    (make-instance 'widget :children
      (list ... (lambda () (render-link ...)) ... )))

Oh, and you don't need to use DEFUN/CC unless you're doing something really complicated.  I've written quite a substantial app without ever using it.

-- Scott

--
You received this message because you are subscribed to the Google Groups "weblocks" group.
To post to this group, send email to webl...@googlegroups.com.
To unsubscribe from this group, send email to weblocks+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/weblocks?hl=en.


rayslava

unread,
Apr 3, 2012, 11:20:36 AM4/3/12
to webl...@googlegroups.com
On Monday, April 2, 2012 6:20:42 PM UTC+4, Scott L. Burson wrote:
Yes, I had trouble with this when I was first learning Weblocks also.

WITH-HTML doesn't return a string; it writes HTML to the output stream.  So calling it to supply the :CONTENT argument doesn't work.  Similarly for RENDER-LINK.

Thanks. I'll try that. 
But you can use functions as widgets; the function will be invoked during rendering, which is the right time to render HTML and links.  So, for example:

  (defun make-test-page ()
    (make-instance 'widget :children
      (list ... (lambda () (render-link ...)) ... )))

Oh, and you don't need to use DEFUN/CC unless you're doing something really complicated.  I've written quite a substantial app without ever using it.
 
-- Scott

I understand that this piece of code looks inappropriate but I just want to try all the power of framework in simple situations firstly.

To unsubscribe from this group, send email to weblocks+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages