Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I believe, everything you want except layouts is already available from Spinneret #1

Open
svetlyak40wt opened this issue Mar 6, 2024 · 3 comments

Comments

@svetlyak40wt
Copy link

What about just adding layouts feature on top of Spinneret as a separate spinneret-layouts system?

@MarceColl
Copy link
Owner

MarceColl commented Mar 6, 2024

Hello! Big fan of yours!

Maybe I was holding it wrong but composition in spinneret was not as seamless as I expected and variable interpolation was not working. Maybe I was doing something wrong.

@MarceColl
Copy link
Owner

Hmmm, trying it again now it mostly works and composes as I expected, I have no idea what I tried then

I could create a spinneret layouts indeed :)

@svetlyak40wt
Copy link
Author

Actually, what you are trying to do with layouts can be accomplished with a macro.

Here is how I've rewrote the code from your README:

(defmacro main-layout ((&key title) &body body)
  `(spinneret:with-html
     (:html
      (:head
       (:script :src "https://whatever")
       (:title ,title))
      (:body
       ,@body))))

(defun main-func ()
  (main-layout (:title "Hello World!")
    (:div "Hello World")))

And when I run it, I'm getting this result:

CL-USER> (main-func)
<html lang=en>
 <head>
  <meta charset=UTF-8>
  <script src=https://whatever></script>
  <title>Hello World!</title>
 </head>
 <body>
  <div>
   Hello World
  </div>
 </body>
</html>

But for my projects based on Reblocks framework, I'm using generic functions for template composition.

For example, here is the main "layout" for the page, defined for any Reblocks app. It calls render-body generic function. And in Ultralisp I define a method for it to show the real page content.

The same way, widgets (a smaller pieces of the page) can define their own html in their render methods and these blocks can nest each other. For example here, I'm wrapping each page widget with the "frame" widget by calling make-page-frame function. This frame widget defines site's menu and sidebar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants