Skip to content

Commit

Permalink
1.0-M1: added groocss method to String
Browse files Browse the repository at this point in the history
  • Loading branch information
adamldavis committed Mar 1, 2019
1 parent 25adaaa commit 346cf46
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/main/groovy/org/groocss/ext/StringExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@ package org.groocss.ext

import groovy.transform.CompileStatic
import org.groocss.Color
import org.groocss.Config
import org.groocss.GrooCSS
import org.groocss.KeyFrames
import org.groocss.MediaCSS
import org.groocss.StyleGroup

/**
* Provides string extensions for GrooCSS to allow for static compilation and code completion.
*/
@CompileStatic
class StringExtension {

/**
* Useful for starting a GrooCSS DSL without importing anything ('main.css'.groocss { CSS DSL }).
* To use config use: 'main.css'.groocss(new Config()) { CSS DSL }.
**/
static GrooCSS groocss(String string, Config config = new Config(), @DelegatesTo(GrooCSS) Closure closure) {
println "processing $string"
GrooCSS.process(config, closure)
}

/** Useful for image urls: allows 'images/image.png'.url syntax. */
static String getUrl(String str) { 'url(' + str + ')' }

Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/org/groocss/StaticCompileSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class StaticCompileSpec extends Specification {

def "static css with sg"() {
when:
def css = GrooCSS.process {
def css = 'test1'.groocss {
sg('.a') { color whiteSmoke.mix(blue) }
sg('.b') { color tint(olive) fontSize 2.cm }
'html body a[id]:hover:active'.sg {
Expand All @@ -21,7 +21,7 @@ class StaticCompileSpec extends Specification {

def "static css with \$"() {
when:
def css = GrooCSS.process {
def css = 'test2'.groocss {
$('.a') { color whiteSmoke.mix(blue) }
$('.b') { color tint(olive) fontSize 2.cm }
'html body a[id]:hover:active'.$ {
Expand Down
10 changes: 10 additions & 0 deletions src/test/groovy/org/groocss/StringExtensionSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ class StringExtensionSpec extends Specification {
gcss = new GrooCSS() // need to do this to set the ThreadLocal value
}

def "should create GrooCSS dsl from string"() {
expect:
'my css'.groocss { section { color red } } instanceof GrooCSS
}

def "should create GrooCSS dsl from string with config"() {
expect:
'main.css'.groocss(new Config(compress: true)) { body { color red } } instanceof GrooCSS
}

def "should create color using .color"() {
expect:
'123456'.color instanceof Color
Expand Down

0 comments on commit 346cf46

Please sign in to comment.