grooscript

converts groovy code to javascript

get it from maven, bintray or download, see versions changes

Try it! Last version 1.1.2

News: Grails 3 plugin out, v1.0.0.


//DSL using Node.js with Express
server {
    get('/') {
        render 'Hello World!'
    }
    get('/spanish') {
        render 'Hola Mundo!'
    }
    get('/salute/:name') {
        render "Hello ${req.params.name}!"
    }
}.start(3000)
//Traits, operators, lists, js code
trait DomFinder {
    @GsNative
    private List selectItems(selector) {/*
        return $(selector).toArray();
    */}

    def propertyMissing(String name) {
        selectItems("#$name") ?: selectItems(".$name"
    }
}
//presenter implements DomFinder
presenter.foo.collect { it.value() }
             .findAll { it.contains 'bar' }
             .sort { it.size() }



//Groovy templates in client and server
ul {
    languages.each {
        li(class: it.style) {
            yield it.name.capitalize()
        }
        if (it.photo) {
            img it.photo
        }
    }
}
    
//Angular apps in Groovy
class TodoController implements AngularController {
    def todos = [[text:'learn grooscript', done: true]]

    def addTodo() {
        scope.todos << [text: scope.todoText, done: false]
        scope.todoText = ''
    }

    def remaining() {
        scope.todos.count { it.done }
    }

    def archive() {
        scope.todos = todos.findAll { !it.done }
    }
}
    

Why?

Explore

Apache License, Version 2.0

twitter mail

grooscript 2012 -