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

Fix pseudo elements and classes not resolving when chained with each #146

Merged
merged 5 commits into from
Jul 25, 2016
Merged
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
2 changes: 1 addition & 1 deletion src/Css/Preprocess/Resolve.elm
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ applyMixins mixins declarations =
applyNestedMixinsToLast
nestedMixins
rest
(Structure.appendToLastSelector selector)
(Structure.appendRepeatableToLastSelector selector)
declarations

(NestSnippet selectorCombinator snippets) :: rest ->
Expand Down
27 changes: 14 additions & 13 deletions src/Css/Structure.elm
Original file line number Diff line number Diff line change
Expand Up @@ -245,34 +245,35 @@ extendLastSelector selector declarations =
first :: extendLastSelector selector rest


appendToLastSelector : RepeatableSimpleSelector -> StyleBlock -> List StyleBlock
appendToLastSelector selector styleBlock =
appendToLastSelector : (Selector -> Selector) -> StyleBlock -> List StyleBlock
appendToLastSelector f styleBlock =
case styleBlock of
StyleBlock only [] properties ->
[ StyleBlock only [] properties
, StyleBlock (appendRepeatableSelector selector only) [] []
, StyleBlock (f only) [] []
]

StyleBlock first rest properties ->
let
newRest =
mapLast (appendRepeatableSelector selector) rest
List.map f rest

newFirst =
f first
in
[ StyleBlock first rest properties
, StyleBlock first newRest []
, StyleBlock newFirst newRest []
]


appendRepeatableToLastSelector : RepeatableSimpleSelector -> StyleBlock -> List StyleBlock
appendRepeatableToLastSelector selector styleBlock =
appendToLastSelector (appendRepeatableSelector selector) styleBlock


appendPseudoElementToLastSelector : PseudoElement -> StyleBlock -> List StyleBlock
appendPseudoElementToLastSelector pseudo styleBlock =
case styleBlock of
StyleBlock only [] properties ->
[ StyleBlock only [] properties
, StyleBlock (applyPseudoElement pseudo only) [] []
]

a ->
[ a ]
appendToLastSelector (applyPseudoElement pseudo) styleBlock


applyPseudoElement : PseudoElement -> Selector -> Selector
Expand Down
14 changes: 14 additions & 0 deletions test/Fixtures.elm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ bug99 =
]


bug140 : Stylesheet
bug140 =
stylesheet
[ each [ input, select, selector "textarea"]
[ focus
[ borderColor (hex "#000000")
]
, after
[ color (hex "#aaaaaa")
]
]
]


simpleEach : Stylesheet
simpleEach =
stylesheet
Expand Down
28 changes: 28 additions & 0 deletions test/Tests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ all =
, atRule
, nestedAtRule
, bug99
, bug140
, universal
, multiSelector
, multiDescendent
Expand Down Expand Up @@ -210,6 +211,33 @@ nestedAtRule =
]


{-| Regression test for https://github.com/rtfeldman/elm-css/issues/140
-}
bug140 : Test
bug140 =
let
input =
Fixtures.bug140

output =
"""
input:focus, select:focus, textarea:focus {
border-color: #000000;
}
input::after, select::after, textarea::after {
color: #aaaaaa;
}
"""
in
describe "`each` with pseudo classes"
[ test "pretty prints the expected output" <|
\_ ->
outdented (prettyPrint input)
|> Expect.equal (outdented output)
]


{-| Regression test for https://github.com/rtfeldman/elm-css/issues/99
-}
bug99 : Test
Expand Down