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

New Feature 🔥 #290

Closed
quimt opened this issue Jun 9, 2024 · 1 comment
Closed

New Feature 🔥 #290

quimt opened this issue Jun 9, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@quimt
Copy link

quimt commented Jun 9, 2024

Is your feature request related to a problem? Please describe. 🤔
I've noticed that some of my code operating on the children of a TagRef' is now broken. Basically this seems to be because the children now appear as seq[Node] instead of seq[TagRef] when passed around as data.

Describe the solution you'd like 💡
Since making a TagRef through buildHtml only to take out a seq of children TagRefs is a bit convoluted, I thought it might would be a good time to implement some templates for creating seqs of to-be-rendered DSL data. I'd use something like this myself in my own development system if it wasn't integrated into happyx. Note that currently the TagRef based approach of buildHtmls fails and only the thunk based approach works in a straightforward way.


template thunkHtml(body: untyped): proc(): TagRef =
  proc(): TagRef = buildHtml:
    body

template thunkHtmls(body: untyped): seq[proc(): TagRef] =
  block:
    var res: seq[proc(): TagRef]
    template html(b: untyped) =
      res.add:
        proc(): TagRef = buildHtml:
          b
    body
    res

template buildHtmls(body: untyped): seq[TagRef] =
  block:
    var res: seq[TagRef]
    template html(b: untyped) =
      res.add:
        buildHtml:
          b
    body
    res

let htmlProcs = thunkHtmls:
  html:
    tSpan: "front"
  html:
    tSpan: "back"

let htmlTags = buildHtmls:
  html:
    tSpan: "right"
  html:
    tSpan: "left"

component FormatProcHtml:
  p: (proc (): TagRef) # parentheses needed in avoid "nested statements" error
  html:
    em(style="color:blue"): {self.p()}

component FormatTagHtml:
  t: TagRef
  html:
    em(style="color:blue"):
      {self.t.val}

appRoutes("ROOT"):
  "/":
    for i in 1..5:
      tDiv:{$htmlProcs[0]()}
      FormatProcHtml(htmlProcs[1])
    for i in 1..5:
      tDiv:{$htmlTags[0]}
      FormatTagHtml(htmlTags[1])

image

@quimt quimt added the enhancement New feature or request label Jun 9, 2024
Ethosa added a commit that referenced this issue Jun 9, 2024
@Ethosa
Copy link
Contributor

Ethosa commented Jun 9, 2024

Solved in the next commit, thx

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

No branches or pull requests

2 participants