-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #12: Added PseudoElement and ** syntax; updated Translator; upd…
…ated related Specs; added PlaceholderProcessor (also fixed bug in processing)
- Loading branch information
1 parent
286043a
commit c7a84ea
Showing
10 changed files
with
304 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.groocss | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.transform.InheritConstructors | ||
|
||
/** | ||
* Represents a CSS3 Pseudo-element such as "::before", "::after", "::first-letter", "::first-line", | ||
* and "::placeholder". "::placeholder" is NOT supported by IE as of July 11 2019. | ||
* | ||
* @see GrooCSS | ||
* @since 1.0-M4 | ||
*/ | ||
@InheritConstructors | ||
@CompileStatic | ||
class PseudoElement extends PseudoClass { | ||
|
||
/** Only here to restrict the DSL so that pseudo-element is used properly. */ | ||
@InheritConstructors | ||
static class StyleGroup extends org.groocss.StyleGroup {} | ||
|
||
/** Allows this to be chainable to pseudo-classes. */ | ||
PseudoElement mod(PseudoClass other) { | ||
new PseudoElement(this.value + "$other") | ||
} | ||
|
||
/** Allows this to be chainable to pseudo-classes. */ | ||
PseudoElement.StyleGroup mod(PseudoClass.StyleGroup other) { | ||
new PseudoElement.StyleGroup(this.value + "$other", other.config, other.owner) | ||
} | ||
|
||
@Override | ||
String toString() { | ||
return "::$value" | ||
} | ||
} |
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
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
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
37 changes: 37 additions & 0 deletions
37
src/main/groovy/org/groocss/proc/PlaceholderProcessor.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.groocss.proc | ||
|
||
import groovy.transform.CompileStatic | ||
import org.groocss.MediaCSS | ||
import org.groocss.StyleGroup | ||
|
||
/** | ||
* Finds any StyleGroup with placeholder in it and adds a copy of it with -webkit-input- prefix added to placeholder. | ||
*/ | ||
@CompileStatic | ||
class PlaceholderProcessor implements Processor<MediaCSS> { | ||
|
||
static final String webkitInputPrefix = '-webkit-input-' | ||
static final String placeholder = 'placeholder' | ||
|
||
@Override | ||
Optional<String> process(MediaCSS cssPart, Processor.Phase phase) { | ||
|
||
if (phase == Processor.Phase.POST_VALIDATE) { | ||
cssPart.groups.findAll { | ||
it instanceof StyleGroup && ((StyleGroup) it).selector.contains('placeholder') | ||
}.each { | ||
println "WARNING: $placeholder not supported by IE" | ||
def sg = (StyleGroup) it | ||
def selector = sg.selector | ||
def newSelector = selector.replace(placeholder, webkitInputPrefix + placeholder) | ||
|
||
def newSg = new StyleGroup(newSelector, sg.config, sg.owner) | ||
|
||
newSg.styleList.addAll sg.styleList | ||
|
||
cssPart.groups << newSg | ||
} | ||
} | ||
return Optional.empty() | ||
} | ||
} |
Oops, something went wrong.