How to Learn GrooCSS

  1. Make sure you have the requirements installed.

  2. See below for a simple example using a Groovy script.

  3. Read about the Gradle Plugin.

  4. Read the whole manual to learn about all the features.

  5. Follow me on Twitter.

  6. Star me on github.

Groovy Script

This example uses Groovy’s @Grab annotation to import GrooCSS. Create a file named "makeCss.groovy" with the following code:

@Grab('org.groocss:groocss:1.0-M3')
import org.groocss.GrooCSS
// demo
def css = GrooCSS.withConfig { prettyPrint() }.process {
    a { textDecoration 'none' }
    body _.content {
        fontSize 20.px
        width 400.px
        display 'flex'
    }
}.writeTo(new File('main.css'))

Although not recommended, this code would create CSS from the given DSL. Invoke "groovy makeCss.groovy" at the command line to run it. It would output in "main.css" the following:

a {
    text-decoration: none;
}
body .content {
    font-size: 20px;
    width: 400px;
    display: flex;
}

Using Gradle without Plugin

I recommend you use GrooCSS with either the Gradle plugin or asset-pipeline, but it can be used by itself.

    import org.groocss.GrooCSS
    //
    buildscript {
        repositories { jcenter() }
        dependencies { classpath 'org.groocss:groocss:1.0-M3' }
    }
    task css doLast {
        def file = file('css/out.css')
        GrooCSS.process {
            // DSL goes here
        }.writeTo(file)
    }

Or using "convert" methods:

    GrooCSS.convertFile('infile.groocss', 'outfile.css')
    //or
    GrooCSS.convert(new File('in'), new File('out'))

Next

Go back to Index | Go to Next


Last updated: 31 July 2019