@@ -27,7 +27,7 @@ package com.thoughtworks.binding
2727import Binding .{BindingSeq , Constants , MultiMountPoint , SingletonBindingSeq }
2828import dom .Runtime .NodeSeqMountPoint
2929import com .thoughtworks .Extractor ._
30- import com .thoughtworks .binding .XmlExtractor .{PrefixedName , UnprefixedName }
30+ import com .thoughtworks .binding .XmlExtractor .{PrefixedName , QName , UnprefixedName }
3131import com .thoughtworks .sde .core .Preprocessor
3232import macrocompat .bundle
3333import org .scalajs .dom .raw ._
@@ -39,6 +39,8 @@ import scala.language.experimental.macros
3939import scalatags .JsDom
4040import scalatags .jsdom
4141import org .scalajs .dom .document
42+ import scalatags .JsDom .TypedTag
43+ import scalatags .generic .Namespace
4244
4345import scala .collection .immutable .Queue
4446import scala .reflect .NameTransformer
@@ -140,7 +142,21 @@ object dom {
140142
141143 }
142144
143- object TagsAndTags2 extends JsDom .Cap with jsdom.Tags with jsdom.Tags2
145+ object TagsAndTags2 extends JsDom .Cap with jsdom.Tags with jsdom.Tags2 {
146+
147+ import scala .language .dynamics
148+
149+ final class DynamicDataTag private [TagsAndTags2 ] ()
150+ extends TypedTag [HTMLElement ](" data" , Nil , false , Namespace .htmlNamespaceConfig)
151+ with Dynamic {
152+ final def selectDynamic (tagName : String ): ConcreteHtmlTag [Element ] = {
153+ TagsAndTags2 .tag(tagName)
154+ }
155+ }
156+
157+ override lazy val data = new DynamicDataTag ()
158+
159+ }
144160
145161 @ inline
146162 def domBindingSeq (bindingSeq : BindingSeq [Node ]) = bindingSeq
@@ -308,7 +324,7 @@ object dom {
308324 private def transformedWithValDefs : PartialFunction [Tree , (Queue [ValDef ], Tree )] = {
309325 case tree @ NodeBuffer (children) =>
310326 nodeSeq(children)
311- case tree @ Elem (UnprefixedName (label) , attributes, _, children) =>
327+ case tree @ Elem (tag , attributes, _, children) =>
312328 val idOption = findTextAttribute(" local-id" , attributes).orElse(findTextAttribute(" id" , attributes))
313329 val elementName = idOption match {
314330 case None => TermName (c.freshName(" element" ))
@@ -323,16 +339,7 @@ object dom {
323339 }
324340 }
325341 } yield {
326- val attributeAccess = key match {
327- case UnprefixedName (localPart) =>
328- val keyName = TermName (NameTransformer .encode(localPart))
329- q """ $elementName. $keyName"""
330- case PrefixedName (prefix, localPart) =>
331- localPart.split(':' ).foldLeft(q """ $elementName. ${TermName (NameTransformer .encode(prefix))}""" ) {
332- (prefixExpr, propertyName) =>
333- q """ $prefixExpr. ${TermName (NameTransformer .encode(propertyName))}"""
334- }
335- }
342+ val attributeAccess = propertyAccess(key, q " $elementName" )
336343
337344 atPos(value.pos) {
338345 value match {
@@ -381,8 +388,10 @@ object dom {
381388 """
382389 })
383390 }
384- val elementDef =
385- q " val $elementName = _root_.com.thoughtworks.binding.dom.Runtime.TagsAndTags2. ${TermName (label)}.render "
391+
392+ val tagAccess = propertyAccess(tag, q " _root_.com.thoughtworks.binding.dom.Runtime.TagsAndTags2 " )
393+
394+ val elementDef = q " val $elementName = $tagAccess.render "
386395 idOption match {
387396 case None =>
388397 valDefs -> q """
@@ -405,6 +414,18 @@ object dom {
405414 attributes.collectFirst { case (UnprefixedName (`unprefixedName`), Text (text)) => text }
406415 }
407416
417+ private def propertyAccess (xmlName : QName , objectAccess : RefTree ): Select = {
418+ xmlName match {
419+ case UnprefixedName (localPart) =>
420+ q " $objectAccess. ${TermName (NameTransformer .encode(localPart))}"
421+ case PrefixedName (prefix, localPart) =>
422+ localPart.split(':' ).foldLeft(q " $objectAccess. ${TermName (NameTransformer .encode(prefix))}" ) {
423+ (prefixExpr, segmentName) =>
424+ q " $prefixExpr. ${TermName (NameTransformer .encode(segmentName))}"
425+ }
426+ }
427+ }
428+
408429 private def transformed : PartialFunction [Tree , Tree ] = {
409430 case Block (stats, expr) =>
410431 super .transform(Block (stats.flatMap {
0 commit comments