-
-
Save Centaur/5010462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val _jqueryCssSelectRegex = """(^\S)+""".r | |
private val _matchChar = Set('*', '[', '^', '-') | |
def sel(exp: String, content: NodeSeq): CssSel = { | |
val selects = _jqueryCssSelectRegex.findAllMatchIn(exp).map(_.matched).toList | |
val (init, last) = | |
if (_matchChar.contains(selects.last.head)) | |
selects.dropRight(2) -> selects.takeRight(2).mkString(" ") | |
else | |
selects.dropRight(1) -> selects.takeRight(1).mkString | |
init.foldRight(last #> content)((exp, cssSel) => exp #> cssSel) | |
} | |
implicit final class TsStringToCssSel(exp: String) { | |
def #>>(content: NodeSeq): CssSel = | |
H.sel(exp, content) | |
def #>>[V <: AnyVal](value: V): CssSel = | |
H.sel(exp, Text(value.toString)) | |
def #>>(value: String): CssSel = | |
H.sel(exp, Text(value)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment