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

Tag Builder #276

Open
davesmith00000 opened this issue Aug 12, 2024 · 0 comments
Open

Tag Builder #276

davesmith00000 opened this issue Aug 12, 2024 · 0 comments

Comments

@davesmith00000
Copy link
Member

From Discord via @JD557, sounds like an interesting suggestion to me. I wonder if it can live in parallel with the current set up, or if it needs to replace it? Give it a try.


I'm not sure if this was discussed before (I think it might break bincompat, so it might be an issue), but are there any plans to improve the ergonomics of creating custom tags?

Here's what I mean: Right now tags are defined with for custom methods:

  def tag[M](name: String)(attributes: Attr[M]*)(children: Elem[M]*): Html[M] =
    Tag(name, attributes.toList, children.toList)
  @targetName("tag-list-repeated")
  def tag[M](name: String)(attributes: List[Attr[M]])(children: Elem[M]*): Html[M] =
    Tag(name, attributes, children.toList)
  @targetName("tag-repeated-list")
  def tag[M](name: String)(attributes: Attr[M]*)(children: List[Elem[M]]): Html[M] =
    Tag(name, attributes.toList, children)
  @targetName("tag-list-list")
  def tag[M](name: String)(attributes: List[Attr[M]])(children: List[Elem[M]]): Html[M] =
    Tag(name, attributes, children)

This is quite annoying to create new tags (and I think this is the reason for https://github.com/PurpleKingdomGames/tyrian/blob/3c3e6e7595e6d6e8e7444103c5c765de3978badc/project/TagGen.scala)

Wouldn't it be possible to instead have something like this?

case class TagBuilder(name: String):
  def apply[M](attributes: Attr[M]*)(children: Elem[M]*): Html[M] =
    Tag(name, attributes.toList, children.toList)
  @targetName("tag-list-repeated")
  def apply[M](attributes: List[Attr[M]])(children: Elem[M]*): Html[M] =
    Tag(name, attributes, children.toList)
  @targetName("tag-repeated-list")
  def apply[M](attributes: Attr[M]*)(children: List[Elem[M]]): Html[M] =
    Tag(name, attributes.toList, children)
  @targetName("tag-list-list")
  def apply[M](attributes: List[Attr[M]])(children: List[Elem[M]]): Html[M] =
    Tag(name, attributes, children)

def tag(name: String): TagBuilder = TagBuilder(name)

Then I think one could just write code like val table = tag("table") and things would just work.
(Maybe there are some exceptions to this that I'm not thinking about)

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

1 participant