ANN: Scalatags 0.3.4

52 views
Skip to first unread message

Haoyi Li

unread,
Jun 22, 2014, 5:10:53 PM6/22/14
to scal...@googlegroups.com, scal...@googlegroups.com, play-fr...@googlegroups.com
https://github.com/lihaoyi/scalatags

Lots of changes over the old 0.2.x series, even though 0.3.x was never really announced. Features include
There are also lots of changes to the internals:
  • The new ASTs, unlike the old ones, are now more-or-less opaque and can't be easily transformed by walking over them.
  • In exchange, 0.3.x has new typeclass-based extension points that are well defined, serving as places where you can hook custom logic into Scalatag and somewhat substituting the use-case of tree-transformers
  • A completely re-done architecture, to support the new dual-backend setup, opening the door to the possibility of writing code that targets both the Text and JsDom backends at the same time
  • Basically all the internal data structures have been renamed (documented here), and make much more sense than they did in 0.2.x
I welcome any questions/opinions/feedback =)

Haoyi Li

unread,
Jun 22, 2014, 5:44:22 PM6/22/14
to Benjamin Jackman, scal...@googlegroups.com, scal...@googlegroups.com, play-fr...@googlegroups.com
I was wondering if you had given more though to SVG support, I know there is this pull request pending

I haven't; I did most of this on the plane back from Berlin, and only arrived in San Francisco <24hrs ago. Will look at your PR in due course =)


On Sun, Jun 22, 2014 at 2:41 PM, Benjamin Jackman <benjamin...@gmail.com> wrote:
Looks really good! I have been using it all day and having static typing is really nice!

I was wondering if you had given more though to SVG support, I know there is this pull request pending:

I was thinking about replacing some d3 charts with a scalatags version to see if it produces more elegent code 
I want to wait until svg is ready.

--
You received this message because you are subscribed to the Google Groups "Scala.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-js+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Haoyi Li

unread,
Jun 24, 2014, 3:33:14 AM6/24/14
to Benjamin Jackman, scal...@googlegroups.com, scal...@googlegroups.com, play-fr...@googlegroups.com
Currently, not really. I used to have that feature, but it got lost in the 0.3.x rewrite, and I didn't feel strongly enough to put it back in. If it's important to you, you could try implementing it (would mostly involve fiddling around here and here, moving/aliasing things inside the StringTags mixin) and send a PR. 

It would probably take some work to make it compile with all the newly path-dependent types, which is why I haven't done it. I'm already doing pretty crazy type/trait stuff and it's amazing that it compile at all as is =P


On Mon, Jun 23, 2014 at 10:41 PM, Benjamin Jackman <benjamin...@gmail.com> wrote:
Is there a way to shorten this in my own library

    import scalatags.JsDom._
    import scalatags.JsDom.tags._
    import scalatags.JsDom.{styles => s, attrs => a}

so that I only have to do one import aka something like:

import cgta.ScalatagsStyle._

Haoyi Li

unread,
Jun 25, 2014, 2:44:52 PM6/25/14
to Benjamin Jackman, scal...@googlegroups.com, scal...@googlegroups.com, play-fr...@googlegroups.com
@BenjaminJackman I've published 0.3.8, which reduces the imports required to a single import and allows you to define custom bundles which can also provide whatever import conventions you desire with a single-import (see the unit test)

It's a pretty big re-organization and may have issues I haven't bumped into, so let me know if there are any problems. It works well enough for the unit tests and scala-js-fiddle in any case. Try it out =)

Benjamin Jackman

unread,
Jun 25, 2014, 2:46:45 PM6/25/14
to Haoyi Li, scal...@googlegroups.com, scal...@googlegroups.com, play-fr...@googlegroups.com
Wow awesome Thanks you so much! Looking forward to trying it out!

Benjamin Jackman

unread,
Jun 25, 2014, 3:19:57 PM6/25/14
to scal...@googlegroups.com, benjamin...@gmail.com, scal...@googlegroups.com, play-fr...@googlegroups.com
Ok trying it out now, 

    import scalatags.JsDom.{styles => s, attrs => a, _}
    import scalatags.JsDom.tags._
    println("Hello World Main Called")
    val t = div(s.color := "red")("SCALA JS APPEARS TO WORK!").render
    val b = button(a.onclick := (() => t.textContent = s"Clicked ${i += 1; i} times"))("Click Me").render

is giving me errors:

[error] /home/bjackman/cgta/orange/viz-sjs/src/main/scala/cgta/viz/learn/OjsHelloWorld.scala:20: could not find implicit value for parameter ev: scalatags.generic.StyleValue[Builder,String]
[error]     val t = div(s.color := "red")("SCALA JS APPEARS TO WORK!").render
[error]                         ^
[error] /home/bjackman/cgta/orange/viz-sjs/src/main/scala/cgta/viz/learn/OjsHelloWorld.scala:21: could not find implicit value for parameter ev: scalatags.generic.AttrValue[Builder,() => <error>]
[error]     val b = button(a.onclick := (() => t.textContent = s"Clicked ${i += 1; i} times"))("Click Me").render
[error]        


    import scalatags.JsDom.all._

works, if I remove the s. and a.

    import scalatags.JsDom.tags._
    import scalatags.JsDom.short._

also works.

Will try custom bundles next

Haoyi Li

unread,
Jun 25, 2014, 3:24:45 PM6/25/14
to Benjamin Jackman, scal...@googlegroups.com, scal...@googlegroups.com, play-fr...@googlegroups.com
If you're not using all or short, you need to pull in the implicits via import scalatags.JsDom.implicits._ If you make a custom bundle that mixes in Aggregate and import from it, that will provide the implicits too.

Benjamin Jackman

unread,
Jun 25, 2014, 3:31:06 PM6/25/14
to Haoyi Li, scal...@googlegroups.com, scal...@googlegroups.com, play-fr...@googlegroups.com
gotcha ok makes sense

Benjamin Jackman

unread,
Jun 25, 2014, 3:41:10 PM6/25/14
to scal...@googlegroups.com, benjamin...@gmail.com, scal...@googlegroups.com, play-fr...@googlegroups.com
So this is what i ended up going with for the JsDom Bundle:

import scalatags.{JsDom, jsdom}
object OTags extends JsDom.Cap with jsdom.Tags with JsDom.Aggregate with scalatags.LowPriorityImplicits {
  object S extends JsDom.Cap with JsDom.Styles
  object A extends JsDom.Cap with JsDom.Attrs
}


    import OTags._

    val t = div(S.color := "red")("SCALA JS APPEARS TO WORK!").render
    val b = button(A.onclick := (() => t.textContent = s"Clicked ${i += 1; i} times"))("Click Me").render

Seems to work great!

Thanks so much!
Reply all
Reply to author
Forward
0 new messages