Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Suvorovkot
    @Suvorovkot
    Yep
    Suvorovkot
    @Suvorovkot
    It helped to import "com.lihaoyi" % "scalatags_2.12" % "0.9.2"
    nafg
    @nafg
    @Suvorovkot you should let %% add the _2.12 for you
    Sakib Hadžiavdić
    @sake92
    Hi guys! I made RxTags library for using Scalatags reactively. It focuses on simplicity above all. Feedback welcome! https://github.com/sake92/RxTags-Starter
    Matthias Toggweiler
    @m-a-t
    Hi, I am doing my first steps using scalatags. I would like translate my CSS to scala. How would you translate
    fusszeile:before {
        content: "Seite " counter(page) " von " counter(pages);
    }
    or
    @page {
        size: 210mm 297mm;
        margin: 20mm 30mm;
        @bottom-right {
            content: element(footer)
        }
    }
    Olivier Filangi
    @ofilangi

    Hello everyone, I 'll try (without success to inialized a a() tag with an onclick event)

     a(href:="#",
            onclick:= { (e: MouseEvent) => ... } ,
              raw("«"))

    this does not compile...I used this trick to have the waiting behaviours:

     a(id:="fa",
                href:="#",
                raw("«"))
     document.getElementById("fa").addEventListener( "click" ,
          (event:MouseEvent) => {
            println("Hello World !")
          })

    are they a solution more elegant to do that ?

    scalway
    @scalway
    @ofilangi Here it works: https://scalafiddle.io/sf/yiVHJDF/0. Not sure wjat was wrong in your case.
    Olivier Filangi
    @ofilangi
    @scalway thanks for your answer. This issue persist on my environnement....I copy your fiddle snippet to test and here the error message :
    No AttrValue defined for type org.scalajs.dom.MouseEvent => Unit; scalatags does not know how to use org.scalajs.dom.MouseEvent => Unit as an attribute [error] onclick:= { (e: MouseEvent) => println("test") } ,
    Olivier Filangi
    @ofilangi
    ok, error fixed, I was confusing scalatags.Text.all. and scalatags.JsDom.all.
    raboof
    @raboof:matrix.org
    [m]
    Just for fun, I made my mastodon profile image using scalatags to create the svg: https://merveilles.town/@raboof / https://git.sr.ht/~raboof/circle/tree/main/item/Main.scala
    (the circle thing)
    bwbecker
    @bwbecker

    I'm trying to write some common fragments to be rendered in both the DOM and Text. That is, something based on the Cross-backend Code at https://www.lihaoyi.com/scalatags/#Cross-backendCode.

    I'm having trouble integrating the fragment into other HTML. Using the example as a starting point, I'd like to do:

    ```
    p( TextTemplates.widget)

    p(TextTemplates.widget)

    But when I do that I get a compile error : found : oat.xplatform.views.SharedHtmlFragmentsJVM.bundle.all.Tag
    required: scalatags.text.Frag

    If I change the return type from Tag to Frag I get
    found : Frag (in scalatags.generic)
    required: Frag (in scalatags.text)

    If I write

    p(TextTemplates.widget.render)

    I get the literal html text of the widget in the paragraph.

    Suggestions?

    bwbecker
    @bwbecker
    PS: This is not my actual code, but it's pretty close.
    Sakib Hadžiavdić
    @sake92
    @bwbecker check out my code here: https://github.com/sake92/hepek/tree/master/hepek-components
    js vs jvm
    depending on what you compile, the import will be different
    in shared code..
    bwbecker
    @bwbecker
    I'll take a look. I understand that the import will be different.
    bwbecker
    @bwbecker
    @sake92 Thanks! Got it working. It took me a night's sleep to realize that this approach is quite different from what is documented in #Cross-backendCode. Once I crossed that bridge, it came together easily. This certainly seems simpler and easier.
    Sakib Hadžiavdić
    @sake92
    np, glad you got it working! :)
    bwbecker
    @bwbecker
    Can someone give me the quick overview of how to build scalatags and publish it locally? I need a version with pull request 214 applied. I looked at the Mill documentation but haven't been able to figure out how it works with cross-compiling. I need v0.9.3 for scalaJS 1.4.0 (and the JVM).
    Li Haoyi
    @lihaoyi
    @bwbecker ./mill __.publishLocal should work
    discobaba
    @uncleweirdo_twitter

    Excuse my under-developed scala intuition but given the following:

    div(
        div(textAlign := center)(
              a(cls := "button", href := Link.screen(os.rel / "Index.vm"))(
                "Home")),
        br(),
        if (empl) br(),
        if (empl) br(),
        if (empl) span(id := SECRET_BUTTON)("Employee Only"),
        if (empl) "Some kinda stuff",
        br(),
        div(id :=ERR_MSG_DIV))

    what is the idiomatic way put the conditional lines in a single "if"?

    raboof
    @raboof:matrix.org
    [m]
    @uncleweirdo_twitter: if you're OK with putting all the conditional elements in an enclosing element, that might be the easiest way.
    discobaba
    @uncleweirdo_twitter
    I'm sure a div is often okay, but some kind of non-printing grouping element would be cool. It sounded like maybe a sequence would work, but I couldn't convince it.
    Sakib Hadžiavdić
    @sake92
    @uncleweirdo_twitter Option.when(empl)(br())
    on scala 2.13
    discobaba
    @uncleweirdo_twitter
    @sake92 This didn't work, if that's what you were trying to convey ...
    div(
        div(textAlign := center)(
              a(cls := "button", href := Link.screen(os.rel / "Index.vm"))(
                "Home")),
        br(),
        Option.when(empl)(
           br(),
           br(),
           span(id := SECRET_BUTTON)("Employee Only"),
           "Some kinda stuff"),
        br(),
        div(id : =ERR_MSG_DIV))
    Antoine Doeraene
    @sherpal
    The second argument to Option.when is actually only one argument (here you are giving 4 of them). It's been a while since I did not use scalatags, but I would imagine that enclosing these four arguments in a List should work, so Option.when(empl)(List(br(), br(), span(...), "Some kinda stuff"))
    discobaba
    @uncleweirdo_twitter
    @sherpal By Jove, you're right. Awesome. Thanks
    Jack Henahan
    @jhenahan
    Is there a way to absolutely unconditionally not escape some input? I'm in the middle of replacing an old legacy project with a fancy new Scala core, and part of that is (sadly) a 1-1 reproduction of our old frontend, which embeds a bunch of values from our backend into inline JSON objects. I'd really prefer to just use circe's .asJson syntax to handle rendering these things before handing off to ScalaTags, but I cannot find a way to prevent it from escaping every " as ". The docs suggest this isn't possible, but I figured I'd ask before I go hand-rolling JSON arrays as strings
    Jack Henahan
    @jhenahan
    (It's especially frustrating because I then have to embed single-quotes. While browsers will handle this fine, I'd prefer to write conformant JSON)
    Sakib Hadžiavdić
    @sake92
    @jhenahan maybe raw() will help?
    Jack Henahan
    @jhenahan
    raw(), shockingly, still escapes double quotes
    (Or just renders RawFrag(whatever) into the JSON if I fail to .render it [and still escapes the quotes])
    Sakib Hadžiavdić
    @sake92
    can you give an example?
    Text or JsDOM ?
    Jack Henahan
    @jhenahan
    Text. So if I have some val countries: Seq(String) = Seq("US", "Canada"), and I say countries.asJson.noSpaces, I have a String in hand like ["US", "Canada"]. But if I then embed that in a script, I get escaped quotes. Fiddle: https://scalafiddle.io/sf/peS8RKO/0
    Sakib Hadžiavdić
    @sake92
    just wrap that string in raw()
    Jack Henahan
    @jhenahan
    Ah, so now we come to the rough bit: In my case, the script block starts with raw""", which then defeats using raw within it. :( https://scalafiddle.io/sf/peS8RKO/2 (and https://scalafiddle.io/sf/peS8RKO/3 with .render)
    I suppose I'll just have to figure out how to refactor this thing to not do that (it's a bit of a mess having been copied pretty much wholesale from the old frontend)
    Jack Henahan
    @jhenahan
    Thanks for the help :)
    Sakib Hadžiavdić
    @sake92
    np, good luck! :D
    Clint Combs
    @ClintCombs
    Is there plan to port scalatags to Scala 3? I see some forks working on it, but haven't found any published artifacts yet. I assume the primary hurdle is porting the macros.
    raboof
    @raboof:matrix.org
    [m]
    @ClintCombs: I don't know, but using the 2.13 artifacts from scala3 worked fine for me
    https://git.sr.ht/~raboof/truchet if you want to take a peek (HEAD is compiling to javascript, but a bit further in the history it was still JVM)
    Li Haoyi
    @lihaoyi
    scalatags doesn't use any macros, so hopefully it should "just work" out of the box