Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a cross platform scala project using the sbt build tool. It is a code generator which, given an appropriate definition of htmls attributes (in the `shared\src\main\scala\com\raquo\domtypes`sub directory) generates code which, once published, may be consumed by a downstream party library (for example laminar) to manipulate / use DOM attributes in scala JS.

You may run code generation with the `sbt test` task. Note the generated code becomes available here - `js\src\test\scala\com\thirdparty\defs`.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
with:
node-version: "18"
- name: Setup JVM
uses: actions/setup-java@v3
uses: coursier/setup-action@v1
with:
java-version: '11'
distribution: 'adopt'
jvm: 'adopt:11'
apps: sbt
- name: Run tests
run: sbt "project domtypesJVM" test "project domtypesJS" +test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ js/yarn.lock
.idea

.DS_Store

.vscode/settings.json
.bloop
.metals
metals.sbt
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run sbt",
"type": "shell",
"command": "cs launch sbt --jvm 11",
"presentation": {
"reveal": "always",
"panel": "new"
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import VersionHelper.{versionFmt, fallbackVersion}

// Lets me depend on Maven Central artifacts immediately without waiting
resolvers ++= Resolver.sonatypeOssRepos("public")
ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("public")
ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("snapshots")


// Makes sure to increment the version for local development
ThisBuild / version := dynverGitDescribeOutput.value
Expand All @@ -12,6 +14,8 @@ ThisBuild / dynver := {
sbtdynver.DynVer
.getGitDescribeOutput(d)
.mkVersion(out => versionFmt(out, dynverSonatypeSnapshots.value), fallbackVersion(d))


}

(ThisBuild / scalaVersion) := Versions.Scala_2_12
Expand Down
10 changes: 10 additions & 0 deletions js/src/test/scala/com/thirdparty/CompileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.thirdparty.tags.HtmlTag
import org.scalajs.dom
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import com.thirdparty.defs.tags.MathMlTags

class CompileSpec extends AnyFunSpec with Matchers {

Expand Down Expand Up @@ -49,6 +50,10 @@ class CompileSpec extends AnyFunSpec with Matchers {
with SvgAttrs
with ComplexSvgKeys

object mathMl
extends MathMlTags


object aria
extends AriaAttrs

Expand Down Expand Up @@ -99,6 +104,11 @@ class CompileSpec extends AnyFunSpec with Matchers {
assert(svg.xlinkHref.qualifiedName == "xlink:href")
assert(SvgAttr.namespaceUrl(svg.xlinkHref.namespace.get) == "http://www.w3.org/1999/xlink")

// MathML

assert(mathMl.mathTag.domName == "math")
assert(mathMl.mi.domName == "mi")

// Aliases

assert(html.typ == html.`type`)
Expand Down
233 changes: 233 additions & 0 deletions js/src/test/scala/com/thirdparty/defs/tags/MathMlTags.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
package com.thirdparty.defs.tags

import com.thirdparty.tags.MathMlTag
import org.scalajs.dom

// #NOTE: GENERATED CODE
// - This file is generated at compile time from the data in Scala DOM Types
// - See `GeneratorSpec.scala` for code generation params
// - Contribute to https://github.com/raquo/scala-dom-types to add missing tags / attrs / props / etc.

trait MathMlTags {


def mathMlTag[El <: dom.MathMLElement](name: String): MathMlTag[El] = new MathMlTag(name)


/**
* The <annotation> MathML element is used to include annotations for a MathML expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/annotation annotation @ MDN]]
*/
lazy val annotation: MathMlTag[dom.MathMLElement] = mathMlTag("annotation")


/**
* The top-level element in MathML, representing a mathematical expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math math @ MDN]]
*/
lazy val mathTag: MathMlTag[dom.MathMLElement] = mathMlTag("math")


/**
* The <merror> MathML element is used to display an error message in a mathematical expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/merror merror @ MDN]]
*/
lazy val merror: MathMlTag[dom.MathMLElement] = mathMlTag("merror")


/**
* Represents a fraction.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfrac mfrac @ MDN]]
*/
lazy val mfrac: MathMlTag[dom.MathMLElement] = mathMlTag("mfrac")


/**
* Represents a mathematical identifier, such as a variable name.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mi mi @ MDN]]
*/
lazy val mi: MathMlTag[dom.MathMLElement] = mathMlTag("mi")


/**
* The <mmultiscripts> MathML element allows the specification of prescripts and postscripts to a base.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mmultiscripts mmultiscripts @ MDN]]
*/
lazy val mmultiscripts: MathMlTag[dom.MathMLElement] = mathMlTag("mmultiscripts")


/**
* Represents a number in a mathematical expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mn mn @ MDN]]
*/
lazy val mn: MathMlTag[dom.MathMLElement] = mathMlTag("mn")


/**
* Represents a mathematical operator.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo mo @ MDN]]
*/
lazy val mo: MathMlTag[dom.MathMLElement] = mathMlTag("mo")


/**
* The <mover> MathML element is used to attach an accent or a limit over an expression. It uses the following syntax: <mover> base overscript </mover>
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mover mover @ MDN]]
*/
lazy val mover: MathMlTag[dom.MathMLElement] = mathMlTag("mover")


/**
* The <mphantom> MathML element is used to hide its content, while still affecting the layout of the expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mphantom mphantom @ MDN]]
*/
lazy val mphantom: MathMlTag[dom.MathMLElement] = mathMlTag("mphantom")


/**
* The <mprescripts> MathML element is used to specify prescripts in a <mmultiscripts> element.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mprescripts mprescripts @ MDN]]
*/
lazy val mprescripts: MathMlTag[dom.MathMLElement] = mathMlTag("mprescripts")


/**
* Represents a root expression with a specified degree.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mroot mroot @ MDN]]
*/
lazy val mroot: MathMlTag[dom.MathMLElement] = mathMlTag("mroot")


/**
* The <mrow> MathML element is used to group sub-expressions, representing them horizontally.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mrow mrow @ MDN]]
*/
lazy val mrow: MathMlTag[dom.MathMLElement] = mathMlTag("mrow")


/**
* Represents a string literal.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/ms ms @ MDN]]
*/
lazy val ms: MathMlTag[dom.MathMLElement] = mathMlTag("ms")


/**
* The <mspace> MathML element is used to display a blank space, whose size is set by its attributes.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mspace mspace @ MDN]]
*/
lazy val mspace: MathMlTag[dom.MathMLElement] = mathMlTag("mspace")


/**
* Represents a square root expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msqrt msqrt @ MDN]]
*/
lazy val msqrt: MathMlTag[dom.MathMLElement] = mathMlTag("msqrt")


/**
* The <mstyle> MathML element is used to change the style of its contents. It is similar to the <style> element in HTML.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mstyle mstyle @ MDN]]
*/
lazy val mstyle: MathMlTag[dom.MathMLElement] = mathMlTag("mstyle")


/**
* Represents a subscript expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msub msub @ MDN]]
*/
lazy val msub: MathMlTag[dom.MathMLElement] = mathMlTag("msub")


/**
* Represents a base with both a subscript and a superscript.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msubsup msubsup @ MDN]]
*/
lazy val msubsup: MathMlTag[dom.MathMLElement] = mathMlTag("msubsup")


/**
* Represents a superscript expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msup msup @ MDN]]
*/
lazy val msup: MathMlTag[dom.MathMLElement] = mathMlTag("msup")


/**
* The <mtable> MathML element allows you to create tables or matrices. Its children are <mtr> elements (representing rows), each of them having <mtd> elements as its children (representing cells). These elements are similar to <table>, <tr> and <td> elements of HTML.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtable mtable @ MDN]]
*/
lazy val mtable: MathMlTag[dom.MathMLElement] = mathMlTag("mtable")


/**
* The <mtd> MathML element represents a cell in a table or a matrix. It may only appear in an <mtr> element.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtd mtd @ MDN]]
*/
lazy val mtd: MathMlTag[dom.MathMLElement] = mathMlTag("mtd")


/**
* Represents text within a mathematical expression.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtext mtext @ MDN]]
*/
lazy val mtext: MathMlTag[dom.MathMLElement] = mathMlTag("mtext")


/**
* The <mtr> MathML element represents a row in a table or a matrix. It may only appear in a <mtable> element and its children are <mtd> elements representing cells. This element is similar to the <tr> element of HTML.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtr mtr @ MDN]]
*/
lazy val mtr: MathMlTag[dom.MathMLElement] = mathMlTag("mtr")


/**
* The <munder> MathML element is used to attach an accent or a limit under an expression. It uses the following syntax: <munder> base underscript </munder>
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munder munder @ MDN]]
*/
lazy val munder: MathMlTag[dom.MathMLElement] = mathMlTag("munder")


/**
* The <munder> MathML element is used to attach an accent or a limit under an expression. It uses the following syntax: <munder> base underscript </munder>
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munderover munderover @ MDN]]
*/
lazy val munderover: MathMlTag[dom.MathMLElement] = mathMlTag("munderover")


/**
* The <semantics> MathML element is used to annotate a MathML expression with additional information, such as its meaning or its presentation.
*
* [[https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics semantics @ MDN]]
*/
lazy val semantics: MathMlTag[dom.MathMLElement] = mathMlTag("semantics")


}
4 changes: 4 additions & 0 deletions js/src/test/scala/com/thirdparty/tags/Tag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ case class HtmlTag[El <: dom.html.Element](
case class SvgTag[El <: dom.svg.Element](
override val domName: String
) extends Tag[El]

case class MathMlTag[El <: dom.MathMLElement](
override val domName: String
) extends Tag[dom.MathMLElement]
27 changes: 26 additions & 1 deletion jvm/src/test/scala/com/raquo/domtypes/GeneratorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.raquo.domtypes

import com.raquo.domtypes.codegen.DefType.LazyVal
import com.raquo.domtypes.codegen._
import com.raquo.domtypes.common.{HtmlTagType, SvgTagType}
import com.raquo.domtypes.common.{HtmlTagType, SvgTagType, MathMlTagType}
import com.raquo.domtypes.defs.styles.StyleTraitDefs
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
Expand Down Expand Up @@ -90,6 +90,31 @@ class GeneratorSpec extends AnyFunSpec with Matchers {
)
}

it("Generate MathMl tags") {
println("=== MATHML TAGS ===")

val traitName = "MathMlTags"

val fileContent = generator.generateTagsTrait(
tagType = MathMlTagType,
defGroups = defGroups.mathMlTagsDefGroups,
printDefGroupComments = false,
traitCommentLines = Nil,
traitModifiers = Nil,
traitName = traitName,
keyKind = "MathMlTag",
baseImplDefComments = Nil,
keyImplName = "mathMlTag",
defType = LazyVal
)

generator.writeToFile(
packagePath = generator.tagDefsPackagePath,
fileName = traitName,
fileContent = fileContent
)
}

it("Generate HTML attributes ") {
println("=== HTML ATTRS ===")

Expand Down
3 changes: 1 addition & 2 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ object Versions {
val Scala_3 = "3.3.3"

// -- Dependencies --

val ScalaJsDom = "2.8.0"
val ScalaJsDom = "2.8.1"

// -- Test --

Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.9.7
sbt.version = 1.10.6
Loading