From d64cb233a76f57039bc6bf2007d26014a71c4b32 Mon Sep 17 00:00:00 2001 From: Henrik Kirk Date: Tue, 27 Sep 2016 21:15:13 +0200 Subject: [PATCH] Updated to scalatags 0.6.0 --- .../main/MainJSApp.scala | 12 +- .../mithril/MithrilBundle.scala | 282 ++++++++++-------- .../mithril/SvgTags.scala | 154 +++++----- .../solarsystemscalemodel/mithril/Tags.scala | 164 +++++----- .../solarsystemscalemodel/mithril/Tags2.scala | 72 ++--- build.sbt | 2 +- 6 files changed, 369 insertions(+), 317 deletions(-) diff --git a/base/src/main/scala/solarsystemscalemodel/main/MainJSApp.scala b/base/src/main/scala/solarsystemscalemodel/main/MainJSApp.scala index 74c4c8b..fdbed61 100644 --- a/base/src/main/scala/solarsystemscalemodel/main/MainJSApp.scala +++ b/base/src/main/scala/solarsystemscalemodel/main/MainJSApp.scala @@ -1,12 +1,12 @@ + package solarsystemscalemodel.main import org.scalajs.dom.Element -import solarsystemscalemodel.core.{UOM, MeasurementSystem, Distance, ModelSolarSystem} import solarsystemscalemodel.core.ModelSolarSystem._ +import solarsystemscalemodel.core.{Distance, MeasurementSystem, ModelSolarSystem, UOM} import scala.scalajs.js import scala.scalajs.js.annotation.{JSExport, JSName} -import scalatags.Text.short /** * Renders a ModelSolarSystem.Model to a virtual DOM using Mithril. @@ -56,9 +56,8 @@ object MainJSApp extends js.JSApp { def isSun = name == "Sun" } import solarsystemscalemodel.mithril.MithrilBundle.attrs._ - import solarsystemscalemodel.mithril.MithrilBundle.short._ - import solarsystemscalemodel.mithril.MithrilBundle.tags._ - import solarsystemscalemodel.mithril.MithrilBundle.short.SeqFrag + import solarsystemscalemodel.mithril.MithrilBundle.short.{SeqFrag, _} + @JSExport def view() = { def createDistanceInput(planet:CelestialBody, setting:Measurement, distance:Distance) = { @@ -119,7 +118,7 @@ object MainJSApp extends js.JSApp { }, state.model.measurementSystem.units.map { unit => option(value:=unit.name,unit.name) }) } - + def textInput(distanceInput:DistanceInput) = { val onInputFunction = { (event: js.Dynamic) => { val text = event.target.value.asInstanceOf[String] @@ -138,3 +137,4 @@ object MainJSApp extends js.JSApp { } } + diff --git a/base/src/main/scala/solarsystemscalemodel/mithril/MithrilBundle.scala b/base/src/main/scala/solarsystemscalemodel/mithril/MithrilBundle.scala index 155450d..d854a47 100644 --- a/base/src/main/scala/solarsystemscalemodel/mithril/MithrilBundle.scala +++ b/base/src/main/scala/solarsystemscalemodel/mithril/MithrilBundle.scala @@ -1,18 +1,18 @@ package solarsystemscalemodel.mithril +import scala.language.implicitConversions import scala.scalajs.js -import scala.scalajs.js.{Dictionary} -import scalatags.stylesheet.{StyleSheetFrag, Cls} -import scalatags.{Companion, DataConverters} +import scala.scalajs.js.{Dictionary, Function} import scalatags.generic._ -import scala.language.implicitConversions - -//A Mithril implementation of scalatags (based on the scalatags DOM implemention) +import scalatags.stylesheet.{Cls, StyleSheetFrag} +import scalatags.{Companion, DataConverters, Escaping} /** - * A mutable datastructure which represents an html element - */ + * A Mithril implementation of scalatags (based on the scalatags DOM implemention) + * + * A mutable datastructure which represents an html element + */ class MithrilBuilder(uri:String, tag:String) { private val attributes = Dictionary.empty[js.Any] @@ -64,6 +64,130 @@ object MithrilElement { object MithrilBundle extends Bundle[MithrilBuilder, MithrilElement, MithrilNode] with Aliases[MithrilBuilder, MithrilElement, MithrilNode]{ + trait MithrilAttributes extends Util { + //A mithril specific attribute used to ensure the correct elements are altered when elements are removed or added + val key = attr("key") + //A mithril specific attribute which provide a hook into element creation on the dom + val config = attr("config") + } + + trait Aggregate extends scalatags.generic.Aggregate[MithrilBuilder, MithrilElement, MithrilNode]{ + type StringFrag = MithrilBundle.StringFrag + type RawFrag = MithrilBundle.RawFrag + type HtmlTag = MithrilBundle.TypedTag[MithrilElement] + type SvgTag = MithrilBundle.TypedTag[MithrilElement] + type Tag = MithrilBundle.TypedTag[MithrilElement] + val RawFrag = MithrilBundle.RawFrag + val StringFrag = MithrilBundle.StringFrag + val HtmlTag = MithrilBundle.TypedTag + val SvgTag = MithrilBundle.TypedTag + val Tag = MithrilBundle.TypedTag + + def StyleFrag(s: StylePair[MithrilBuilder, _]): StyleSheetFrag = ??? + + def ClsModifier(s: Cls): Modifier = ??? + + def genericAttr[T] = new MithrilBundle.GenericAttr[T] + + def genericStyle[T] = new MithrilBundle.GenericStyle[T] + + def genericPixelStyle[T](implicit ev: StyleValue[T]): PixelStyleValue[T] = new MithrilBundle.GenericPixelStyle[T](ev) + + def genericPixelStylePx[T](implicit ev: StyleValue[String]): PixelStyleValue[T] = new MithrilBundle.GenericPixelStylePx[T](ev) + + implicit def stringFrag(v: String): StringFrag = new MithrilBundle.StringFrag(v) + + def raw(s: String) = RawFrag(s) + } + + trait TagFactory extends scalatags.generic.Util[MithrilBuilder, MithrilElement, MithrilNode]{ + def tag(s: String, void: Boolean = false): ConcreteHtmlTag[MithrilElement] = { + typedTag[MithrilElement](s, void) + } + def typedTag[T <: MithrilElement](s: String, void: Boolean = false) + (implicit ns: Namespace): ConcreteHtmlTag[T] = { + if (!Escaping.validTag(s)) + throw new IllegalArgumentException( + s"Illegal tag name: $s is not a valid XML tag name" + ) + makeAbstractTypedTag[T](s, void, ns) + } + } + + + trait Cap extends Util with TagFactory { self => + type ConcreteHtmlTag[T <: MithrilElement] = TypedTag[T] + + protected[this] implicit def stringAttrX = new GenericAttr[String] + protected[this] implicit def stringStyleX = new GenericStyle[String] + protected[this] implicit def stringPixelStyleX = new GenericPixelStyle[String](stringStyleX) + implicit def UnitFrag(u: Unit): StringFrag = new MithrilBundle.StringFrag("") + def makeAbstractTypedTag[T <: MithrilElement](tag: String, void: Boolean, namespaceConfig: Namespace): TypedTag[T] = { + TypedTag(tag, Nil, void, namespaceConfig) + } + + implicit class SeqFrag[A](xs: Seq[A])(implicit ev: A => Frag) extends Frag { + def applyTo(t: MithrilBuilder): Unit = xs.foreach(_.applyTo(t)) + def render: MithrilElement = { + MithrilElement.fragment(xs.map(_.render)) + } + } + } + + case class StringFrag(v: String) extends MtFrag { + def render: MithrilElement = MithrilElement.text(v) + override def applyTo(builder: MithrilBuilder) { builder.appendText(v) } + } + + case class RawFrag(v: String) extends Modifier{ + def applyTo(builder: MithrilBuilder): Unit = { + builder.addRaw(v) + } + } + + class GenericAttr[T] extends AttrValue[T] { + def apply(builder: MithrilBuilder, attribute: Attr, value: T): Unit = { + builder.setAttribute(attribute.name, value.asInstanceOf[js.Any]) + } + } + + class GenericStyle[T] extends StyleValue[T] { + def apply(builder: MithrilBuilder, s: Style, v: T): Unit = { + builder.setStyleProperty(s.cssName, v.toString) + } + } + + class GenericPixelStyle[T](ev: StyleValue[T]) extends PixelStyleValue[T]{ + def apply(s: Style, v: T) = StylePair(s, v, ev) + } + + class GenericPixelStylePx[T](ev: StyleValue[String]) extends PixelStyleValue[T]{ + def apply(s: Style, v: T) = StylePair(s, v + "px", ev) + } + + case class TypedTag[+Output <: MithrilElement](tag: String = "", + modifiers: List[Seq[Modifier]], + void: Boolean = false, + namespace: Namespace) + extends scalatags.generic.TypedTag[MithrilBuilder, Output, MithrilNode] + with MtFrag { + protected[this] type Self = TypedTag[Output] + + /** + * Trivial override, not strictly necessary, but it makes IntelliJ happy... + */ + def apply(xs: Modifier*): TypedTag[Output] = { + this.copy(tag = tag, void = void, modifiers = xs :: modifiers) + } + + override def toString = render.toString + + def render: Output = { + val elem = new MithrilBuilder(namespace.uri, tag) + build(elem) + elem.build.asInstanceOf[Output] + } + } object attrs extends MithrilBundle.Cap with Attrs object tags extends MithrilBundle.Cap with solarsystemscalemodel.mithril.Tags object tags2 extends MithrilBundle.Cap with solarsystemscalemodel.mithril.Tags2 @@ -71,120 +195,38 @@ object MithrilBundle extends Bundle[MithrilBuilder, MithrilElement, MithrilNode] object styles2 extends MithrilBundle.Cap with Styles2 object svgTags extends MithrilBundle.Cap with solarsystemscalemodel.mithril.SvgTags object svgAttrs extends MithrilBundle.Cap with SvgAttrs - object implicits extends Aggregate - trait MithrilAttributes extends Util { - val key = "key".attr //A mithril specific attribute used to ensure the correct elements are altered when - //elements are removed or added - val config = "config".attr //A mithril specific attribute which provide a hook into element creation on the dom - } -object all - extends Cap - with Attrs - with Styles - with solarsystemscalemodel.mithril.Tags - with DataConverters - with Aggregate - with MithrilAttributes - with LowPriorityImplicits -object short - extends Cap - with Util - with DataConverters - with AbstractShort - with Aggregate - with MithrilAttributes - with LowPriorityImplicits{ - object * extends Cap with Attrs with Styles -} -trait Aggregate extends scalatags.generic.Aggregate[MithrilBuilder,MithrilElement,MithrilNode]{ - def StyleFrag(s: StylePair[MithrilBuilder, _]): StyleSheetFrag = ??? - def ClsModifier(s: Cls): Modifier = ??? - def genericAttr[T] = new MithrilBundle.GenericAttr[T] - def genericStyle[T] = new MithrilBundle.GenericStyle[T] - def genericPixelStyle[T](implicit ev: StyleValue[T]): PixelStyleValue[T] = new MithrilBundle.GenericPixelStyle[T](ev) - def genericPixelStylePx[T](implicit ev: StyleValue[String]): PixelStyleValue[T] = new MithrilBundle.GenericPixelStylePx[T](ev) - implicit def stringFrag(v: String) = new MithrilBundle.StringFrag(v) - val RawFrag = MithrilBundle.RawFrag - val StringFrag = MithrilBundle.StringFrag - type StringFrag = MithrilBundle.StringFrag - type RawFrag = MithrilBundle.RawFrag - def raw(s: String) = RawFrag(s) - type HtmlTag = MithrilBundle.TypedTag[MithrilElement] - val HtmlTag = MithrilBundle.TypedTag - type SvgTag = MithrilBundle.TypedTag[MithrilElement] - val SvgTag = MithrilBundle.TypedTag - type Tag = MithrilBundle.TypedTag[MithrilElement] - val Tag = MithrilBundle.TypedTag -} -trait Cap extends Util{ self => - type ConcreteHtmlTag[T <: MithrilElement] = TypedTag[T] - protected[this] implicit def stringAttrX = new GenericAttr[String] - protected[this] implicit def stringStyleX = new GenericStyle[String] - protected[this] implicit def stringPixelStyleX = new GenericPixelStyle[String](stringStyleX) - implicit def UnitFrag(u: Unit) = new MithrilBundle.StringFrag("") - def makeAbstractTypedTag[T <: MithrilElement](tag: String, void: Boolean, namespaceConfig: Namespace): TypedTag[T] = { - TypedTag(tag, Nil, void, namespaceConfig) - } - implicit class SeqFrag[A <% Frag](xs: Seq[A]) extends Frag { - def applyTo(t: MithrilBuilder): Unit = xs.foreach(_.applyTo(t)) - def render: MithrilElement = { - MithrilElement.fragment(xs.map(_.render)) - } - } -} -object StringFrag extends Companion[StringFrag] -case class StringFrag(v: String) extends MtFrag { - def render: MithrilElement = MithrilElement.text(v) - override def applyTo(builder: MithrilBuilder) { builder.appendText(v) } -} -object RawFrag extends Companion[RawFrag] -case class RawFrag(v: String) extends Modifier{ - def applyTo(builder: MithrilBuilder): Unit = { - builder.addRaw(v) - } -} -class GenericAttr[T] extends AttrValue[T]{ - def apply(builder:MithrilBuilder, attribute: Attr, value: T): Unit = { - builder.setAttribute(attribute.name, value.asInstanceOf[js.Any]) - } -} -class GenericStyle[T] extends StyleValue[T]{ - def apply(builder:MithrilBuilder, s: Style, v: T): Unit = { - builder.setStyleProperty(s.cssName, v.toString) + + object implicits extends Aggregate with DataConverters + + object all + extends Cap + with Attrs + with Styles + with solarsystemscalemodel.mithril.Tags + with DataConverters + with Aggregate + with MithrilAttributes + with LowPriorityImplicits + + object short + extends Cap + with DataConverters + with solarsystemscalemodel.mithril.Tags + with AbstractShort + with Aggregate + with MithrilAttributes + with LowPriorityImplicits{ + + object * extends Cap with Attrs with Styles } -} -class GenericPixelStyle[T](ev: StyleValue[T]) extends PixelStyleValue[T]{ - def apply(s: Style, v: T) = StylePair(s, v, ev) -} -class GenericPixelStylePx[T](ev: StyleValue[String]) extends PixelStyleValue[T]{ - def apply(s: Style, v: T) = StylePair(s, v + "px", ev) -} -case class TypedTag[+Output <: MithrilElement](tag: String = "", - modifiers: List[Seq[Modifier]], - void: Boolean = false, - namespace: Namespace) - extends scalatags.generic.TypedTag[MithrilBuilder, Output, MithrilNode] - with MtFrag { - protected[this] type Self = TypedTag[Output] - def render: Output = { - val elem = new MithrilBuilder(namespace.uri, tag) - build(elem) - elem.build.asInstanceOf[Output] - } - - /** - * Trivial override, not strictly necessary, but it makes IntelliJ happy... - */ - def apply(xs: Modifier*): TypedTag[Output] = { - this.copy(tag = tag, void = void, modifiers = xs :: modifiers) - } - override def toString = render.toString -} + + object StringFrag extends Companion[StringFrag] + object RawFrag extends Companion[RawFrag] } trait LowPriorityImplicits { - implicit def bindJsAnyLike[T <% js.Function] = new scalatags.generic.AttrValue[MithrilBuilder, T]{ - def apply(builder: MithrilBuilder, a: scalatags.generic.Attr, f: T): Unit = { - builder.setAttribute(a.name, f) - } + implicit def bindJsAnyLike[T](implicit ev$1: T => Function) = new scalatags.generic.AttrValue[MithrilBuilder, T]{ + def apply(builder: MithrilBuilder, a: scalatags.generic.Attr, f: T): Unit = { + builder.setAttribute(a.name, f) } + } } \ No newline at end of file diff --git a/base/src/main/scala/solarsystemscalemodel/mithril/SvgTags.scala b/base/src/main/scala/solarsystemscalemodel/mithril/SvgTags.scala index f3223a2..2e1e5ed 100644 --- a/base/src/main/scala/solarsystemscalemodel/mithril/SvgTags.scala +++ b/base/src/main/scala/solarsystemscalemodel/mithril/SvgTags.scala @@ -1,81 +1,83 @@ package solarsystemscalemodel.mithril +import solarsystemscalemodel.mithril.MithrilBundle.TagFactory + import scalatags.generic -trait SvgTags extends generic.SvgTags[MithrilBuilder, MithrilElement, MithrilNode]{ - val altglyph = "altglyph".tag - val altglyphdef = "altglyphdef".tag - val altglyphitem = "altglyphitem".tag - val animate = "animate".tag - val animatemotion = "animatemotion".tag - val animatetransform = "animatetransform".tag - val circle = "circle".tag - val clippath = "clippath".tag - val `color-profile` = "color-profile".tag - val cursor = "cursor".tag - val defs = "defs".tag - val desc = "desc".tag - val ellipse = "ellipse".tag - val feblend = "feblend".tag - val fecolormatrix = "fecolormatrix".tag - val fecomponenttransfer = "fecomponenttransfer".tag - val fecomposite = "fecomposite".tag - val feconvolvematrix = "feconvolvematrix".tag - val fediffuselighting = "fediffuselighting".tag - val fedisplacementmap = "fedisplacementmap".tag - val fedistantlighting = "fedistantlighting".tag - val feflood = "feflood".tag - val fefunca = "fefunca".tag - val fefuncb = "fefuncb".tag - val fefuncg = "fefuncg".tag - val fefuncr = "fefuncr".tag - val fegaussianblur = "fegaussianblur".tag - val feimage = "feimage".tag - val femerge = "femerge".tag - val femergenode = "femergenode".tag - val femorphology = "femorphology".tag - val feoffset = "feoffset".tag - val fepointlight = "fepointlight".tag - val fespecularlighting = "fespecularlighting".tag - val fespotlight = "fespotlight".tag - val fetile = "fetile".tag - val feturbulance = "feturbulance".tag - val filter = "filter".tag - val font = "font".tag - val `font-face` = "font-face".tag - val `font-face-format` = "font-face-format".tag - val `font-face-name` = "font-face-name".tag - val `font-face-src` = "font-face-src".tag - val `font-face-uri` = "font-face-uri".tag - val foreignobject = "foreignobject".tag - val g = "g".tag - val glyph = "glyph".tag - val glyphref = "glyphref".tag - val hkern = "hkern".tag - val image = "image".tag - val line = "line".tag - val lineargradient = "lineargradient".tag - val marker = "marker".tag - val mask = "mask".tag - val metadata = "metadata".tag - val `missing-glyph` = "missing-glyph".tag - val mpath = "mpath".tag - val path = "path".tag - val pattern = "pattern".tag - val polygon = "polygon".tag - val polyline = "polyline".tag - val radialgradient = "radialgradient".tag - val rect = "rect".tag - val set = "set".tag - val stop = "stop".tag - val svg = "svg".tag - val switch = "switch".tag - val symbol = "symbol".tag - val text = "text".tag - val textpath = "textpath".tag - val tref = "tref".tag - val tspan = "tspan".tag - val use = "use".tag - val view = "view".tag - val vkern = "vkern".tag +trait SvgTags extends generic.SvgTags[MithrilBuilder, MithrilElement, MithrilNode] with TagFactory { + val altGlyph = typedTag[MithrilElement]("altglyph") + val altGlyphDef = typedTag[MithrilElement]("altglyphdef") + val altGlyphItem = typedTag[MithrilElement]("altglyphitem") + val animate = typedTag[MithrilElement]("animate") + val animateMotion = typedTag[MithrilElement]("animatemotion") + val animateTransform = typedTag[MithrilElement]("animatetransform") + val circle = typedTag[MithrilElement]("circle") + val clipPath = typedTag[MithrilElement]("clippath") + val `color-profile` = typedTag[MithrilElement]("color-profile") + val cursor = typedTag[MithrilElement]("cursor") + val defs = typedTag[MithrilElement]("defs") + val desc = typedTag[MithrilElement]("desc") + val ellipse = typedTag[MithrilElement]("ellipse") + val feBlend = typedTag[MithrilElement]("feblend") + val feColorMatrix = typedTag[MithrilElement]("fecolormatrix") + val feComponentTransfer = typedTag[MithrilElement]("fecomponenttransfer") + val feComposite = typedTag[MithrilElement]("fecomposite") + val feConvolveMatrix = typedTag[MithrilElement]("feconvolvematrix") + val feDiffuseLighting = typedTag[MithrilElement]("fediffuselighting") + val feDisplacementMap = typedTag[MithrilElement]("fedisplacementmap") + val feDistantLighting = typedTag[MithrilElement]("fedistantlighting") + val feFlood = typedTag[MithrilElement]("feflood") + val feFuncA = typedTag[MithrilElement]("fefunca") + val feFuncB = typedTag[MithrilElement]("fefuncb") + val feFuncG = typedTag[MithrilElement]("fefuncg") + val feFuncR = typedTag[MithrilElement]("fefuncr") + val feGaussianBlur = typedTag[MithrilElement]("fegaussianblur") + val feImage = typedTag[MithrilElement]("feimage") + val feMerge = typedTag[MithrilElement]("femerge") + val feMergeNode = typedTag[MithrilElement]("femergenode") + val feMorphology = typedTag[MithrilElement]("femorphology") + val feOffset = typedTag[MithrilElement]("feoffset") + val fePointLight = typedTag[MithrilElement]("fepointlight") + val feSpecularLighting = typedTag[MithrilElement]("fespecularlighting") + val feSpotlight = typedTag[MithrilElement]("fespotlight") + val feTile = typedTag[MithrilElement]("fetile") + val feTurbulance = typedTag[MithrilElement]("feturbulance") + val filter = typedTag[MithrilElement]("filter") + val font = typedTag[MithrilElement]("font") + val `font-face` = typedTag[MithrilElement]("font-face") + val `font-face-format` = typedTag[MithrilElement]("font-face-format") + val `font-face-name` = typedTag[MithrilElement]("font-face-name") + val `font-face-src` = typedTag[MithrilElement]("font-face-src") + val `font-face-uri` = typedTag[MithrilElement]("font-face-uri") + val foreignObject = typedTag[MithrilElement]("foreignobject") + val g = typedTag[MithrilElement]("g") + val glyph = typedTag[MithrilElement]("glyph") + val glyphRef = typedTag[MithrilElement]("glyphref") + val hkern = typedTag[MithrilElement]("hkern") + val image = typedTag[MithrilElement]("image") + val line = typedTag[MithrilElement]("line") + val linearGradient = typedTag[MithrilElement]("lineargradient") + val marker = typedTag[MithrilElement]("marker") + val mask = typedTag[MithrilElement]("mask") + val metadata = typedTag[MithrilElement]("metadata") + val `missing-glyph` = typedTag[MithrilElement]("missing-glyph") + val mpath = typedTag[MithrilElement]("mpath") + val path = typedTag[MithrilElement]("path") + val pattern = typedTag[MithrilElement]("pattern") + val polygon = typedTag[MithrilElement]("polygon") + val polyline = typedTag[MithrilElement]("polyline") + val radialGradient = typedTag[MithrilElement]("radialgradient") + val rect = typedTag[MithrilElement]("rect") + val set = typedTag[MithrilElement]("set") + val stop = typedTag[MithrilElement]("stop") + val svg = typedTag[MithrilElement]("svg") + val switch = typedTag[MithrilElement]("switch") + val symbol = typedTag[MithrilElement]("symbol") + val text = typedTag[MithrilElement]("text") + val textPath = typedTag[MithrilElement]("textpath") + val tref = typedTag[MithrilElement]("tref") + val tspan = typedTag[MithrilElement]("tspan") + val use = typedTag[MithrilElement]("use") + val view = typedTag[MithrilElement]("view") + val vkern = typedTag[MithrilElement]("vkern") } diff --git a/base/src/main/scala/solarsystemscalemodel/mithril/Tags.scala b/base/src/main/scala/solarsystemscalemodel/mithril/Tags.scala index 73646ba..961b2b7 100644 --- a/base/src/main/scala/solarsystemscalemodel/mithril/Tags.scala +++ b/base/src/main/scala/solarsystemscalemodel/mithril/Tags.scala @@ -1,94 +1,98 @@ package solarsystemscalemodel.mithril -//A Mithril implementation of scalatags (based on the scalatags DOM implemention) -trait Tags extends scalatags.generic.Tags[MithrilBuilder, MithrilElement, MithrilNode] { +import solarsystemscalemodel.mithril.MithrilBundle.TagFactory + +/** + * A Mithril implementation of scalatags (based on the scalatags DOM implemention) + */ +trait Tags extends scalatags.generic.Tags[MithrilBuilder, MithrilElement, MithrilNode] with TagFactory { // Root Element - val html = "html".tag[MithrilElement] + val html = typedTag[MithrilElement]("html") // Document Metadata - val head = "head".tag[MithrilElement] - val base = "base".voidTag[MithrilElement] - val link = "link".voidTag[MithrilElement] - val meta = "meta".voidTag[MithrilElement] + val head = typedTag[MithrilElement]("head") + val base = typedTag[MithrilElement]("base", void = true) + val link = typedTag[MithrilElement]("link", void = true) + val meta = typedTag[MithrilElement]("meta", void = true) // Scripting - val script = "script".tag[MithrilElement] + val script = typedTag[MithrilElement]("script") // Sections - val body = "body".tag[MithrilElement] - val h1 = "h1".tag[MithrilElement] - val h2 = "h2".tag[MithrilElement] - val h3 = "h3".tag[MithrilElement] - val h4 = "h4".tag[MithrilElement] - val h5 = "h5".tag[MithrilElement] - val h6 = "h6".tag[MithrilElement] - val header = "header".tag[MithrilElement] - val footer = "footer".tag[MithrilElement] + val body = typedTag[MithrilElement]("body") + val h1 = typedTag[MithrilElement]("h1") + val h2 = typedTag[MithrilElement]("h2") + val h3 = typedTag[MithrilElement]("h3") + val h4 = typedTag[MithrilElement]("h4") + val h5 = typedTag[MithrilElement]("h5") + val h6 = typedTag[MithrilElement]("h6") + val header = typedTag[MithrilElement]("header") + val footer = typedTag[MithrilElement]("footer") // Grouping content - val p = "p".tag[MithrilElement] - val hr = "hr".voidTag[MithrilElement] - val pre = "pre".tag[MithrilElement] - val blockquote = "blockquote".tag[MithrilElement] - val ol = "ol".tag[MithrilElement] - val ul = "ul".tag[MithrilElement] - val li = "li".tag[MithrilElement] - val dl = "dl".tag[MithrilElement] - val dt = "dt".tag[MithrilElement] - val dd = "dd".tag[MithrilElement] - val figure = "figure".tag[MithrilElement] - val figcaption = "figcaption".tag[MithrilElement] - val div = "div".tag[MithrilElement] + val p = typedTag[MithrilElement]("p") + val hr = typedTag[MithrilElement]("hr", void = true) + val pre = typedTag[MithrilElement]("pre") + val blockquote = typedTag[MithrilElement]("blockquote") + val ol = typedTag[MithrilElement]("ol") + val ul = typedTag[MithrilElement]("ul") + val li = typedTag[MithrilElement]("li") + val dl = typedTag[MithrilElement]("dl") + val dt = typedTag[MithrilElement]("dt") + val dd = typedTag[MithrilElement]("dd") + val figure = typedTag[MithrilElement]("figure") + val figcaption = typedTag[MithrilElement]("figcaption") + val div = typedTag[MithrilElement]("div") // Text-level semantics - val a = "a".tag[MithrilElement] - val em = "em".tag[MithrilElement] - val strong = "strong".tag[MithrilElement] - val small = "small".tag[MithrilElement] - val s = "s".tag[MithrilElement] - val cite = "cite".tag[MithrilElement] - val code = "code".tag[MithrilElement] - val sub = "sub".tag[MithrilElement] - val sup = "sup".tag[MithrilElement] - val i = "i".tag[MithrilElement] - val b = "b".tag[MithrilElement] - val u = "u".tag[MithrilElement] - val span = "span".tag[MithrilElement] - val br = "br".voidTag[MithrilElement] - val wbr = "wbr".voidTag[MithrilElement] + val a = typedTag[MithrilElement]("a") + val em = typedTag[MithrilElement]("em") + val strong = typedTag[MithrilElement]("strong") + val small = typedTag[MithrilElement]("small") + val s = typedTag[MithrilElement]("s") + val cite = typedTag[MithrilElement]("cite") + val code = typedTag[MithrilElement]("code") + val sub = typedTag[MithrilElement]("sub") + val sup = typedTag[MithrilElement]("sup") + val i = typedTag[MithrilElement]("i") + val b = typedTag[MithrilElement]("b") + val u = typedTag[MithrilElement]("u") + val span = typedTag[MithrilElement]("span") + val br = typedTag[MithrilElement]("br", void = true) + val wbr = typedTag[MithrilElement]("wbr", void = true) // Edits - val ins = "ins".tag[MithrilElement] - val del = "del".tag[MithrilElement] + val ins = typedTag[MithrilElement]("ins") + val del = typedTag[MithrilElement]("del") // Embedded content - val img = "img".voidTag[MithrilElement] - val iframe = "iframe".tag[MithrilElement] - val embed = "embed".voidTag[MithrilElement] - val `object` = "object".tag[MithrilElement] - val param = "param".voidTag[MithrilElement] - val video = "video".tag[MithrilElement] - val audio = "audio".tag[MithrilElement] - val source = "source".voidTag[MithrilElement] - val track = "track".voidTag[MithrilElement] - val canvas = "canvas".tag[MithrilElement] - val map = "map".tag[MithrilElement] - val area = "area".voidTag[MithrilElement] + val img = typedTag[MithrilElement]("img", void = true) + val iframe = typedTag[MithrilElement]("iframe") + val embed = typedTag[MithrilElement]("embed", void = true) + val `object` = typedTag[MithrilElement]("object") + val param = typedTag[MithrilElement]("param", void = true) + val video = typedTag[MithrilElement]("video") + val audio = typedTag[MithrilElement]("audio") + val source = typedTag[MithrilElement]("source", void = true) + val track = typedTag[MithrilElement]("track", void = true) + val canvas = typedTag[MithrilElement]("canvas") + val map = typedTag[MithrilElement]("map") + val area = typedTag[MithrilElement]("area", void = true) // Tabular data - val table = "table".tag[MithrilElement] - val caption = "caption".tag[MithrilElement] - val colgroup = "colgroup".tag[MithrilElement] - val col = "col".voidTag[MithrilElement] - val tbody = "tbody".tag[MithrilElement] - val thead = "thead".tag[MithrilElement] - val tfoot = "tfoot".tag[MithrilElement] - val tr = "tr".tag[MithrilElement] - val td = "td".tag[MithrilElement] - val th = "th".tag[MithrilElement] + val table = typedTag[MithrilElement]("table") + val caption = typedTag[MithrilElement]("caption") + val colgroup = typedTag[MithrilElement]("colgroup") + val col = typedTag[MithrilElement]("col", void = true) + val tbody = typedTag[MithrilElement]("tbody") + val thead = typedTag[MithrilElement]("thead") + val tfoot = typedTag[MithrilElement]("tfoot") + val tr = typedTag[MithrilElement]("tr") + val td = typedTag[MithrilElement]("td") + val th = typedTag[MithrilElement]("th") // Forms - val form = "form".tag[MithrilElement] - val fieldset = "fieldset".tag[MithrilElement] - val legend = "legend".tag[MithrilElement] - val label = "label".tag[MithrilElement] - val input = "input".voidTag[MithrilElement] - val button = "button".tag[MithrilElement] - val select = "select".tag[MithrilElement] - val datalist = "datalist".tag[MithrilElement] - val optgroup = "optgroup".tag[MithrilElement] - val option = "option".tag[MithrilElement] - val textarea = "textarea".tag[MithrilElement] + val form = typedTag[MithrilElement]("form") + val fieldset = typedTag[MithrilElement]("fieldset") + val legend = typedTag[MithrilElement]("legend") + val label = typedTag[MithrilElement]("label") + val input = typedTag[MithrilElement]("input", void = true) //.voidTag[MithrilElement] + val button = typedTag[MithrilElement]("button") + val select = typedTag[MithrilElement]("select") + val datalist = typedTag[MithrilElement]("datalist") + val optgroup = typedTag[MithrilElement]("optgroup") + val option = typedTag[MithrilElement]("option") + val textarea = typedTag[MithrilElement]("textarea") } diff --git a/base/src/main/scala/solarsystemscalemodel/mithril/Tags2.scala b/base/src/main/scala/solarsystemscalemodel/mithril/Tags2.scala index 18f6e47..7e8e903 100644 --- a/base/src/main/scala/solarsystemscalemodel/mithril/Tags2.scala +++ b/base/src/main/scala/solarsystemscalemodel/mithril/Tags2.scala @@ -1,43 +1,47 @@ package solarsystemscalemodel.mithril -//A Mithril implementation of scalatags (based on the scalatags DOM implemention) -trait Tags2 extends scalatags.generic.Tags2[MithrilBuilder,MithrilElement,MithrilNode] { - val title = "title".tag - val style = "style".tag +import solarsystemscalemodel.mithril.MithrilBundle.TagFactory + +/** + * A Mithril implementation of scalatags (based on the scalatags DOM implemention) + */ +trait Tags2 extends scalatags.generic.Tags2[MithrilBuilder, MithrilElement, MithrilNode] with TagFactory { + val title = typedTag[MithrilElement]("title") + val style = typedTag[MithrilElement]("style") // Scripting - val noscript = "noscript".tag + val noscript = typedTag[MithrilElement]("noscript") // Sections - val section = "section".tag - val nav = "nav".tag - val article = "article".tag - val aside = "aside".tag - val address = "address".tag - val main = "main".tag + val section = typedTag[MithrilElement]("section") + val nav = typedTag[MithrilElement]("nav") + val article = typedTag[MithrilElement]("article") + val aside = typedTag[MithrilElement]("aside") + val address = typedTag[MithrilElement]("address") + val main = typedTag[MithrilElement]("main") // Text level semantics - val q = "q".tag - val dfn = "dfn".tag - val abbr = "abbr".tag - val data = "data".tag - val time = "time".tag - val `var` = "var".tag - val samp = "samp".tag - val kbd = "kbd".tag - val math = "math".tag - val mark = "mark".tag - val ruby = "ruby".tag - val rt = "rt".tag - val rp = "rp".tag - val bdi = "bdi".tag - val bdo = "bdo".tag + val q = typedTag[MithrilElement]("q") + val dfn = typedTag[MithrilElement]("dfn") + val abbr = typedTag[MithrilElement]("abbr") + val data = typedTag[MithrilElement]("data") + val time = typedTag[MithrilElement]("time") + val `var` = typedTag[MithrilElement]("var") + val samp = typedTag[MithrilElement]("samp") + val kbd = typedTag[MithrilElement]("kbd") + val math = typedTag[MithrilElement]("math") + val mark = typedTag[MithrilElement]("mark") + val ruby = typedTag[MithrilElement]("ruby") + val rt = typedTag[MithrilElement]("rt") + val rp = typedTag[MithrilElement]("rp") + val bdi = typedTag[MithrilElement]("bdi") + val bdo = typedTag[MithrilElement]("bdo") // Forms - val keygen = "keygen".voidTag - val output = "output".tag - val progress = "progress".tag - val meter = "meter".tag + val keygen = typedTag[MithrilElement]("keygen", void = true) + val output = typedTag[MithrilElement]("output") + val progress = typedTag[MithrilElement]("progress") + val meter = typedTag[MithrilElement]("meter") // Interactive elements - val details = "details".tag - val summary = "summary".tag - val command = "command".voidTag - val menu = "menu".tag + val details = typedTag[MithrilElement]("details") + val summary = typedTag[MithrilElement]("summary") + val command = typedTag[MithrilElement]("command", void = true) + val menu = typedTag[MithrilElement]("menu") } diff --git a/build.sbt b/build.sbt index a920a5a..f5c1f60 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,7 @@ lazy val root = project.in(file(".")).aggregate(base, integration) lazy val base = project.in(file("base")).settings( scalaVersion := "2.11.6", - libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.5.2", + libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.6.0", libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0" % "test", testFrameworks += new TestFramework("utest.runner.Framework"), persistLauncher in Compile := true