Skip to content

Commit

Permalink
Merge pull request #146 from tolgap/each_with_pseudo
Browse files Browse the repository at this point in the history
Fix pseudo elements and classes not resolving when chained with `each`
  • Loading branch information
Richard Feldman authored Jul 25, 2016
2 parents 89d3844 + 58e7d8a commit 3413e22
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
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

0 comments on commit 3413e22

Please sign in to comment.