Skip to content

Commit

Permalink
Added DontMergeClass test and fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ReviakinAleksey committed Jul 11, 2019
1 parent 823f300 commit 5597516
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 19 additions & 0 deletions core/util/src/test/scala/net/liftweb/util/CssSelectorSpec.scala
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,26 @@ object CssBindHelpersSpec extends Specification with XmlMatchers {
(res \ "@class").length must_== 0
}

"don't merge class attribute" in {
val func = "p !!" #> <span class="replacement">10</span>
val res = func.apply(<p class="first second">Test</p>)
(res \ "@class").text must_== "replacement"
}

"merge other attributes when using don't merge class modification" in {
val func = "p !!" #> <span data-two="2" class="replacement">10</span>
val res = func.apply(<p data-one="1" class="first second">Test</p>)
(res \ "@data-one").text must_== "1"
(res \ "@data-two").text must_== "2"
(res \ "@class").text must_== "replacement"
}

"leave node class attribute for replacement without class" in {
// TODO: Since was agreed not to change current behaviour, create test for it (https://groups.google.com/forum/#!topic/liftweb/Nswcxoykspc)
val func = "p !!" #> <span>10</span>
val res = func.apply(<p class="first second">Test</p>)
(res \ "@class").text must_== "first second"
}

"Remove a subnode's class attribute" in {

Expand Down
11 changes: 6 additions & 5 deletions docs/css-selectors.adoc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,15 @@ Remove from attribute rule: `[attribute-name!]`::
its own separated by a space. For example, `^ [class!]` will remove the
class named by the transformation result from all root elements.

Don't merge attributes rule: `!!`::
Don't merge class attribute rule: `!!`::
By default, if the transformation yields a single element and the element
matched by the selector is being replaced by that result, the attributes from
the matched element are merged into the attributes of the transformation's
element. This modifier prevents that from happening. For example, by default
doing `"input" #> <div />` and applying it to `<input type="text">` would
yield `<div type="text" />`. Doing `"input !!" #> <div />` would instead yield
`<div />`.
element. This modifier prevents *ONLY* class attribute merging from happening.
For example, by default doing `"input" #> <div class="c1"/>` and applying it to
`<input class="c2" type="text"/>` would yield `<div type="text" class="c1 c2"/>`.
Doing `"input !!" #> <div class="c1" />` would instead yield
`<div type="text" class="c1"/>`.

Lift node rule: `^^`::
This rule will lift the first selected element all the way to the root of the
Expand Down

0 comments on commit 5597516

Please sign in to comment.