Grooscript and Grails 3

Jorge Franco Leza
Jorge Franco LezaDeveloper en OSOCO
grooscript & grails 3
Jorge Franco Leza
Greach - Madrid - April 8th 2016
About me
Developer
Between Madrid & Sevilla
jorge.franco.leza@gmail.com
@jfrancoleza
About grooscript
Apache 2 library
In github, contribute!
Groovy code to javascript
Just a tool, not a framework
Use with Node.js or other java frameworks
Last version 1.2.3
Gradle plugin
http://grooscript.org/gradle/tasks.html
plugins {

id "org.grooscript.conversion" version "1.2.3"

}
Convert files
grooscript {

source = ['src/main/groovy/gs']

destination = 'grails-app/assets/javascripts/generated'

initialText = '//Grooscript converted file'

}
bootRun.dependsOn 'convertThread'

compileGroovy.dependsOn 'convert'
task convertMyScript(type: org.grooscript.gradle.ConvertTask) {

source = ['src/main/groovy/MyScript.groovy']

mainContextScope = ['$']

destination = 'src/main/webapp/js'

includeDependencies = true

}
Groovy markup templates
templates {

templatesPath = 'grails-app/views/gtpl'

templates = ['list-links.gml']

destinationFile = 'grails-app/assets/javascripts/' +

'generated/Templates.js'

}



bootRun.dependsOn 'templatesThread'

compileGroovy.dependsOn 'templatesJs'
* can’t use groovy markup templates with g:render
p model.title

ul(class: "list-links") {

model.list.each { item ->

li {

a(href: item.url) {

p item.text

}

}

}

}
import org.grooscript.templates.Templates



Templates.applyTemplate('list-links.gml',

[title: 'Controllers', list: [

[url: 'grails.org', text: 'Grails'],

[url: 'grooscript.org', text: 'grooscript']

]]

)
list-links.gml
Spy file changes
spy {

files = [

'grails-app/assets/stylesheets/app.css',

'grails-app/views/reload/index.gsp'

]



onChanges = { list ->

//Or simpler http request

springWebsocketTo('http://localhost:8080/stomp')

.data('reload').onChannel('/app/reload')

}

}



bootRun.dependsOn 'spyChanges'
Grails 3 plugin
compile "org.grails.plugins:grooscript:1.2.2"
Setup
<!doctype html>

<html>

<head>

<asset:stylesheet src="application.css"/>

<asset:javascript src="jquery-2.2.0.min.js"/>

<asset:javascript src="grooscript-grails.js"/>



<g:layoutHead/>

</head>

<body>



<g:layoutBody/>

<asset:deferredScripts/>



</body>

</html>
Groovy code
<asset:javascript src="generated/Hello"/>
<grooscript:code>

import gs.Hello



$('body').append '''<footer><p>

<a href="http://grooscript.org">Grooscript Home</a> &&

<a href="https://twitter.com/grooscript">Twitter</a>

</p></footer>'''

new Hello().world()

</grooscript:code>
<grooscript:code>

def sing = { name ->

console.log 'Singing...' + name

}



Closure doSomething = { mapOfClosures ->

mapOfClosures.each { key, value ->

value(key)

}

}



$(document).ready doSomething([groovy: sing, grails: sing, grooscript: sing])

</grooscript:code>
Templates
<grooscript:template>

ul {

5.times { number ->

li number + " li item"

}

}

</grooscript:template>
Websockets
class ReloadController {



def index() { }



@MessageMapping("/reload")

@SendTo("/topic/reload")

protected String colors() {

return 'reload!'

}

}
compile "org.grails.plugins:grails-spring-websocket:2.3.0"
<!doctype html>

<html>

<head>

<meta name="layout" content="main"/>

<title>Reloading</title>

<asset:javascript src="spring-websocket" />

</head>

<body>

<grooscript:reloadOn path="/topic/reload"/>

<p class="reload-message">Change something in this gsp
or in application.css!</p>

</body>

</html>
<grooscript:initSpringWebsocket>

println 'Websocket is up!'

GrooscriptGrails.sendWebsocketMessage '/app/colors'

</grooscript:initSpringWebsocket>



<grooscript:onServerEvent path="/topic/colors">

allCubes(data)

</grooscript:onServerEvent>



<grooscript:template functionName="allCubes" onLoad="false" itemSelector="body">

table(id: "all-cubes") {

data.eachWithIndex { row, i ->

tr {

row.eachWithIndex { color, j ->

td(id: 'row-' + i + '-' + j,

class: 'cube ' + colors[color],

onmouseover: 'touch(' + i + ', ' + j + ')')

}

}

}

}

</grooscript:template>
Remote model
package rest
import grails.rest.Resource



@Resource(uri='/books', formats=['json'])

class Book {



String title

String author

}
* only json
<grooscript:code>

import rest.Book



def drawBooks = {

Book.list().then { list ->

$('#bookList').html ''

list.each {

appendBookToList(it)

}

}

}



def appendBookToList = { book ->

$('#bookList').append('<p>Title: '+book.title+' - Author: ‘
+ (book.author?: 'unknown') +'</p>')

}



def addBook = {

def title = $('#title').val()

def author = $('#author').val()

new Book(title: title, author: author).save().then {

appendBookToList(it)

}

}



$(document).ready {

drawBooks()

}


</grooscript:code>
Components
http://webcomponents.org
<asset:javascript src="webcomponents.min.js"/>
Custom elements - Shadow dom
<grooscript:component src="components.Counter" name="my-counter"/>
<p>Hello World!</p>

<my-counter></my-counter>

<my-counter value="3"></my-counter>
package components



class Counter {

static style = ''' 

div {

width: 100px;

}

'''

static renderAfter = ['inc', 'dec']

int value = 0

void inc() {

value++

}

void dec() {

value--

}

def render() {

div {

h1 value.toString()

p {

button(onclick: 'dec', '-')

button(onclick: 'inc', '+')

}

}

}

}
Links
Homepage: http://grooscript.org
Documentation: http://grooscript.org/doc
Github: http://github.com/chiquitinxx/grooscript
Demos: http://github.com/chiquitinxx/grooscript-demos
Gradle plugin: http://github.com/chiquitinxx/grooscript-gradle-plugin
Grails 3 plugin: http://grooscript.org/grails3-plugin/
All together: https://github.com/chiquitinxx/grails3-demo-grooscript
grooscript@gmail.com
@grooscript
Thank you!
1 de 21

Recomendados

Grooscript greach por
Grooscript greachGrooscript greach
Grooscript greachJorge Franco Leza
2.2K vistas45 diapositivas
Grooscript gr8conf 2015 por
Grooscript gr8conf 2015Grooscript gr8conf 2015
Grooscript gr8conf 2015Jorge Franco Leza
2K vistas31 diapositivas
Creating ASTTs The painful truth por
Creating ASTTs The painful truthCreating ASTTs The painful truth
Creating ASTTs The painful truthMario García
1.3K vistas170 diapositivas
Grooscript greach 2015 por
Grooscript greach 2015Grooscript greach 2015
Grooscript greach 2015Jorge Franco Leza
2.7K vistas27 diapositivas
Grooscript in Action SpringOne2gx 2015 por
Grooscript in Action SpringOne2gx 2015Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015Jorge Franco Leza
2.3K vistas49 diapositivas
Rest, sockets em golang por
Rest, sockets em golangRest, sockets em golang
Rest, sockets em golangjefferson Otoni Lima
181 vistas70 diapositivas

Más contenido relacionado

La actualidad más candente

GroovyFX - groove JavaFX Gr8Conf EU 2017 por
GroovyFX - groove JavaFX Gr8Conf EU 2017GroovyFX - groove JavaFX Gr8Conf EU 2017
GroovyFX - groove JavaFX Gr8Conf EU 2017sascha_klein
611 vistas52 diapositivas
Grunt.js introduction por
Grunt.js introductionGrunt.js introduction
Grunt.js introductionClaudio Mignanti
1K vistas12 diapositivas
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease por
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeKAI CHU CHUNG
926 vistas52 diapositivas
NetBeans Support for EcmaScript 6 por
NetBeans Support for EcmaScript 6NetBeans Support for EcmaScript 6
NetBeans Support for EcmaScript 6Kostas Saidis
1.9K vistas40 diapositivas
Gradle in 45min por
Gradle in 45minGradle in 45min
Gradle in 45minSchalk Cronjé
1.6K vistas49 diapositivas
Groovy on the shell por
Groovy on the shellGroovy on the shell
Groovy on the shellsascha_klein
778 vistas45 diapositivas

La actualidad más candente(19)

GroovyFX - groove JavaFX Gr8Conf EU 2017 por sascha_klein
GroovyFX - groove JavaFX Gr8Conf EU 2017GroovyFX - groove JavaFX Gr8Conf EU 2017
GroovyFX - groove JavaFX Gr8Conf EU 2017
sascha_klein611 vistas
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease por KAI CHU CHUNG
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
KAI CHU CHUNG926 vistas
NetBeans Support for EcmaScript 6 por Kostas Saidis
NetBeans Support for EcmaScript 6NetBeans Support for EcmaScript 6
NetBeans Support for EcmaScript 6
Kostas Saidis1.9K vistas
Groovy on the shell por sascha_klein
Groovy on the shellGroovy on the shell
Groovy on the shell
sascha_klein778 vistas
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie... por Fwdays
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
Fwdays446 vistas
Security Challenges in Node.js por Websecurify
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
Websecurify3.3K vistas
Take A Gulp at Task Automation por Joel Lord
Take A Gulp at Task AutomationTake A Gulp at Task Automation
Take A Gulp at Task Automation
Joel Lord241 vistas
The Gradle in Ratpack: Dissected por David Carr
The Gradle in Ratpack: DissectedThe Gradle in Ratpack: Dissected
The Gradle in Ratpack: Dissected
David Carr594 vistas
Django & Buildout (en) por zerok
Django & Buildout (en)Django & Buildout (en)
Django & Buildout (en)
zerok11.5K vistas
淺談 Groovy 與 AWS 雲端應用開發整合 por Kyle Lin
淺談 Groovy 與 AWS 雲端應用開發整合淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合
Kyle Lin12.6K vistas
Basic Gradle Plugin Writing por Schalk Cronjé
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
Schalk Cronjé1.7K vistas
Meetup-js-032815 por Joe Devlin
Meetup-js-032815Meetup-js-032815
Meetup-js-032815
Joe Devlin491 vistas

Destacado

Sobre GrooScript por
Sobre GrooScriptSobre GrooScript
Sobre GrooScriptJorge Franco Leza
1K vistas17 diapositivas
From Grails to Android: A Simple Journey por
From Grails to Android: A Simple JourneyFrom Grails to Android: A Simple Journey
From Grails to Android: A Simple JourneyAnnyce Davis
776 vistas126 diapositivas
Greach 2016 dockerize your grails por
Greach 2016   dockerize your grailsGreach 2016   dockerize your grails
Greach 2016 dockerize your grailsIván López Martín
1.8K vistas31 diapositivas
Geb for browser automation por
Geb for browser automationGeb for browser automation
Geb for browser automationJacob Aae Mikkelsen
2.2K vistas108 diapositivas
Mastering Grails 3 Plugins - Greach 2016 por
Mastering Grails 3 Plugins - Greach 2016Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Alvaro Sanchez-Mariscal
2.4K vistas46 diapositivas
Continuous Delivery As Code por
Continuous Delivery As CodeContinuous Delivery As Code
Continuous Delivery As CodeAlex Soto
1.5K vistas103 diapositivas

Destacado(7)

Similar a Grooscript and Grails 3

Django + Vue, JavaScript de 3ª generación para modernizar Django por
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoJavier Abadía
4.6K vistas40 diapositivas
AFUP Lorraine - Symfony Webpack Encore por
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreEngineor
356 vistas52 diapositivas
How to replace rails asset pipeline with webpack? por
How to replace rails asset pipeline with webpack?How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?Tomasz Bak
1.6K vistas25 diapositivas
お題でGroovyプログラミング: Part A por
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part AKazuchika Sekiya
946 vistas28 diapositivas
Introduction to angular js por
Introduction to angular jsIntroduction to angular js
Introduction to angular jsMarco Vito Moscaritolo
1.1K vistas32 diapositivas
Custom gutenberg block development in react por
Custom gutenberg block development in reactCustom gutenberg block development in react
Custom gutenberg block development in reactImran Sayed
926 vistas71 diapositivas

Similar a Grooscript and Grails 3(20)

Django + Vue, JavaScript de 3ª generación para modernizar Django por Javier Abadía
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar Django
Javier Abadía4.6K vistas
AFUP Lorraine - Symfony Webpack Encore por Engineor
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack Encore
Engineor356 vistas
How to replace rails asset pipeline with webpack? por Tomasz Bak
How to replace rails asset pipeline with webpack?How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?
Tomasz Bak1.6K vistas
お題でGroovyプログラミング: Part A por Kazuchika Sekiya
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
Kazuchika Sekiya946 vistas
Custom gutenberg block development in react por Imran Sayed
Custom gutenberg block development in reactCustom gutenberg block development in react
Custom gutenberg block development in react
Imran Sayed926 vistas
Grunt & Front-end Workflow por Pagepro
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
Pagepro739 vistas
Private slideshow por sblackman
Private slideshowPrivate slideshow
Private slideshow
sblackman878 vistas
20190118_NetadashiMeetup#8_React2019 por Makoto Mori
20190118_NetadashiMeetup#8_React201920190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
Makoto Mori201 vistas
Javascript MVVM with Vue.JS por Eueung Mulyana
Javascript MVVM with Vue.JSJavascript MVVM with Vue.JS
Javascript MVVM with Vue.JS
Eueung Mulyana2.9K vistas
Front End Development for Back End Developers - UberConf 2017 por Matt Raible
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
Matt Raible1.4K vistas
Grooscript gr8conf por GR8Conf
Grooscript gr8confGrooscript gr8conf
Grooscript gr8conf
GR8Conf696 vistas
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts por Simo Ahava
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsMeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
Simo Ahava5K vistas
Web applications with Catalyst por svilen.ivanov
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalyst
svilen.ivanov2.1K vistas
Modern frontend development with VueJs por Tudor Barbu
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
Tudor Barbu1.6K vistas
What's New and Newer in Apache httpd-24 por Jim Jagielski
What's New and Newer in Apache httpd-24What's New and Newer in Apache httpd-24
What's New and Newer in Apache httpd-24
Jim Jagielski1.1K vistas
intro to Angular js por Brian Atkins
intro to Angular jsintro to Angular js
intro to Angular js
Brian Atkins327 vistas
Desenvolvimento web com Ruby on Rails (parte 2) por Joao Lucas Santana
Desenvolvimento web com Ruby on Rails (parte 2)Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)
Joao Lucas Santana1.2K vistas
Single Page JavaScript WebApps... A Gradle Story por Kon Soulianidis
Single Page JavaScript WebApps... A Gradle StorySingle Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle Story
Kon Soulianidis4K vistas
React por 중운 박
React React
React
중운 박6.8K vistas

Último

STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf por
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdfDr. Jimmy Schwarzkopf
24 vistas29 diapositivas
Microsoft Power Platform.pptx por
Microsoft Power Platform.pptxMicrosoft Power Platform.pptx
Microsoft Power Platform.pptxUni Systems S.M.S.A.
61 vistas38 diapositivas
"Surviving highload with Node.js", Andrii Shumada por
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
33 vistas29 diapositivas
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... por
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...Bernd Ruecker
48 vistas69 diapositivas
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... por
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...Jasper Oosterveld
27 vistas49 diapositivas
Design Driven Network Assurance por
Design Driven Network AssuranceDesign Driven Network Assurance
Design Driven Network AssuranceNetwork Automation Forum
19 vistas42 diapositivas

Último(20)

STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf por Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
"Surviving highload with Node.js", Andrii Shumada por Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays33 vistas
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... por Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker48 vistas
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... por Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Jasper Oosterveld27 vistas
The Forbidden VPN Secrets.pdf por Mariam Shaba
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdf
Mariam Shaba20 vistas
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 por IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... por The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
Data Integrity for Banking and Financial Services por Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely29 vistas
Igniting Next Level Productivity with AI-Infused Data Integration Workflows por Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software317 vistas
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... por TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 vistas
"Node.js Development in 2024: trends and tools", Nikita Galkin por Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays17 vistas

Grooscript and Grails 3

  • 1. grooscript & grails 3 Jorge Franco Leza Greach - Madrid - April 8th 2016
  • 2. About me Developer Between Madrid & Sevilla jorge.franco.leza@gmail.com @jfrancoleza
  • 3. About grooscript Apache 2 library In github, contribute! Groovy code to javascript Just a tool, not a framework Use with Node.js or other java frameworks Last version 1.2.3
  • 4. Gradle plugin http://grooscript.org/gradle/tasks.html plugins {
 id "org.grooscript.conversion" version "1.2.3"
 }
  • 5. Convert files grooscript {
 source = ['src/main/groovy/gs']
 destination = 'grails-app/assets/javascripts/generated'
 initialText = '//Grooscript converted file'
 } bootRun.dependsOn 'convertThread'
 compileGroovy.dependsOn 'convert' task convertMyScript(type: org.grooscript.gradle.ConvertTask) {
 source = ['src/main/groovy/MyScript.groovy']
 mainContextScope = ['$']
 destination = 'src/main/webapp/js'
 includeDependencies = true
 }
  • 6. Groovy markup templates templates {
 templatesPath = 'grails-app/views/gtpl'
 templates = ['list-links.gml']
 destinationFile = 'grails-app/assets/javascripts/' +
 'generated/Templates.js'
 }
 
 bootRun.dependsOn 'templatesThread'
 compileGroovy.dependsOn 'templatesJs' * can’t use groovy markup templates with g:render
  • 7. p model.title
 ul(class: "list-links") {
 model.list.each { item ->
 li {
 a(href: item.url) {
 p item.text
 }
 }
 }
 } import org.grooscript.templates.Templates
 
 Templates.applyTemplate('list-links.gml',
 [title: 'Controllers', list: [
 [url: 'grails.org', text: 'Grails'],
 [url: 'grooscript.org', text: 'grooscript']
 ]]
 ) list-links.gml
  • 8. Spy file changes spy {
 files = [
 'grails-app/assets/stylesheets/app.css',
 'grails-app/views/reload/index.gsp'
 ]
 
 onChanges = { list ->
 //Or simpler http request
 springWebsocketTo('http://localhost:8080/stomp')
 .data('reload').onChannel('/app/reload')
 }
 }
 
 bootRun.dependsOn 'spyChanges'
  • 9. Grails 3 plugin compile "org.grails.plugins:grooscript:1.2.2"
  • 10. Setup <!doctype html>
 <html>
 <head>
 <asset:stylesheet src="application.css"/>
 <asset:javascript src="jquery-2.2.0.min.js"/>
 <asset:javascript src="grooscript-grails.js"/>
 
 <g:layoutHead/>
 </head>
 <body>
 
 <g:layoutBody/>
 <asset:deferredScripts/>
 
 </body>
 </html>
  • 11. Groovy code <asset:javascript src="generated/Hello"/> <grooscript:code>
 import gs.Hello
 
 $('body').append '''<footer><p>
 <a href="http://grooscript.org">Grooscript Home</a> &&
 <a href="https://twitter.com/grooscript">Twitter</a>
 </p></footer>'''
 new Hello().world()
 </grooscript:code> <grooscript:code>
 def sing = { name ->
 console.log 'Singing...' + name
 }
 
 Closure doSomething = { mapOfClosures ->
 mapOfClosures.each { key, value ->
 value(key)
 }
 }
 
 $(document).ready doSomething([groovy: sing, grails: sing, grooscript: sing])
 </grooscript:code>
  • 12. Templates <grooscript:template>
 ul {
 5.times { number ->
 li number + " li item"
 }
 }
 </grooscript:template>
  • 13. Websockets class ReloadController {
 
 def index() { }
 
 @MessageMapping("/reload")
 @SendTo("/topic/reload")
 protected String colors() {
 return 'reload!'
 }
 } compile "org.grails.plugins:grails-spring-websocket:2.3.0"
  • 14. <!doctype html>
 <html>
 <head>
 <meta name="layout" content="main"/>
 <title>Reloading</title>
 <asset:javascript src="spring-websocket" />
 </head>
 <body>
 <grooscript:reloadOn path="/topic/reload"/>
 <p class="reload-message">Change something in this gsp or in application.css!</p>
 </body>
 </html>
  • 15. <grooscript:initSpringWebsocket>
 println 'Websocket is up!'
 GrooscriptGrails.sendWebsocketMessage '/app/colors'
 </grooscript:initSpringWebsocket>
 
 <grooscript:onServerEvent path="/topic/colors">
 allCubes(data)
 </grooscript:onServerEvent>
 
 <grooscript:template functionName="allCubes" onLoad="false" itemSelector="body">
 table(id: "all-cubes") {
 data.eachWithIndex { row, i ->
 tr {
 row.eachWithIndex { color, j ->
 td(id: 'row-' + i + '-' + j,
 class: 'cube ' + colors[color],
 onmouseover: 'touch(' + i + ', ' + j + ')')
 }
 }
 }
 }
 </grooscript:template>
  • 16. Remote model package rest import grails.rest.Resource
 
 @Resource(uri='/books', formats=['json'])
 class Book {
 
 String title
 String author
 } * only json
  • 17. <grooscript:code>
 import rest.Book
 
 def drawBooks = {
 Book.list().then { list ->
 $('#bookList').html ''
 list.each {
 appendBookToList(it)
 }
 }
 }
 
 def appendBookToList = { book ->
 $('#bookList').append('<p>Title: '+book.title+' - Author: ‘ + (book.author?: 'unknown') +'</p>')
 }
 
 def addBook = {
 def title = $('#title').val()
 def author = $('#author').val()
 new Book(title: title, author: author).save().then {
 appendBookToList(it)
 }
 }
 
 $(document).ready {
 drawBooks()
 } 
 </grooscript:code>
  • 18. Components http://webcomponents.org <asset:javascript src="webcomponents.min.js"/> Custom elements - Shadow dom <grooscript:component src="components.Counter" name="my-counter"/> <p>Hello World!</p>
 <my-counter></my-counter>
 <my-counter value="3"></my-counter>
  • 19. package components
 
 class Counter {
 static style = ''' 
 div {
 width: 100px;
 }
 '''
 static renderAfter = ['inc', 'dec']
 int value = 0
 void inc() {
 value++
 }
 void dec() {
 value--
 }
 def render() {
 div {
 h1 value.toString()
 p {
 button(onclick: 'dec', '-')
 button(onclick: 'inc', '+')
 }
 }
 }
 }
  • 20. Links Homepage: http://grooscript.org Documentation: http://grooscript.org/doc Github: http://github.com/chiquitinxx/grooscript Demos: http://github.com/chiquitinxx/grooscript-demos Gradle plugin: http://github.com/chiquitinxx/grooscript-gradle-plugin Grails 3 plugin: http://grooscript.org/grails3-plugin/ All together: https://github.com/chiquitinxx/grails3-demo-grooscript grooscript@gmail.com @grooscript