Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: allow for customSheetName to be an empty string #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions scalatags/src/scalatags/stylesheet/StyleSheet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class CascadingStyleSheet(implicit sourceName: sourcecode.FullName) ext
abstract class StyleSheet(implicit sourceName: sourcecode.FullName){
/**
* The name of this CSS stylesheet. Defaults to the name of the trait,
* but you can override
* but you can override.
*/
def customSheetName: Option[String] = None

Expand All @@ -30,7 +30,12 @@ abstract class StyleSheet(implicit sourceName: sourcecode.FullName){
* any applicable pseudo-selectors into the name of the CSS class.
*/
protected[this] def nameFor(memberName: String, pseudoSelectors: String) = {
customSheetName.getOrElse(defaultSheetName.replace(".", "-")) + "-" + memberName + pseudoSelectors
val baseSuffix = memberName + pseudoSelectors
customSheetName match {
case Some("") => baseSuffix
case Some(value) => value + "-" + baseSuffix
case None => defaultSheetName.replace(".", "-") + "-" + baseSuffix
}
}

/**
Expand Down
24 changes: 24 additions & 0 deletions scalatags/test/src/scalatags/generic/StyleSheetTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,18 @@ abstract class StyleSheetTests[Builder, Output <: FragT, FragT]
def y = cls.hover(
opacity := 0.5
)

}

object CustomEmpty extends CascadingStyleSheet{
initStyleSheet()

override def customSheetName = Some("")
val x = cls(
backgroundColor := "red",
height := 125
)
}

def check(txt: String, expected: String) = {
// augmentString = work around scala/bug#11125 on JDK 11
Expand Down Expand Up @@ -181,6 +191,7 @@ abstract class StyleSheetTests[Builder, Output <: FragT, FragT]
"""
)
}

test("defs"){
check(
Defs.styleSheetText,
Expand All @@ -192,9 +203,22 @@ abstract class StyleSheetTests[Builder, Output <: FragT, FragT]
.$pkg-Defs-y:hover{
opacity: 0.5;
}
"""
)
}

test("customEmpty"){
check(
CustomEmpty.styleSheetText,
s"""
.x{
background-color: red;
height: 125px;
}
"""
)
}

test("failure"){
test("noDirectInstantiation"){
// This doesn't seem to work, even though that snippet does indeed
Expand Down