grooscript

library to convert groovy code to javascript

Getting Started Documentation Presentation


//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

get it from maven, bintray or download

Last version 1.3.0, see versions changes

twitter mail

grooscript 2012 -