Skip to content

Commit

Permalink
Added raw for adding raw css
Browse files Browse the repository at this point in the history
  • Loading branch information
adamldavis committed Aug 10, 2017
1 parent 057270d commit 63acc0e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
17 changes: 17 additions & 0 deletions src/main/groovy/org/groocss/Comment.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.groocss

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.TupleConstructor

/**
* Created by adavis on 8/9/17.
*/
@TupleConstructor
@EqualsAndHashCode
@CompileStatic
class Comment {
String comment
boolean isEmpty() { comment == '' }
String toString() { "/**$comment*/" }
}
6 changes: 6 additions & 0 deletions src/main/groovy/org/groocss/GrooCSS.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1738,4 +1738,10 @@ class GrooCSS extends Script {
new PseudoClass(value)
}

Raw raw(String raw) {
def r = new Raw(raw)
currentCss << r
r
}

}
28 changes: 11 additions & 17 deletions src/main/groovy/org/groocss/MediaCSS.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class MediaCSS {
/** List of @font-face elements. */
List<FontFace> fonts = []

/** List of style groups. */
List<StyleGroup> groups = []
/** List of style groups, comments, raws. */
List groups = []

/** List of @keyframes. */
List<KeyFrames> kfs = []
Expand All @@ -28,23 +28,17 @@ class MediaCSS {
this.config = config1
}

MediaCSS leftShift(StyleGroup sg) { add sg; this }
MediaCSS add(StyleGroup sg) { groups << sg; this }
MediaCSS leftShift(KeyFrames kf) { add kf; this }
MediaCSS add(KeyFrames kf) { kfs << kf; this }
MediaCSS leftShift(FontFace ff) { add ff; this }
MediaCSS add(FontFace ff) { fonts << ff; this }

MediaCSS leftShift(MediaCSS mediaCSS) { add mediaCSS; this }
MediaCSS add(MediaCSS mediaCSS) { otherCss << mediaCSS; this }
MediaCSS leftShift(sg) { add sg }
MediaCSS add(it) {
if (it instanceof KeyFrames) kfs << ((KeyFrames) it)
else if (it instanceof FontFace) fonts << ((FontFace) it)
else if (it instanceof MediaCSS) otherCss << ((MediaCSS) it)
else groups << it
this
}

MediaCSS add(Collection coll) {
coll.each {
if (it instanceof StyleGroup) add((StyleGroup) it)
if (it instanceof KeyFrames) add((KeyFrames) it)
if (it instanceof FontFace) add((FontFace) it)
if (it instanceof MediaCSS) add((MediaCSS) it)
}
coll.each {add(it)}
this
}
MediaCSS addAll(Collection coll) { add(coll) }
Expand Down
17 changes: 17 additions & 0 deletions src/main/groovy/org/groocss/Raw.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.groocss

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.TupleConstructor

/**
* Created by adavis on 8/9/17.
*/
@TupleConstructor
@EqualsAndHashCode
@CompileStatic
class Raw {
String rawCss
boolean isEmpty() { rawCss == '' }
String toString() {rawCss}
}
3 changes: 2 additions & 1 deletion src/main/groovy/org/groocss/StyleGroup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class StyleGroup extends Selectable {

/** Finds an existing StyleGroup with given selector and appends [comma selector] to its selector.*/
StyleGroup extend(String otherSelector) {
StyleGroup other = owner.groups.find {it.selector == otherSelector}
StyleGroup other = owner.groups.findAll{it instanceof Selectable}.find{
((Selectable) it).selector == otherSelector}
if (other) other.extenders << this
other
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/groovy/org/groocss/RawSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.groocss

import spock.lang.Specification

/**
* Created by adavis on 8/9/17.
*/
class RawSpec extends Specification {

def "raw should just include it"() {
given:
def css = GrooCSS.process {
raw '::webkit-blaw { dostuff }'
}
expect:
'::webkit-blaw { dostuff }' == "$css"
}
}

0 comments on commit 63acc0e

Please sign in to comment.