├── .gitignore ├── README.md ├── build.gradle ├── doc ├── chat_example.adoc ├── nodejs_example.adoc └── react_example.adoc ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── chat.png ├── countries.png ├── game.png ├── map.png ├── newchat.png ├── node.png ├── paint.png ├── snapsvg.png ├── stars.png ├── three.png └── todo.png ├── js ├── Execute.js ├── GrooscriptObservable.js ├── JsColors.js ├── NodeJs.js ├── NodeServer.js ├── authors.js ├── awesome.js ├── colors.js ├── observeRx.js ├── runrx.js └── startServer.js ├── package.json ├── speed-test ├── grooscript.js ├── test.groovy ├── test.js └── testInJs.js ├── src ├── main │ ├── groovy │ │ ├── Execute.groovy │ │ ├── angular │ │ │ ├── todoAngular.groovy │ │ │ └── todoAngularTwo.groovy │ │ ├── asciidoctor │ │ │ └── AdocLive.groovy │ │ ├── authors.groovy │ │ ├── chat │ │ │ ├── Client.groovy │ │ │ └── NodeServer.groovy │ │ ├── colors │ │ │ └── JsColors.groovy │ │ ├── countries │ │ │ ├── CountriesPresenter.groovy │ │ │ └── CustomSigma.groovy │ │ ├── dualrx │ │ │ └── GrooscriptObservable.groovy │ │ ├── firebase │ │ │ ├── BaseFirebase.groovy │ │ │ └── GrooscriptFirebase.groovy │ │ ├── firebaseAction.groovy │ │ ├── game │ │ │ ├── Cell.groovy │ │ │ ├── Game.groovy │ │ │ └── GamePresenter.groovy │ │ ├── jQueryRest.groovy │ │ ├── maps │ │ │ └── GoogleMap.groovy │ │ ├── nodejs │ │ │ └── NodeJs.groovy │ │ ├── observeRx.groovy │ │ ├── paint │ │ │ ├── Draw.groovy │ │ │ └── Functions.groovy │ │ ├── raphael │ │ │ └── Stars.groovy │ │ ├── react.groovy │ │ ├── react │ │ │ ├── Component.groovy │ │ │ ├── ComponentImpl.groovy │ │ │ └── TodoApp.groovy │ │ ├── reactNative │ │ │ └── awesome.groovy │ │ ├── rest │ │ │ └── JQueryRestApi.groovy │ │ ├── rxjs │ │ │ ├── autocomplete.groovy │ │ │ └── autocompleteTwo.groovy │ │ ├── snap.groovy │ │ ├── snap │ │ │ └── SnapSvg.groovy │ │ ├── startLiveAdoc.groovy │ │ ├── startMap.groovy │ │ ├── startServer.groovy │ │ └── three │ │ │ ├── Three.groovy │ │ │ └── startThree.groovy │ └── webapp │ │ ├── angular.html │ │ ├── angularTwo.html │ │ ├── asciidoctor.html │ │ ├── autocomplete.html │ │ ├── autocompleteTwo.html │ │ ├── bezier.html │ │ ├── countries.json │ │ ├── css │ │ ├── asciidoctor.css │ │ ├── chat.css │ │ ├── style.css │ │ └── todo.css │ │ ├── firebase.html │ │ ├── game.html │ │ ├── img │ │ ├── barcelona.png │ │ ├── campeon.jpg │ │ ├── grails.png │ │ ├── groovy.png │ │ ├── groovylogo.svg │ │ ├── gs.png │ │ ├── logo.png │ │ └── texture.jpg │ │ ├── jqueryrest.html │ │ ├── js │ │ ├── AdocLive.js │ │ ├── BaseFirebase.js │ │ ├── Cell.js │ │ ├── Client.js │ │ ├── CountriesPresenter.js │ │ ├── CustomSigma.js │ │ ├── Draw.js │ │ ├── Functions.js │ │ ├── Game.js │ │ ├── GamePresenter.js │ │ ├── GrooscriptFirebase.js │ │ ├── SnapSvg.js │ │ ├── Stars.js │ │ ├── Three.js │ │ ├── asciidoctor-core.min.js │ │ ├── autocomplete.js │ │ ├── autocompleteTwo.js │ │ ├── common.js │ │ ├── firebaseAction.js │ │ ├── grooscript-tools.js │ │ ├── grooscript.min.js │ │ ├── gstemplates.js │ │ ├── jquery.min.js │ │ ├── jqueryrest │ │ │ ├── JQueryRestApi.js │ │ │ └── jQueryRest.js │ │ ├── map │ │ │ ├── GoogleMap.js │ │ │ └── startMap.js │ │ ├── opal.min.js │ │ ├── react.js │ │ ├── require.js │ │ ├── requireGame.js │ │ ├── rx.lite.compat.js │ │ ├── sigma.min.js │ │ ├── snap.js │ │ ├── snap.svg-min.js │ │ ├── startLiveAdoc.js │ │ ├── startThree.js │ │ ├── three.min.js │ │ ├── todo.js │ │ ├── todoAngular.js │ │ └── todoAngularTwo.js │ │ ├── maps.html │ │ ├── react.html │ │ ├── sigma.html │ │ ├── snapsvg.html │ │ ├── stars.html │ │ ├── templates │ │ ├── index.gtpl │ │ ├── join.gtpl │ │ ├── left.gtpl │ │ └── message.gtpl │ │ └── three.html └── test │ ├── groovy │ ├── countries │ │ └── CountriesPresenterSpec.groovy │ └── react │ │ └── TodoAppTest.groovy │ └── resources │ └── miniCountries.json └── startChat.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | nodejs_example.html 3 | react_example.html 4 | chat_example.html 5 | grooscript-demos.* 6 | bower_components 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Grooscript demos 2 | ================ 3 | 4 | ### Groovy code converted to javascript with [grooscript](https://www.grooscript.org) 5 | 6 | ## Using Node.js with colors, request and async npm's [guide](https://www.grooscript.org/nodejs_example.html) 7 | 8 | [Dsl](https://github.com/chiquitinxx/grooscript-demos/tree/master/src/main/groovy/Execute.groovy) 9 | 10 | ![Node modules](img/node.png) 11 | 12 | ## Jackson Pollock painting demo, see in [action](https://www.grooscript.org/demo/bezier.html) 13 | 14 | [Draw](https://github.com/chiquitinxx/grooscript-demos/tree/master/src/main/groovy/paint/Draw.groovy) 15 | [Functions](https://github.com/chiquitinxx/grooscript-demos/tree/master/src/main/groovy/paint/Functions.groovy) 16 | 17 | ![Painting App](img/paint.png) 18 | 19 | ## Creating components like [react.js](http://facebook.github.io/react/) but in Groovy [guide](https://www.grooscript.org/react_example.html) 20 | 21 | [Sources](https://github.com/chiquitinxx/grooscript-demos/tree/master/src/main/groovy/react) 22 | [In action](http://grooscript.org/demo/react.html) 23 | 24 | ![Todo App](img/todo.png) 25 | 26 | ## Live conversions from [asciidoctor](http://asciidoctor.org/) to html 27 | 28 | [Source](https://github.com/chiquitinxx/grooscript-demos/blob/master/src/main/groovy/asciidoctor/AdocLive.groovy) 29 | 30 | ### [Try it!](https://www.grooscript.org/demo/asciidoctor.html) 31 | 32 | ## 2048 game, [play!](https://www.grooscript.org/demo/game.html) 33 | 34 | [Sources](https://github.com/chiquitinxx/grooscript-demos/tree/master/src/main/groovy/game) 35 | 36 | ![Game](img/game.png) 37 | 38 | ## Interactive graphic search, see in [action](https://www.grooscript.org/demo/sigma.html) 39 | 40 | [Source](https://github.com/chiquitinxx/grooscript-demos/blob/master/src/main/groovy/countries) 41 | 42 | ![Countries](img/countries.png) 43 | 44 | ## Basic chat running in Node.js, deployed in Heroku [join](https://cryptic-headland-6974.herokuapp.com/) [+info](http://grooscript.org/chat_example.html) 45 | 46 | [Server](https://github.com/chiquitinxx/grooscript-demos/blob/master/src/main/groovy/startServer.groovy) 47 | [Client](https://github.com/chiquitinxx/grooscript-demos/blob/master/src/main/groovy/chat/Client.groovy) 48 | 49 | ![Chat](img/newchat.png) 50 | 51 | ## Svg clock, see in [action](https://www.grooscript.org/demo/snapsvg.html) 52 | 53 | ![Chat](img/snapsvg.png) 54 | 55 | ## See all stars moving [here](https://www.grooscript.org/demo/stars.html) 56 | 57 | ![Stars](img/stars.png) 58 | 59 | ## Three.js objects [here](https://www.grooscript.org/demo/three.html) 60 | 61 | [Source code](https://github.com/chiquitinxx/grooscript-demos/blob/master/src/main/groovy/three) 62 | 63 | ![Three.js](img/three.png) 64 | 65 | ## Create a Rest API fake using npm faker and json-server 66 | 67 | [Source code](https://github.com/chiquitinxx/grooscript-demos/blob/master/src/main/groovy/authors.groovy) 68 | 69 | ## Google maps DSL 70 | 71 | [Source code](https://github.com/chiquitinxx/grooscript-demos/blob/master/src/main/groovy/startMap.groovy) 72 | ![Spain Map](img/map.png) 73 | 74 | Build 75 | --- 76 | 77 | In build.gradle, there are all the task to convert groovy files to javascript. Convert all demos with **./gradlew convertAll** :) 78 | 79 | To get links and info to run demos run **./gradlew showInfo** 80 | 81 | To run the demos in Node.js (colors.js, startChat.js and restApi), you need Node.js installed, and run **npm install** (maybe as sudo) to install dependencies. 82 | -------------------------------------------------------------------------------- /doc/chat_example.adoc: -------------------------------------------------------------------------------- 1 | = Chat made in groovy, running in Node.js 2 | :author: {author} 3 | :email: {email} 4 | :source-highlighter: pygments 5 | 6 | With http://grooscript.org[grooscript], you can create groovy code and run it in your browser or 7 | http://nodejs.org/[Node.js]. Let's see an example using a groovy dsl in the server, groovy templates, 8 | http://socket.io/[socket.io], and more groovy code in the client. Is just a chat application, clients login 9 | the chat, write messages and see messages from other logged users. 10 | 11 | image::chat.png[Chat] 12 | 13 | === Server side 14 | 15 | The server is a node.js app, starting a web server with http://expressjs.com/[express], and websocket server 16 | with socket.io. To run all this you need Node.js installed, and run `>npm install` to install all node.js 17 | modules needed. The server just serves 18 | `index.html` page and process chat commands coming from websockets. I have created a groovy dsl to start 19 | the server: 20 | 21 | [source,groovy] 22 | -- 23 | include::{sourcesDir}/startServer.groovy[] 24 | -- 25 | 26 | === Groovy templates 27 | 28 | I have created a little helper, in the grooscript gradle plugin, to process groovy templates. Is a incubating 29 | feature, with some limitations, but is the best time to try it :). 30 | 31 | [source,groovy] 32 | -- 33 | task chatTemplates(type: org.grooscript.gradle.TemplatesTask) { 34 | templatesPath = 'src/main/webapp/templates' 35 | templates = ['join.gtpl', 'left.gtpl', 'message.gtpl', 'index.gtpl'] 36 | destinationFile = 'src/main/webapp/js/gstemplates.js' 37 | } 38 | -- 39 | 40 | The templates are converted to javascript, saved in the javascript file `destinationFile`. Adding that file, 41 | you can apply templates with a model, returning text html code. 42 | 43 | [source,groovy] 44 | -- 45 | def html = Templates.applyTemplate('join.gtpl', [name: data.name]) 46 | -- 47 | 48 | Index template is used in the server, the rest are used in the browser, to use with the messages coming 49 | from websocket. Is very easy create logic in a groovy template, for example to show messages 50 | from a pirate user: 51 | 52 | [source,groovy] 53 | -- 54 | include::{templatesDir}/message.gtpl[] 55 | -- 56 | 57 | === Client side 58 | 59 | The index page is a groovy template coming from the server: 60 | 61 | [source,groovy] 62 | -- 63 | include::{templatesDir}/index.gtpl[] 64 | -- 65 | 66 | Jquery, grooscript, grooscript-tools, templates, socket.io are the libraries needed. The logic of the 67 | application running in the browser is in `Client.groovy`. Just with `Client.init()` starts all in the browser: 68 | 69 | [source,groovy] 70 | -- 71 | include::{sourcesDir}/chat/Client.groovy[] 72 | -- 73 | 74 | Lot of things are done in the client, send the login, switching views between chat mode and login mode, 75 | receive login from other users, show messages from other users, disconnected users, init sockets client and 76 | listeners,... As you can see, all logic is in one groovy file. 77 | 78 | === Run all 79 | 80 | To run this, created `startChat.js` file, only have to do `>node js/startChat.js` to run the server: 81 | 82 | [source,javascript] 83 | -- 84 | include::{currentDir}/startChat.js[] 85 | -- 86 | 87 | Now open your browser in `http://localhost:3000/[http://localhost:3000]` and the login div appears. 88 | 89 | All the code is on https://github.com/chiquitinxx/grooscript-demos[github]. Go, clone and play with it. 90 | 91 | === Conclusion 92 | 93 | Is very easy create logic in groovy and see the results in the browser. Was very funny explore socket.io 94 | and groovy templates with grooscript. Groovy is better language than javascript, and if you know groovy you 95 | can create better code running in js world. 96 | 97 | Please, if you have comments, suggestions, problems,... don't hesitate to contact me at grooscript@gmail.com, or open 98 | an issue or feature in http://github.com/chiquitinxx/grooscript/issues?state=open[Github]. More guides come in the 99 | future, also can find more documentation in http://grooscript.org[grooscript] site. -------------------------------------------------------------------------------- /doc/nodejs_example.adoc: -------------------------------------------------------------------------------- 1 | = Using http://grooscript.org[grooscript] Node.js support 2 | :author: Jorge Franco 3 | :email: grooscript@gmail.com 4 | :source-highlighter: pygments 5 | :icons: font 6 | 7 | With grooscript, you can convert your groovy code to javascript. Main use is associated to web applications 8 | running in your browsers, in the client side. But maybe, you want to use in the server side, in a 9 | http://nodejs.org[Node.js] application. I think node isn't the best idea in your server side, but has very 10 | good things, as a very big community and lot of modules. Also, that application runs very fast. 11 | 12 | 13 | The source code of this example is part of grooscript demos project on https://github.com/chiquitinxx/grooscript-demos[github]. 14 | You need node.js, and some http://www.npmjs.org/[npm] modules. Only grooscript module is needed to use grooscript converted code, rest 15 | of modules are used for fun in this example. Install node.js, then install modules, maybe with sudo: 16 | 17 | [source,bash] 18 | -- 19 | > npm install 20 | -- 21 | 22 | Also you need https://github.com/chiquitinxx/grooscript-gradle-plugin[grooscript gradle plugin] to convert groovy 23 | code to javascript. Install http://www.gradle.org[gradle] if you don't have it installed in your machine. You can use 24 | http://gvmtool.net[Gvm] to install gradle {gradleVersion}. 25 | 26 | === Gradle 27 | 28 | Is a node.js project, but we will use gradle to work with groovy files and convert to javascript. 29 | 30 | [source,groovy] 31 | -- 32 | include::{currentDir}/build.gradle[tags=conf] 33 | -- 34 | <1> Get grooscript gradle plugin from bintray. 35 | <2> As a normal groovy proyect we will use groovy and some grooscript features. 36 | <3> Groovy file to be converted to javascript. 37 | <4> Folder to save js file. 38 | <5> Classpath to use when compiling groovy file before convert it. 39 | 40 | To convert +Execute.groovy+ to javascript, do +> ./gradlew convert+. There are more task, to explore the 41 | plugin take a look at link:starting_gradle.html[starting guide]. 42 | 43 | === Node.js 44 | 45 | Now, let's take a look to +colors.js+ code. The Node.js application that you run with node: 46 | 47 | [source,javascript] 48 | -- 49 | include::{jsDir}/colors.js[] 50 | -- 51 | <1> Grooscript module, needed if you use groovy converted code in your application. 52 | <2> The javascript converted file with the code of our application. 53 | 54 | === Groovy 55 | 56 | Grooscript support a lot of groovy magic, as traits, dsl's, lists, ... This application play a bit with 57 | some Node.js modules using a bit of that magic. You are creating your application in groovy, and you can 58 | use the tools you know, as Spock, Codenarc, Gradle,... always better than use javascript :) 59 | 60 | [source,groovy] 61 | -- 62 | include::{sourcesDir}/Execute.groovy[] 63 | -- 64 | <1> Color output in your console using colors.js module. 65 | <2> Add node.js modules. 66 | <3> Execute tasks in parallel using async.js module. 67 | 68 | [source,groovy] 69 | -- 70 | include::{sourcesDir}/nodejs/NodeJs.groovy[] 71 | -- 72 | <1> Out groovy class implements a trait. 73 | <2> This AST will put in your js method the code between /* and */ 74 | <3> Add colors module in constructor, because color functions comes with the trait. 75 | <4> Request comes from request module. 76 | <5> Use async module to make a parallel execution of groovy closures that will be javascript functions at runtime. 77 | <6> You use groovy features in your code as @DelegateTo, to get help from your IDE writing the DSL. 78 | 79 | Finally the trait with the functions to color our console info +JsColors.groovy+: 80 | 81 | [source,groovy] 82 | -- 83 | include::{sourcesDir}/colors/JsColors.groovy[] 84 | -- 85 | 86 | All this groovy code is converted to javascript and will run in your Node.js application. 87 | 88 | === Run it 89 | 90 | If your groovy code is converted to javascript, a file `js/Execute.js` must exist. To convert `Execute.groovy` 91 | use `> ./gradlew convert`. If some error, as compilation error, or conversion failure, you get info in the console. 92 | If all is ok, just run the application with `> node js/colors.js` 93 | 94 | This application use some nice Node.js modules, as show console messages in console, get content from url's, 95 | or launch tasks concurrently. 96 | 97 | image::node.png[Result] 98 | 99 | === Conclusion 100 | 101 | This is not the best example, but you can take the idea, how to interact between Node.js and groovy. Groovy 102 | can do the same things that node, but maybe you have to use javascript(sorry) and you can introduce Groovy magic 103 | to make your javascript life more fun. 104 | 105 | Please, if you have comments, suggestions, problems,... don't hesitate to contact me at grooscript@gmail.com, or open 106 | an issue or feature in http://github.com/chiquitinxx/grooscript/issues?state=open[Github]. This is an open source project and your feedback is more than welcome 107 | to improve it. More guides come in the future, also can find more documentation in http://grooscript.org[grooscript] 108 | site. -------------------------------------------------------------------------------- /doc/react_example.adoc: -------------------------------------------------------------------------------- 1 | = Reacting with http://grooscript.org[grooscript] 2 | :author: Jorge Franco 3 | :email: grooscript@gmail.com 4 | :source-highlighter: pygments 5 | :icons: font 6 | 7 | http://facebook.github.io/react/index.html[React] is a javascript library for building UI's. It's a different 8 | approach, usually people use templates. With react, you work with javascript objects. I think is a good idea, but, 9 | it's better to do similar implementation using grooscript. 10 | 11 | 12 | I wrote this link:nodejs_example.html[guide] where I created a DSL on top of Node.js using traits. Now I'm going to use 13 | AST's and groovy beans. Use the groovy features in the browser, is the main reason to use grooscript. 14 | 15 | So let's create reactive objects as react.js does, in a TO-DO sample application: 16 | 17 | image::todo.png[Result] 18 | 19 | === In javascript, from react.js page 20 | 21 | [source,javascript] 22 | -- 23 | var TodoList = React.createClass({displayName: 'TodoList', 24 | render: function() { 25 | var createItem = function(itemText) { 26 | return React.DOM.li(null, itemText); 27 | }; 28 | return React.DOM.ul(null, this.props.items.map(createItem)); 29 | } 30 | }); 31 | var TodoApp = React.createClass({displayName: 'TodoApp', 32 | getInitialState: function() { 33 | return {items: [], text: ''}; 34 | }, 35 | onChange: function(e) { 36 | this.setState({text: e.target.value}); 37 | }, 38 | handleSubmit: function(e) { 39 | e.preventDefault(); 40 | var nextItems = this.state.items.concat([this.state.text]); 41 | var nextText = ''; 42 | this.setState({items: nextItems, text: nextText}); 43 | }, 44 | render: function() { 45 | return ( 46 | React.DOM.div(null, 47 | React.DOM.h3(null, "TODO"), 48 | TodoList({items: this.state.items}), 49 | React.DOM.form({onSubmit: this.handleSubmit}, 50 | React.DOM.input({onChange: this.onChange, value: this.state.text}), 51 | React.DOM.button(null, 'Add #' + (this.state.items.length + 1)) 52 | ) 53 | ) 54 | ); 55 | } 56 | }); 57 | React.renderComponent(TodoApp(null), mountNode); 58 | -- 59 | 60 | === In groovy, my implementation 61 | 62 | [source,groovy] 63 | -- 64 | include::{sourcesDir}/react/TodoApp.groovy[] 65 | -- 66 | <1> AST that do all react job. 67 | <2> List of all TODO's added. 68 | <3> New TODO that is being typed in the text input. 69 | <4> Initialization of the component. 70 | <5> React on any change in the input text. 71 | <6> On 'Add TODO' click. 72 | <7> Html dsl that renders the component. 73 | 74 | For the execution in javascript, I have used this groovy script (react.groovy): 75 | 76 | [source,groovy] 77 | -- 78 | include::{sourcesDir}/react.groovy[] 79 | -- 80 | <1> Little helper class that comes with grooscript to do some jQuery stuff. 81 | <2> Call init function in the component. 82 | <3> Set the selector where draw the component. 83 | <4> Start the component. 84 | <5> Call the function to render the component on load the page. 85 | 86 | === Advantages 87 | 88 | * You can create your own framework / libraries, that perfect fit with your application. 89 | * You write groovy code and test it with https://code.google.com/p/spock/[spock] or your favorite java / groovy testing framework. 90 | * You don't have to do functional tests, you can test all with unit tests and mock javascript / jquery. 91 | * You write the render code as a DSL, using groovy code, very powerful. 92 | * You can use traits, AST's, a little of inheritance, DSL's, a bit of meta-programming,... and a lot of groovy magic in your application. 93 | * You don't have to use any pre-processor as react.js does, just converting the code to javascript applies the AST's. 94 | 95 | === Implementation 96 | 97 | The code is implemented as part of the grooscript-demos project on https://github.com/chiquitinxx/grooscript-demos[github], and you 98 | can see in action in grooscript http://grooscript.org[homepage]. Just with grooscript I convert `TodoApp.groovy` and `react.groovy` files 99 | to javascript and add them with `grooscript.js`, `grooscript-tools.js` and `jquery.js` to html: 100 | 101 | [source,html] 102 | -- 103 | include::{webDir}/react.html[] 104 | -- 105 | 106 | You can take a look at the source code on https://github.com/chiquitinxx/grooscript-demos/tree/master/src/main/groovy/react[Github] 107 | 108 | === Conclusion 109 | 110 | Implement things in http://groovy-lang.org/[groovy] is a pleasure, and now, with grooscript, you can create nice pieces 111 | of code that will run smooth in your browser. This is just a suggestion, loads of new ideas can be created 112 | in the browser or node.js using groovy and grooscript. 113 | 114 | Please, if you have comments, suggestions, problems,... don't hesitate to contact me at grooscript@gmail.com, or open 115 | an issue or feature in http://github.com/chiquitinxx/grooscript/issues?state=open[Github]. More guides come in the 116 | future, also can find more documentation in http://grooscript.org[grooscript] site. -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Mar 02 23:26:53 CET 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /img/chat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/chat.png -------------------------------------------------------------------------------- /img/countries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/countries.png -------------------------------------------------------------------------------- /img/game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/game.png -------------------------------------------------------------------------------- /img/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/map.png -------------------------------------------------------------------------------- /img/newchat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/newchat.png -------------------------------------------------------------------------------- /img/node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/node.png -------------------------------------------------------------------------------- /img/paint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/paint.png -------------------------------------------------------------------------------- /img/snapsvg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/snapsvg.png -------------------------------------------------------------------------------- /img/stars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/stars.png -------------------------------------------------------------------------------- /img/three.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/three.png -------------------------------------------------------------------------------- /img/todo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/img/todo.png -------------------------------------------------------------------------------- /js/Execute.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | NodeJs.nodejs(function(it) { 3 | gs.mc(this,"rainbow",["\nGrooscript in action 2015!"]); 4 | gs.mc(this,"red",["--------------------------\n"]); 5 | gs.mc(this,"module",["request"]); 6 | gs.mc(this,"module",["async"]); 7 | return gs.mc(this,"parallel",[gs.list([function(it) { 8 | return gs.mc(this,"countBodyChars",["http://grails.org"]); 9 | } , function(it) { 10 | return gs.mc(this,"countBodyChars",["http://bintray.com"]); 11 | } , function(it) { 12 | return gs.mc(this,"countBodyChars",["http://google.com"]); 13 | } , function(it) { 14 | return gs.mc(this,"countBodyChars",["http://twitter.com"]); 15 | } , function(it) { 16 | return gs.mc(this,"countBodyChars",["http://gradle.org"]); 17 | } , function(it) { 18 | return gs.mc(this,"bold",["\nReading url's...\n"]); 19 | }])]); 20 | }); 21 | -------------------------------------------------------------------------------- /js/GrooscriptObservable.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function GrooscriptObservable() { 3 | var gSobject = gs.inherit(gs.baseClass,'GrooscriptObservable'); 4 | gSobject.clazz = { name: 'dualrx.GrooscriptObservable', simpleName: 'GrooscriptObservable'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.observable = null; 7 | gSobject['methodMissing'] = function(name, args) { 8 | return gs.mc(gs.gp(gs.thisOrObject(this,gSobject),"observable"),"" + (name) + "",gs.list([new gs.spread(args)])); 9 | } 10 | gSobject.fromList = function(x0) { return GrooscriptObservable.fromList(x0); } 11 | gSobject.platformObservable = function(list) { 12 | return Rx.Observable.from(list); 13 | } 14 | gSobject['GrooscriptObservable1'] = function(list) { 15 | gs.sp(this,"observable",gs.mc(gSobject,"platformObservable",[list])); 16 | return this; 17 | } 18 | if (arguments.length==1) {gSobject.GrooscriptObservable1(arguments[0]); } 19 | 20 | return gSobject; 21 | }; 22 | GrooscriptObservable.fromList = function(list) { 23 | return GrooscriptObservable(list); 24 | } 25 | -------------------------------------------------------------------------------- /js/JsColors.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | JsColors = function() {}; 3 | JsColors.gSaT = function(target) { 4 | target.red = function(x0, x1) { return JsColors.red(target, x0, x1); }; 5 | target.bold = function(x0, x1) { return JsColors.bold(target, x0, x1); }; 6 | target.grey = function(x0, x1) { return JsColors.grey(target, x0, x1); }; 7 | target.rainbow = function(x0, x1) { return JsColors.rainbow(target, x0, x1); }; 8 | }; 9 | JsColors.$init$ = function($self) { 10 | } 11 | function JsColors$static$init$($static$self){ 12 | 13 | }; 14 | JsColors.red = function($self, msg) { 15 | console.log(msg.red); 16 | } 17 | JsColors.bold = function($self, msg) { 18 | console.log(msg.bold); 19 | } 20 | JsColors.grey = function($self, msg) { 21 | console.log(msg.grey); 22 | } 23 | JsColors.rainbow = function($self, msg) { 24 | console.log(msg.rainbow); 25 | } 26 | -------------------------------------------------------------------------------- /js/NodeJs.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function NodeJs() { 3 | var gSobject = gs.init('NodeJs'); 4 | gSobject.clazz = { name: 'nodejs.NodeJs', simpleName: 'NodeJs'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.clazz.interfaces = [{ name: 'colors.JsColors', simpleName: 'JsColors'}]; 7 | if (JsColors['setProperty']) { 8 | gSobject.setProperty = function(x1) { return JsColors.setProperty(gSobject,x1); } 9 | } 10 | if (JsColors['getProperty']) { 11 | gSobject.getProperty = function() { return JsColors.getProperty(gSobject); } 12 | } 13 | gSobject.red = function(x1) { return JsColors.red(gSobject,x1); } 14 | gSobject.bold = function(x1) { return JsColors.bold(gSobject,x1); } 15 | JsColors.$init$(gSobject); 16 | gSobject.rainbow = function(x1) { return JsColors.rainbow(gSobject,x1); } 17 | gSobject.grey = function(x1) { return JsColors.grey(gSobject,x1); } 18 | gSobject.module = function(name) { 19 | try { 20 | global[name] = require(name); 21 | } catch(err) { 22 | this.red('Module '+name+' not installed, please install it.'); 23 | } 24 | } 25 | gSobject['countBodyChars'] = function(url) { 26 | var time = gs.date(); 27 | gs.mc(this,"grey",[" Going " + (url) + ""], gSobject); 28 | return gs.mc(this,"request",[url, function(error, response, body) { 29 | if ((!gs.bool(error)) && (gs.equals(gs.gp(response,"statusCode"), 200))) { 30 | return gs.println("" + (url) + " body size: " + (gs.mc(body,"size",[])) + " time: " + (gs.minus(gs.gp(gs.date(),"time"), gs.gp(time,"time"))) + ""); 31 | } else { 32 | return gs.println("Error: " + (error) + ""); 33 | }; 34 | }], gSobject); 35 | } 36 | gSobject['parallel'] = function(closures) { 37 | return gs.mc(gs.fs('async', this, gSobject),"parallel",[closures]); 38 | } 39 | gSobject.nodejs = function(x0) { return NodeJs.nodejs(x0); } 40 | gSobject['NodeJs0'] = function(it) { 41 | gs.mc(gSobject,"module",["colors"]); 42 | return this; 43 | } 44 | if (arguments.length==0) {gSobject.NodeJs0(); } 45 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 46 | 47 | return gSobject; 48 | }; 49 | NodeJs.nodejs = function(cl) { 50 | var node = NodeJs(); 51 | gs.sp(cl,"delegate",node); 52 | return gs.execCall(cl, this, []); 53 | } 54 | -------------------------------------------------------------------------------- /js/NodeServer.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function NodeServer() { 3 | var gSobject = gs.init('NodeServer'); 4 | gSobject.clazz = { name: 'chat.NodeServer', simpleName: 'NodeServer'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.expressApp = gs.map().add("get",function(path, closure) { 7 | return "Get in '" + (path) + "'."; 8 | }); 9 | gSobject.nodeJsServer = gs.map().add("listen",function(port) { 10 | return gs.println(gs.plus("Listening in port ", port)); 11 | }); 12 | gSobject.socketIo = null; 13 | gSobject.allSocketsOn = gs.list([]); 14 | gSobject.allClients = gs.list([]); 15 | gSobject.setupServer = function() { 16 | var express = require('express'); 17 | this.expressApp = express(); 18 | this.expressApp.set('port', (process.env.PORT || 5000)); 19 | this.expressApp.use(express.static(__dirname + '/src/main/webapp')); 20 | this.nodeJsServer = require('http').Server(this.expressApp); 21 | this.socketIo = require('socket.io')(this.nodeJsServer); 22 | } 23 | gSobject.startNodeJsServer = function() { 24 | var port = this.expressApp.get('port'); 25 | console.log("Chat is running at port:" + port); 26 | this.nodeJsServer.listen(port); 27 | } 28 | gSobject.listenSockets = function() { 29 | console.log('Initializing socket.io...'); 30 | this.socketIo.sockets.on('connection', function(socket) { 31 | gSobject.allClients.push(socket); 32 | 33 | gSobject.allSocketsOn.each(function (data) { 34 | var fn; 35 | if (data.path == 'disconnect') { 36 | fn = function() { 37 | data.closure(socket); 38 | }; 39 | } else { 40 | var fn = function(msg) { 41 | data.closure(msg, socket); 42 | }; 43 | } 44 | socket.on(data.path, fn); 45 | //console.log('Listening sockets: '+data.path); 46 | }); 47 | 48 | socket.on('disconnect', function() { 49 | console.log('Got disconnect !'); 50 | 51 | var i = gSobject.allClients.indexOf(socket); 52 | delete gSobject.allClients[i]; 53 | }); 54 | }); 55 | } 56 | gSobject['get'] = function(path, closure) { 57 | return gs.mc(gSobject.expressApp,"get",[path, function(req, resp) { 58 | gs.sp(closure,"delegate",gs.map().add("req",req).add("resp",resp).add("render",function(it) { 59 | return gs.mc(resp,"send",[it]); 60 | })); 61 | return gs.execCall(closure, this, []); 62 | }]); 63 | } 64 | gSobject['on'] = function(path, closure) { 65 | return gs.mc(gSobject.allSocketsOn,'leftShift', gs.list([gs.map().add("path",path).add("closure",closure)])); 66 | } 67 | gSobject.server = function(x0) { return NodeServer.server(x0); } 68 | gSobject['NodeServer0'] = function(it) { 69 | gs.mc(gSobject,"setupServer",[]); 70 | return this; 71 | } 72 | if (arguments.length==0) {gSobject.NodeServer0(); } 73 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 74 | 75 | return gSobject; 76 | }; 77 | NodeServer.server = function(closure) { 78 | var nodeServer = NodeServer(); 79 | gs.sp(closure,"delegate",nodeServer); 80 | gs.execCall(closure, this, []); 81 | return gs.map().add("start",function(it) { 82 | gs.mc(nodeServer,"listenSockets",[]); 83 | return gs.mc(nodeServer,"startNodeJsServer",[]); 84 | }); 85 | } 86 | -------------------------------------------------------------------------------- /js/authors.js: -------------------------------------------------------------------------------- 1 | var gs = require('grooscript'); 2 | function Faker() { 3 | var gSobject = gs.init('Faker'); 4 | gSobject.clazz = { name: 'Faker', simpleName: 'Faker'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject._faker = null; 7 | gSobject.faker = function() { 8 | if (!this._faker) { 9 | this._faker = require('faker'); 10 | } 11 | return this._faker; 12 | } 13 | gSobject.nodeExports = function(map) { 14 | module.exports = function() { 15 | return gs.toJavascript(map); 16 | }; 17 | } 18 | gSobject['resolveConfig'] = function(value, counter) { 19 | if (gs.equals(value, "inc")) { 20 | return gs.plus(counter, 1); 21 | } else { 22 | var path = gs.mc(value,"split",["."]); 23 | if (gs.equals((path[0]), "random")) { 24 | return gs.mc(gs.random(),"nextInt",[parseInt(path[1])]); 25 | } else { 26 | return gs.execCall((gs.mc(gSobject,"faker",[])[(path[0])])[(path[1])], this, []); 27 | }; 28 | }; 29 | } 30 | gSobject['exports'] = function(name, number, configuration) { 31 | var list = gs.list([]); 32 | gs.println("Exporting " + (number) + " " + (name) + "."); 33 | gs.mc(number,"times",[function(it) { 34 | return gs.mc(list,'leftShift', gs.list([gs.mc(configuration,"inject",[gs.map(), function(map, conf) { 35 | (map[gs.gp(conf,"key")]) = gs.mc(gSobject,"resolveConfig",[gs.gp(conf,"value"), it]); 36 | return map; 37 | }])])); 38 | }]); 39 | return gs.mc(gSobject,"nodeExports",[gs.map().add("" + (name) + "",list)]); 40 | } 41 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 42 | 43 | return gSobject; 44 | }; 45 | gs.mc(Faker(),"exports",["authors", 3, gs.map().add("id","inc").add("name","name.firstName").add("city","address.city").add("image","image.image").add("birthDate","date.past").add("age","random.99")]); 46 | -------------------------------------------------------------------------------- /js/awesome.js: -------------------------------------------------------------------------------- 1 | //Grooscript example using reactjs native to create ios app 2 | //Starting react native getting started: http://facebook.github.io/react-native/docs/getting-started.html#content 3 | //and replace index.ios.js with this file 4 | 'use strict'; 5 | 6 | var React = require('react-native'); 7 | var { 8 | AppRegistry, 9 | StyleSheet, 10 | Text, 11 | Image, 12 | View, 13 | } = React; 14 | 15 | var gs = require('grooscript'); 16 | 17 | function Components() { 18 | var gSobject = gs.inherit(gs.baseClass,'Components'); 19 | gSobject.clazz = { name: 'reactNative.Components', simpleName: 'Components'}; 20 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 21 | gSobject.list = gs.list([]); 22 | gSobject['methodMissing'] = function(name, args) { 23 | return gs.mc(gSobject.list,'leftShift', gs.list([gs.mc(React,"createElement",[gs.mc(gSobject,"component",[name]), gs.toJavascript(args[0]), args[1]])])); 24 | } 25 | gSobject['image'] = function(args) { 26 | return gs.mc(gSobject.list,'leftShift', gs.list([gs.mc(React,"createElement",[gs.mc(gSobject,"component",["image"]), gs.toJavascript(args)])])); 27 | } 28 | gSobject.component = function(name) { 29 | if (name == 'text') return Text; 30 | if (name == 'image') return Image; 31 | } 32 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 33 | 34 | return gSobject; 35 | }; 36 | 37 | function GroovyView() { 38 | var gSobject = gs.inherit(gs.baseClass,'GroovyView'); 39 | gSobject.clazz = { name: 'reactNative.GroovyView', simpleName: 'GroovyView'}; 40 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 41 | gSobject['data'] = function(map, closure) { 42 | var allParams = gs.list([View , map]); 43 | var components = Components(); 44 | gs.sp(closure,"delegate",components); 45 | gs.execCall(closure, this, []); 46 | gs.mc(gs.gp(components,"list"),"each",[function(it) { 47 | return gs.mc(allParams,'leftShift', gs.list([it])); 48 | }]); 49 | return gs.mc(gs.gp(React,"createElement"),"apply",[React, allParams]); 50 | } 51 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 52 | 53 | return gSobject; 54 | }; 55 | 56 | 57 | var styles = gs.mc(StyleSheet,"create",[gs.toJavascript(gs.map().add("container",gs.map().add("flex",1).add("justifyContent","center").add("alignItems","center").add("backgroundColor","#ffffff")).add("welcome",gs.map().add("fontSize",20).add("textAlign","center").add("margin",10)).add("image",gs.map().add("width",192).add("height",96)))]); 58 | var AwesomeProject = gs.mc(React,"createClass",[gs.map().add("render",function(it) { 59 | var groovyView = GroovyView(); 60 | return gs.mc(groovyView,"data",[gs.map().add("style",gs.gp(styles,"container")), function(it) { 61 | gs.mc(this,"image",[gs.map().add("style",gs.gp(styles,"image")).add("source",gs.map().add("uri","http://grooscript.org/img/groovy.png"))]); 62 | gs.mc(this,"text",[gs.map().add("style",gs.gp(styles,"welcome")), "Hello #ios from #groovylang"]); 63 | gs.mc(this,"text",[gs.map().add("style",gs.gp(styles,"welcome")), "With @grooscript"]); 64 | return gs.mc(this,"text",[gs.map().add("style",gs.gp(styles,"welcome")), "and @reactjs native"]); 65 | }]); 66 | })]); 67 | 68 | AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject); -------------------------------------------------------------------------------- /js/colors.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var gs = require('grooscript'); //<1> 3 | 4 | eval(fs.readFileSync('js/JsColors.js')+''); //<2> 5 | eval(fs.readFileSync('js/NodeJs.js')+''); //<2> 6 | eval(fs.readFileSync('js/Execute.js')+''); //<2> 7 | 8 | 9 | -------------------------------------------------------------------------------- /js/observeRx.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | gs.mc(gs.mc(gs.execStatic(GrooscriptObservable,'fromList', this,[gs.list(["one" , "two" , "three"])]),"take",[2]),"subscribe",[function(arg) { 3 | return gs.println(arg); 4 | }]); 5 | -------------------------------------------------------------------------------- /js/runrx.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var gs = require('grooscript'); 3 | var Rx = require('rx'); 4 | 5 | eval(fs.readFileSync('js/GrooscriptObservable.js')+''); 6 | eval(fs.readFileSync('js/observeRx.js')+''); //<2> 7 | 8 | 9 | -------------------------------------------------------------------------------- /js/startServer.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | gs.mc(NodeServer.server(function(it) { 3 | gs.mc(this,"get",["/", function(it) { 4 | return gs.mc(this,"render",[gs.execStatic(Templates,'applyTemplate', this,["index.gtpl"])]); 5 | }]); 6 | gs.mc(this,"on",["login", function(data, socket) { 7 | if ((gs.bool(gs.gp(data,"name"))) && (!gs.bool(gs.gp(socket,"login")))) { 8 | gs.sp(socket,"login",gs.gp(data,"name")); 9 | gs.mc(socket,"emit",["loginok", gs.map().add("name",gs.gp(data,"name"))]); 10 | return gs.mc(gs.gp(socket,"broadcast"),"emit",["loginok", gs.map().add("name",gs.gp(data,"name"))]); 11 | }; 12 | }]); 13 | gs.mc(this,"on",["msg", function(data, socket) { 14 | if ((gs.bool(gs.gp(data,"msg"))) && (gs.bool(gs.gp(socket,"login")))) { 15 | return gs.mc(gs.gp(socket,"broadcast"),"emit",["msg", gs.map().add("from",gs.gp(socket,"login")).add("msg",gs.gp(data,"msg"))]); 16 | }; 17 | }]); 18 | return gs.mc(this,"on",["disconnect", function(socket) { 19 | if (gs.bool(gs.gp(socket,"login"))) { 20 | return gs.mc(gs.gp(socket,"broadcast"),"emit",["off", gs.map().add("name",gs.gp(socket,"login"))]); 21 | }; 22 | }]); 23 | }),"start",[]); 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "grooscript-demos", 3 | "homepage" : "https://github.com/chiquitinxx/grooscript-demos", 4 | "author" : "Jorge Franco ", 5 | "repository" : {"type": "git", "url": "git://github.com/chiquitinxx/grooscript-demos.git"}, 6 | "licenses": [ 7 | { 8 | "type": "APACHE2", 9 | "url": "https://github.com/chiquitinxx/grooscript/blob/master/LICENSE.txt" 10 | } 11 | ], 12 | "dependencies": { 13 | "async": "^0.9.0", 14 | "request": "^2.51.0", 15 | "grooscript": "*", 16 | "colors": "^1.0.3", 17 | "express": "^4.10.6", 18 | "socket.io": "^1.2.1", 19 | "faker": "^2.1.3", 20 | "node-rest-client": "^1.5.1", 21 | "rx": "^2.5.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /speed-test/test.groovy: -------------------------------------------------------------------------------- 1 | 2 | class Container { 3 | def pieces = [] 4 | 5 | Container() { 6 | def number = new Random().nextInt(20) + 20 7 | number.times { 8 | def piece = [name: "name${it}", value: it] 9 | pieces << piece 10 | } 11 | } 12 | 13 | long sum() { 14 | pieces.sum { it.value } 15 | } 16 | } 17 | 18 | def takeTime = { closure -> 19 | def init = new Date() 20 | closure() 21 | new Date().time - init.time 22 | } 23 | 24 | println "Sum containers time: " + takeTime { 25 | 5000.times { 26 | def container = new Container() 27 | container.sum() 28 | } 29 | } 30 | 31 | println "Functional time: " + takeTime { 32 | 500.times { 33 | def container = new Container() 34 | container.pieces. 35 | collect { [doubleName: it.name * 2, value: 1 / (it.value + 1)] }. 36 | sort { it.value }. 37 | inject(0) { acc, item -> acc + item.value } 38 | } 39 | } -------------------------------------------------------------------------------- /speed-test/test.js: -------------------------------------------------------------------------------- 1 | var gs = require('./grooscript.js'); 2 | function Container() { 3 | var gSobject = gs.init('Container'); 4 | gSobject.clazz = { name: 'Container', simpleName: 'Container'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.pieces = gs.list([]); 7 | gSobject['sum'] = function(it) { 8 | return gs.mc(gSobject.pieces,"sum",[function(it) { 9 | return gs.gp(it,"value"); 10 | }]); 11 | } 12 | gSobject['Container0'] = function(it2) { 13 | var number = gs.plus(gs.mc(gs.random(),"nextInt",[20]), 20); 14 | gs.mc(number,"times",[function(it) { 15 | var piece = gs.map().add("name","name" + (it) + "").add("value",it); 16 | return gs.mc(gSobject.pieces,'leftShift', gs.list([piece])); 17 | //gSobject.pieces.push(piece); 18 | }]); 19 | return this; 20 | } 21 | if (arguments.length==0) {gSobject.Container0(); } 22 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 23 | 24 | return gSobject; 25 | }; 26 | var takeTime = function(closure) { 27 | var init = gs.date(); 28 | gs.execCall(closure, this, []); 29 | return gs.minus(gs.gp(gs.date(),"time"), gs.gp(init,"time")); 30 | }; 31 | gs.println(gs.plus("Sum containers time: ", gs.execCall(takeTime, this, [function(it) { 32 | return (5000).times(function(it) { 33 | var container = Container(); 34 | return gs.mc(container,"sum",[]); 35 | }); 36 | }]))); 37 | gs.println(gs.plus("Functional time: ", gs.execCall(takeTime, this, [function(it) { 38 | return (500).times(function(it) { 39 | var container = Container(); 40 | return gs.mc(gs.mc(gs.mc(gs.gp(container,"pieces"),"collect",[function(it) { 41 | return gs.map().add("doubleName",gs.multiply(gs.gp(it,"name"), 2)).add("value",gs.div(1, (gs.plus(gs.gp(it,"value"), 1)))); 42 | }]),"sort",[function(it) { 43 | return gs.gp(it,"value"); 44 | }]),"inject",[0, function(acc, item) { 45 | return gs.plus(acc, gs.gp(item,"value")); 46 | }]); 47 | }); 48 | }]))); 49 | -------------------------------------------------------------------------------- /speed-test/testInJs.js: -------------------------------------------------------------------------------- 1 | function Container() { 2 | this.pieces = []; 3 | 4 | var i, number = Math.ceil(Math.random()*20) + 21; 5 | for (i = 0; i < number; i++) { 6 | this.pieces.push({name: "name " + i, value: i}) 7 | } 8 | 9 | this.sum = function() { 10 | var i, all = 0; 11 | for (i = 0; i < this.pieces.length; i++) { 12 | all += this.pieces[i].value; 13 | } 14 | return all; 15 | } 16 | } 17 | 18 | function takeTime(closure) { 19 | var init = new Date(); 20 | closure(); 21 | return (new Date().getTime() - init.getTime()); 22 | } 23 | 24 | console.log("Sum containers time: " + takeTime(function() { 25 | var i; 26 | for (i = 0; i < 5000; i++) { 27 | var container = new Container(); 28 | container.sum(); 29 | } 30 | })); 31 | 32 | /* 33 | console.log("Functional time: " + takeTime(function() { 34 | var i; 35 | for (i = 0; i < 500; i++) { 36 | var container = new Container(); 37 | container.sum(); 38 | } 39 | 500.times { 40 | def container = new Container() 41 | container.pieces. 42 | collect { [doubleName: it.name * 2, value: 1 / (it.value + 1)] }. 43 | sort { it.value }. 44 | inject(0) { acc, item -> acc + item.value } 45 | } 46 | })); 47 | */ -------------------------------------------------------------------------------- /src/main/groovy/Execute.groovy: -------------------------------------------------------------------------------- 1 | import static nodejs.NodeJs.nodejs 2 | 3 | nodejs { 4 | rainbow '\nGrooscript in action 2015!' //<1> 5 | red '--------------------------\n' 6 | 7 | module 'request' //<2> 8 | module 'async' 9 | 10 | parallel([ //<3> 11 | { countBodyChars 'http://grails.org' }, 12 | { countBodyChars 'http://bintray.com' }, 13 | { countBodyChars 'http://google.com' }, 14 | { countBodyChars 'http://twitter.com' }, 15 | { countBodyChars 'http://gradle.org' }, 16 | { bold '\nReading url\'s...\n' }, 17 | ]) 18 | } -------------------------------------------------------------------------------- /src/main/groovy/angular/todoAngular.groovy: -------------------------------------------------------------------------------- 1 | package angular 2 | 3 | /** 4 | * Created by jorgefrancoleza on 1/3/15. 5 | */ 6 | def todoAngular = { $scope -> 7 | $scope.todos = [ 8 | [text:'learn angular', done: true], 9 | [text:'build an angular app', done: false] 10 | ] 11 | 12 | $scope.addTodo = { 13 | $scope.todos << [text:$scope.todoText, done:false] 14 | $scope.todoText = '' 15 | } 16 | 17 | $scope.remaining = { 18 | $scope.todos.inject(0) { acc, todo -> 19 | todo.done ? acc + 1 : acc 20 | } 21 | } 22 | 23 | $scope.archive = { 24 | $scope.todos = $scope.todos.findAll { !it.done } 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/groovy/angular/todoAngularTwo.groovy: -------------------------------------------------------------------------------- 1 | package angular 2 | 3 | /** 4 | * Created by jorgefrancoleza on 1/3/15. 5 | */ 6 | trait AngularController { 7 | 8 | def scope 9 | 10 | Closure init() { 11 | { controller, angularScope -> 12 | controller.scope = angularScope 13 | controllerProperties(controller).each { nameProperty -> 14 | angularScope."$nameProperty" = controller."$nameProperty" 15 | } 16 | controllerMethods(controller).each { nameMethod -> 17 | angularScope."$nameMethod" = controller.&"$nameMethod" 18 | } 19 | }.curry(this) 20 | } 21 | 22 | static controllerProperties(controller) { 23 | controller.properties.findAll { key, value -> 24 | !(key in ['class', 'scope']) 25 | }.collect { key, value -> key } 26 | } 27 | 28 | static controllerMethods(controller) { 29 | controller.metaClass.methods.findAll { method -> 30 | !method.name.startsWith('set') && !method.name.startsWith('get') && !method.name.contains('$') && 31 | !(method.name in ['equals', 'hashCode', 'notify', 'notifyAll', 'toString', 32 | 'wait', 'controllerMethods', 'controllerProperties', 'init', 33 | 'invokeMethod']) 34 | }.collect { it.name } 35 | } 36 | } 37 | 38 | class TodoController implements AngularController { 39 | def todos = [ 40 | [text:'learn angular', done: true], 41 | [text:'build an angular app', done: false] 42 | ] 43 | 44 | def addTodo() { 45 | scope.todos << [text: scope.todoText, done: false] 46 | scope.todoText = '' 47 | } 48 | 49 | def remaining() { 50 | scope.todos.count { it.done } 51 | } 52 | 53 | def archive() { 54 | scope.todos = todos.findAll { !it.done } 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/groovy/asciidoctor/AdocLive.groovy: -------------------------------------------------------------------------------- 1 | package asciidoctor 2 | 3 | import org.grooscript.asts.GsNative 4 | import react.Component 5 | 6 | @Component 7 | class AdocLive { 8 | String adocCode 9 | def convertedCode 10 | 11 | void init() { 12 | adocCode = '''http://asciidoctor.org[*Asciidoctor*] 13 | running on http://opalrb.org[_Opal_] 14 | brings AsciiDoc to the browser!''' 15 | convertedCode = convert(adocCode) 16 | } 17 | 18 | @GsNative 19 | def convert(toConvert) {/* 20 | var options = Opal.hash2(['attributes'], {attributes: ['showtitle']}); 21 | return Opal.Asciidoctor.$convert(toConvert, options); 22 | */} 23 | 24 | void adocCodeChange(newText) { 25 | convertedCode = convert(newText) 26 | setAdocCode(newText) 27 | } 28 | 29 | void render() { 30 | h3 'Asciidoctor code:' 31 | p '* Stay alert, your cursor move to the end after each change' 32 | textarea(id:'adocCode', cols: 100, rows: 14) { 33 | yieldUnescaped adocCode 34 | } 35 | h3 'Html Result:' 36 | hr() 37 | div { 38 | yieldUnescaped convertedCode 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/groovy/authors.groovy: -------------------------------------------------------------------------------- 1 | import org.grooscript.asts.GsNative 2 | 3 | /** 4 | * Created by jorgefrancoleza on 31/5/15. 5 | */ 6 | 7 | class Faker { 8 | private _faker 9 | 10 | @GsNative 11 | private faker() {/* 12 | if (!this._faker) { 13 | this._faker = require('faker'); 14 | } 15 | return this._faker; 16 | */} 17 | 18 | @GsNative 19 | private nodeExports(map) {/* 20 | module.exports = function() { 21 | return gs.toJavascript(map); 22 | }; 23 | */} 24 | 25 | private resolveConfig(value, counter) { 26 | if (value == 'inc') { 27 | return counter + 1 28 | } else { 29 | def path = value.split('.') 30 | if (path[0] == 'random') { 31 | return new Random().nextInt(Integer.parseInt(path[1])) 32 | } else { 33 | return faker()[path[0]][path[1]]() 34 | } 35 | } 36 | } 37 | 38 | void exports(String name, int number, Map configuration) { 39 | def list = [] 40 | println "Exporting ${number} ${name}." 41 | number.times { 42 | list << configuration.inject([:]) { map, conf -> 43 | map[conf.key] = resolveConfig(conf.value, it) 44 | map 45 | } 46 | } 47 | nodeExports(["$name": list]) 48 | } 49 | } 50 | 51 | new Faker().exports('authors', 3, [ 52 | id: 'inc', 53 | name: 'name.firstName', 54 | city: 'address.city', 55 | image: 'image.image', 56 | birthDate: 'date.past', 57 | age: 'random.99' 58 | ]) 59 | -------------------------------------------------------------------------------- /src/main/groovy/chat/Client.groovy: -------------------------------------------------------------------------------- 1 | package chat 2 | 3 | import org.grooscript.asts.GsNative 4 | import org.grooscript.jquery.GQuery 5 | import org.grooscript.jquery.GQueryImpl 6 | import org.grooscript.templates.Templates 7 | 8 | class Client { 9 | 10 | def login 11 | def chat 12 | def socket 13 | GQuery gQuery 14 | 15 | Client(jQueryImpl) { 16 | this.gQuery = jQueryImpl 17 | socketInit() 18 | socket.on 'msg', { data -> 19 | gQuery('#messages').append Templates.applyTemplate('message.gtpl', [name: data.from, msg: data.msg]) 20 | } 21 | socket.on 'loginok', { data -> 22 | if (data.name == login) { 23 | chatMode(login) 24 | } 25 | gQuery('#messages').append Templates.applyTemplate('join.gtpl', [name: data.name]) 26 | } 27 | socket.on 'off', { data -> 28 | gQuery('#messages').append Templates.applyTemplate('left.gtpl', [name: data.name]) 29 | } 30 | gQuery('#chatArea').hide() 31 | gQuery('#loginArea').show() 32 | bindEvents() 33 | } 34 | 35 | @GsNative 36 | void socketInit() {/* 37 | this.socket = io(window.location.hostname); 38 | */} 39 | 40 | def sendMessageClick() { 41 | socket.emit 'msg', [msg: chat] 42 | gQuery('#messages').append Templates.applyTemplate('message.gtpl', [name: login, msg: chat]) 43 | setChat '' 44 | } 45 | 46 | def loginButtonClick() { 47 | socket.emit 'login', [name: login] 48 | } 49 | 50 | void chatMode(login) { 51 | gQuery('#chatArea').show() 52 | gQuery('#loginArea').hide() 53 | gQuery('#chat').focus() 54 | gQuery('title').text "Chat - $login" 55 | } 56 | 57 | static init() { 58 | def gQuery = new GQueryImpl() 59 | gQuery.onReady { 60 | def client = new Client(gQuery) 61 | gQuery.bindAllProperties(client) 62 | gQuery.attachMethodsToDomEvents(client) 63 | } 64 | } 65 | 66 | private bindEvents() { 67 | gQuery('#chat').keypress { event -> 68 | if (event.which == 13) { 69 | sendMessageClick() 70 | } 71 | } 72 | gQuery('#login').keypress { event -> 73 | if (event.which == 13) { 74 | loginButtonClick() 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/groovy/chat/NodeServer.groovy: -------------------------------------------------------------------------------- 1 | package chat 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | /** 6 | * User: jorgefrancoleza 7 | * Date: 21/10/14 8 | */ 9 | class NodeServer { 10 | //Initial functions, so this groovy script will run 11 | def expressApp = [get: { path, closure -> "Get in '${path}'."}] 12 | def nodeJsServer = [listen: { Integer port -> println 'Listening in port ' + port}] 13 | def socketIo 14 | def allSocketsOn = [] 15 | def allClients = [] 16 | 17 | NodeServer() { 18 | setupServer() 19 | } 20 | 21 | @GsNative 22 | private setupServer() {/* 23 | var express = require('express'); 24 | this.expressApp = express(); 25 | this.expressApp.set('port', (process.env.PORT || 5000)); 26 | this.expressApp.use(express.static(__dirname + '/src/main/webapp')); 27 | this.nodeJsServer = require('http').Server(this.expressApp); 28 | this.socketIo = require('socket.io')(this.nodeJsServer); 29 | */} 30 | 31 | @GsNative 32 | private startNodeJsServer() {/* 33 | var port = this.expressApp.get('port'); 34 | console.log("Chat is running at port:" + port); 35 | this.nodeJsServer.listen(port); 36 | */} 37 | 38 | @GsNative 39 | def listenSockets() {/* 40 | console.log('Initializing socket.io...'); 41 | this.socketIo.sockets.on('connection', function(socket) { 42 | gSobject.allClients.push(socket); 43 | 44 | gSobject.allSocketsOn.each(function (data) { 45 | var fn; 46 | if (data.path == 'disconnect') { 47 | fn = function() { 48 | data.closure(socket); 49 | }; 50 | } else { 51 | var fn = function(msg) { 52 | data.closure(msg, socket); 53 | }; 54 | } 55 | socket.on(data.path, fn); 56 | //console.log('Listening sockets: '+data.path); 57 | }); 58 | 59 | socket.on('disconnect', function() { 60 | console.log('Got disconnect !'); 61 | 62 | var i = gSobject.allClients.indexOf(socket); 63 | delete gSobject.allClients[i]; 64 | }); 65 | }); 66 | 67 | */} 68 | 69 | def get(String path, Closure closure) { 70 | expressApp.get(path, { req, resp -> 71 | closure.delegate = [req: req, resp: resp, render: { resp.send(it)}] 72 | closure() 73 | }) 74 | } 75 | 76 | def on(String path, Closure closure) { 77 | allSocketsOn << [path: path, closure: closure] 78 | } 79 | 80 | static server(@DelegatesTo(NodeServer) closure) { 81 | NodeServer nodeServer = new NodeServer() 82 | closure.delegate = nodeServer 83 | closure() 84 | [start: { -> 85 | nodeServer.listenSockets() 86 | nodeServer.startNodeJsServer() 87 | }] 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/groovy/colors/JsColors.groovy: -------------------------------------------------------------------------------- 1 | package colors 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | trait JsColors { 6 | @GsNative 7 | def red(String msg) {/* 8 | console.log(msg.red); 9 | */} 10 | 11 | @GsNative 12 | def bold(String msg) {/* 13 | console.log(msg.bold); 14 | */} 15 | 16 | @GsNative 17 | def grey(String msg) {/* 18 | console.log(msg.grey); 19 | */} 20 | 21 | @GsNative 22 | def rainbow(String msg) {/* 23 | console.log(msg.rainbow); 24 | */} 25 | } 26 | -------------------------------------------------------------------------------- /src/main/groovy/countries/CountriesPresenter.groovy: -------------------------------------------------------------------------------- 1 | package countries 2 | 3 | import groovy.json.JsonSlurper 4 | import org.grooscript.asts.GsNotConvert 5 | import org.grooscript.jquery.GQuery 6 | 7 | /** 8 | * User: jorgefrancoleza 9 | * Date: 19/10/14 10 | */ 11 | class CountriesPresenter { 12 | 13 | def countries 14 | CustomSigma customSigma 15 | GQuery gQuery 16 | 17 | def purpleColor = '#b0b' 18 | def greyColor = '#aaa' 19 | 20 | @GsNotConvert 21 | def loadCountries() { 22 | new JsonSlurper().parseText(new File('src/test/resources/miniCountries.json').text) 23 | } 24 | 25 | def start() { 26 | countries = loadCountries(). 27 | findAll { it.population > 100000 && it.alpha3Code != 'COD' }. 28 | unique { it.alpha3Code } 29 | countries.each { country -> 30 | customSigma.addNode id: country.alpha3Code, label: country.name, 31 | x: country.latlng[1], y: country.latlng[0], color: purpleColor 32 | } 33 | countries.each { country -> 34 | country.borders?.each { border -> 35 | if (countries.find { it.alpha3Code == border} != null) { 36 | customSigma.addEdge((country.alpha3Code + border), country.alpha3Code, border) 37 | } 38 | } 39 | } 40 | updateNumberCountries countries.size() 41 | customSigma.refresh() 42 | } 43 | 44 | def onChangeCountry(searchString) { 45 | def listMatches = [] 46 | if (searchString) { 47 | customSigma.applyToNodes { node -> 48 | if (node.label.toUpperCase().contains(searchString.toUpperCase())) { 49 | node.color = purpleColor 50 | listMatches << node 51 | } else { 52 | node.color = greyColor 53 | } 54 | } 55 | updateNumberCountries listMatches.size(), 56 | listMatches.size() < 5 ? listMatches.collect { it.label }.join(', ') : '' 57 | } else { 58 | customSigma.applyToNodes { node -> 59 | node.color = purpleColor 60 | } 61 | updateNumberCountries countries.size() 62 | } 63 | if (listMatches && listMatches.size() == 1) { 64 | def node = listMatches.first() 65 | customSigma.moveCamaraToNode node 66 | } else { 67 | customSigma.moveCamaraTo 0, 0, 1 68 | } 69 | customSigma.refresh() 70 | } 71 | 72 | private updateNumberCountries(number, message = '') { 73 | gQuery('#searchResult').html("${number} found. ${message}") 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/groovy/countries/CustomSigma.groovy: -------------------------------------------------------------------------------- 1 | package countries 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | /** 6 | * User: jorgefrancoleza 7 | * Date: 19/10/14 8 | */ 9 | class CustomSigma { 10 | 11 | def s 12 | 13 | CustomSigma(String container) { 14 | init(container) 15 | } 16 | 17 | @GsNative 18 | private init(String container) {/* 19 | this.s = new sigma(container); 20 | this.s.settings({ 21 | edgeColor: 'default', 22 | defaultEdgeColor: 'grey' 23 | }); 24 | */} 25 | 26 | @GsNative 27 | def refresh() {/* 28 | this.s.refresh(); 29 | */} 30 | 31 | @GsNative 32 | def addNode(Map data) {/* 33 | this.s.graph.addNode({ 34 | // Main attributes: 35 | id: data.id, 36 | label: data.label, 37 | // Display attributes: 38 | x: data.x * 10, 39 | y: data.y * (-10), 40 | size: 1, 41 | color: data.color 42 | }); 43 | */} 44 | 45 | @GsNative 46 | def addEdge(String id, String source, String target) {/* 47 | this.s.graph.addEdge({ 48 | id: id, 49 | // Reference extremities: 50 | source: source, 51 | target: target 52 | }); 53 | */} 54 | 55 | def moveCamaraTo(x, y, ratio) { 56 | s.cameras[0].goTo x:x, y:y, ratio:ratio 57 | } 58 | 59 | @GsNative 60 | def moveCamaraToNode(node) {/* 61 | this.s.cameras[0].goTo({x:node['read_cam0:x'],y:node['read_cam0:y'],ratio:0.300}) 62 | */} 63 | 64 | def applyToNodes(closure) { 65 | s.graph.nodes().forEach(closure) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/groovy/dualrx/GrooscriptObservable.groovy: -------------------------------------------------------------------------------- 1 | package dualrx 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | class GrooscriptObservable { 6 | 7 | def observable 8 | 9 | GrooscriptObservable(List list) { 10 | this.observable = platformObservable(list) 11 | } 12 | 13 | def methodMissing(String name, args) { 14 | this.observable."$name"(*args) 15 | } 16 | 17 | static fromList(List list) { 18 | new GrooscriptObservable(list) 19 | } 20 | 21 | @GsNative 22 | private platformObservable(List list) {/* 23 | return Rx.Observable.from(list); 24 | */ 25 | Class.forName("rx.Observable").invokeMethod("from", list) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/groovy/firebase/BaseFirebase.groovy: -------------------------------------------------------------------------------- 1 | package firebase 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | class BaseFirebase { 6 | 7 | def dataRef 8 | 9 | BaseFirebase(String url) { 10 | initFirebase(url) 11 | this.metaClass.methods.each { it -> 12 | if (it.name.startsWith('on')) { 13 | def nameProperty = it.name.substring(2).toLowerCase() 14 | doOnEvent(nameProperty, it.name) 15 | } 16 | } 17 | } 18 | 19 | @GsNative 20 | void setProperty(String name, value) {/* 21 | this.dataRef.child(name).set(gs.toJavascript(value)); 22 | */} 23 | 24 | @GsNative 25 | private initFirebase(String url) {/* 26 | this.dataRef = new Firebase(url); 27 | */} 28 | 29 | @GsNative 30 | private doOnEvent(String name, String nameMethod) {/* 31 | gSobject.dataRef.child(name).on('value', function(snapshot) { 32 | gSobject[nameMethod](gs.toGroovy(snapshot.val())); 33 | }); 34 | */} 35 | } 36 | -------------------------------------------------------------------------------- /src/main/groovy/firebase/GrooscriptFirebase.groovy: -------------------------------------------------------------------------------- 1 | package firebase 2 | 3 | class GrooscriptFirebase extends BaseFirebase { 4 | GrooscriptFirebase() { 5 | super('https://vivid-fire-5565.firebaseio.com/') 6 | } 7 | 8 | def onMessage(message) { 9 | println "Message received: $message" 10 | $('body').append "

Message received: ${message}

" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/groovy/firebaseAction.groovy: -------------------------------------------------------------------------------- 1 | import firebase.GrooscriptFirebase 2 | 3 | 4 | def firebase = new GrooscriptFirebase() 5 | def message = [list: [1, 2, 3], number: 5, name: 'grooscript'] 6 | $('body').append "

Send message: ${message}

" 7 | firebase.message = message 8 | $('body').append "

Done synchronous!

" -------------------------------------------------------------------------------- /src/main/groovy/game/Cell.groovy: -------------------------------------------------------------------------------- 1 | package game 2 | 3 | class Cell { 4 | def value 5 | 6 | void reset() { 7 | value = null 8 | } 9 | 10 | boolean equals(Cell other) { 11 | this.value && other.value && value == other.value 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/groovy/game/Game.groovy: -------------------------------------------------------------------------------- 1 | package game 2 | 3 | class Game { 4 | 5 | def size = 4 6 | def total = size * size 7 | def goal = 2048 8 | def initialNumbers = 2 9 | 10 | // 0 . 1 . 2 . 3 11 | // 4 . 5 . 6 . 7 12 | // 8 . 9 . 10 . 11 13 | // 12 . 13 . 14 . 15 14 | 15 | List cells 16 | def rows 17 | def columns 18 | 19 | Game() { 20 | cells = [] 21 | rows = [] 22 | columns = [] 23 | total.times { 24 | cells << new Cell() 25 | } 26 | size.times { number -> 27 | def row = [] 28 | def column = [] 29 | size.times { 30 | row << cells[number * size + it] 31 | column << cells[ it * size + number] 32 | } 33 | rows[number] = row 34 | columns[number] = column 35 | } 36 | initialNumbers.times { 37 | addRandomNumber() 38 | } 39 | } 40 | 41 | def processLine(List line) { 42 | compressLine(line) 43 | joinLine(line) 44 | compressLine(line) 45 | } 46 | 47 | boolean isDone() { 48 | cells.any { it.value >= goal } 49 | } 50 | 51 | boolean isFull() { 52 | cells.every { it.value } 53 | } 54 | 55 | void addRandomNumber() { 56 | def empties = cells.findAll { !it.value } 57 | empties[new Random().nextInt(empties.size())].value = 2 58 | } 59 | 60 | void moveRight() { 61 | rows.each { 62 | processLine it.reverse() 63 | } 64 | } 65 | 66 | void moveLeft() { 67 | rows.each { 68 | processLine it 69 | } 70 | } 71 | 72 | void moveUp() { 73 | columns.each { 74 | processLine it 75 | } 76 | } 77 | 78 | void moveDown() { 79 | columns.each { 80 | processLine it.reverse() 81 | } 82 | } 83 | 84 | private joinLine(List line) { 85 | (size - 1).times { number -> 86 | if (line[number] == line[number + 1]) { 87 | line[number].value = line[number].value * 2 88 | line[number + 1].reset() 89 | } 90 | } 91 | } 92 | 93 | private compressLine(List line) { 94 | def lineCompressed = line.findAll { it.value } 95 | line.eachWithIndex { cell, i -> 96 | if (i < lineCompressed.size()) { 97 | cell.value = lineCompressed[i].value 98 | } else { 99 | cell.reset() 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/groovy/game/GamePresenter.groovy: -------------------------------------------------------------------------------- 1 | package game 2 | 3 | import org.grooscript.builder.HtmlBuilder 4 | 5 | /** 6 | * User: jorgefrancoleza 7 | * Date: 15/07/14 8 | */ 9 | class GamePresenter { 10 | 11 | Game game 12 | def allowMove = true 13 | 14 | def init() { 15 | game = new Game() 16 | $('#result').html '' 17 | drawGame() 18 | } 19 | 20 | def drawGame() { 21 | $('#gameTable').html htmlFromGame 22 | } 23 | 24 | def getHtmlFromGame() { 25 | HtmlBuilder.build { 26 | table(class: 'table') { 27 | game.rows.each { row -> 28 | tr { 29 | row.each { cell -> 30 | td(class: 'cell') { 31 | p "${cell.value ?: ''}" 32 | } 33 | } 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | def move(adress) { 41 | if (allowMove) { 42 | game."move${adress.capitalize()}"() 43 | if (game.isFull()) { 44 | allowMove = false 45 | $('#result').html '

You have lost

' 46 | } else if (game.isDone()) { 47 | allowMove = false 48 | $('#result').html '

Congratulations, you have finished!

' 49 | } else { 50 | game.addRandomNumber() 51 | } 52 | drawGame() 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/groovy/jQueryRest.groovy: -------------------------------------------------------------------------------- 1 | import rest.JQueryRestApi 2 | 3 | class Author implements JQueryRestApi { 4 | Long id 5 | String name 6 | String city 7 | String image 8 | int age 9 | 10 | String toString() { 11 | "id: ${id} name: ${name}" 12 | } 13 | } 14 | 15 | def onError = { jqXHR, status -> 16 | println "Error jqXHR: ${jqXHR} status: ${status}" 17 | } 18 | 19 | Author.url = 'http://localhost:3000' 20 | Author.resource ='authors' 21 | 22 | def api = new Author() 23 | api.one(1, { data -> 24 | def author = new Author(data) 25 | println "Success one: ${author}" 26 | }, onError) 27 | api.all({ authors -> 28 | println "Success all: ${authors.size()}" 29 | authors.findAll { it.image }.each { 30 | $('body').append("") 31 | } 32 | }, onError) 33 | 34 | def newAuthor = new Author(name: "Jorge Franco", city: "Madrid / Sevilla", image: "img/logo.png") 35 | newAuthor.add({ data -> 36 | println "Success add: ${data.id}" 37 | api.all({ authors -> 38 | println "Success after insert ${data.name}: ${authors.size()}" 39 | }, onError) 40 | }, onError) -------------------------------------------------------------------------------- /src/main/groovy/maps/GoogleMap.groovy: -------------------------------------------------------------------------------- 1 | package maps 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | /** 6 | * Created by jorgefrancoleza on 7/6/15. 7 | */ 8 | class GoogleMap { 9 | 10 | Map options = [ 11 | zoom: 8 12 | ] 13 | private List _style 14 | private List _marks = [] 15 | 16 | static GoogleMap init(@DelegatesTo(GoogleMap) Closure actions) { 17 | def map = new GoogleMap() 18 | actions.delegate = map 19 | actions() 20 | map 21 | } 22 | 23 | @GsNative 24 | def ltlg(latitude, longitude) {/* 25 | return new google.maps.LatLng(latitude, longitude); 26 | */} 27 | 28 | void putStyle(List styles) { 29 | _style = styles 30 | } 31 | 32 | void mark(Map options) { 33 | _marks << options 34 | } 35 | 36 | @GsNative 37 | void start(String selectorId) {/* 38 | var style = this._style; 39 | var options = this.options; 40 | var marks = this._marks; 41 | google.maps.event.addDomListener(window, 'load', function() { 42 | var MY_MAPTYPE_ID = 'custom_style'; 43 | if (style) { 44 | options['mapTypeControlOptions'] = { 45 | mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID] 46 | } 47 | options['mapTypeId'] = MY_MAPTYPE_ID; 48 | } 49 | var map = new google.maps.Map(document.getElementById(selectorId), gs.toJavascript(options)); 50 | if (style) { 51 | var styledMapOptions = {name: 'Custom Style'}; 52 | var customMapType = new google.maps.StyledMapType(gs.toJavascript(style), styledMapOptions); 53 | map.mapTypes.set(MY_MAPTYPE_ID, customMapType); 54 | } 55 | marks.each(function(mark) { 56 | mark.map = map; 57 | var googleMark = new google.maps.Marker(gs.toJavascript(mark)); 58 | if (mark.infoWindow) { 59 | var infowindow = new google.maps.InfoWindow({content: mark.infoWindow}); 60 | google.maps.event.addListener(googleMark, 'click', function() { 61 | infowindow.open(map, googleMark); 62 | }); 63 | } 64 | }); 65 | }); 66 | */} 67 | } 68 | -------------------------------------------------------------------------------- /src/main/groovy/nodejs/NodeJs.groovy: -------------------------------------------------------------------------------- 1 | package nodejs 2 | 3 | import colors.JsColors 4 | import org.grooscript.asts.GsNative 5 | 6 | class NodeJs implements JsColors { //<1> 7 | 8 | @GsNative //<2> 9 | def module(String name) {/* 10 | try { 11 | global[name] = require(name); 12 | } catch(err) { 13 | this.red('Module '+name+' not installed, please install it.'); 14 | } 15 | */} 16 | 17 | NodeJs() { 18 | module 'colors' //<3> 19 | } 20 | 21 | def countBodyChars(String url) { 22 | def time = new Date() 23 | grey " Going $url" 24 | request(url, { error, response, body -> //<4> 25 | if (!error && response.statusCode == 200) { 26 | println "$url body size: ${body.size()} time: ${new Date().time - time.time}" 27 | } else { 28 | println "Error: ${error}" 29 | } 30 | }) 31 | } 32 | 33 | def parallel(List closures) { 34 | async.parallel closures //<5> 35 | } 36 | 37 | static nodejs(@DelegatesTo(NodeJs) Closure cl) { //<6> 38 | def node = new NodeJs() 39 | cl.delegate = node 40 | cl() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/groovy/observeRx.groovy: -------------------------------------------------------------------------------- 1 | import dualrx.GrooscriptObservable 2 | 3 | GrooscriptObservable.fromList(["one", "two", "three"]) 4 | .take(2) 5 | .subscribe({arg -> println(arg)}) 6 | -------------------------------------------------------------------------------- /src/main/groovy/paint/Draw.groovy: -------------------------------------------------------------------------------- 1 | package paint 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | class Draw { 6 | 7 | Functions functions = new Functions() 8 | def r = new Random() 9 | def colors = [ 10 | [r: 232, g: 51, b: 1], 11 | [r: 248, g: 179, b: 10], 12 | [r: 247, g: 239, b: 189], 13 | [r: 29, g: 16, b: 8], 14 | ] 15 | static final PRECISSION = 800 16 | static final N_GRADES = 9 17 | def maxWidth = 500 18 | def maxHeight = 500 19 | 20 | def ctx 21 | def ctxWidth 22 | def ctxHeight 23 | 24 | Draw(idCanvas) { 25 | initCanvas(idCanvas) 26 | } 27 | 28 | /** 29 | * Draw random bezier 30 | * @return 31 | */ 32 | def random() { 33 | def points = [] 34 | 35 | N_GRADES.times { 36 | points << [x: r.nextInt(maxWidth), y: r.nextInt(maxHeight)] 37 | } 38 | def movex = r.nextInt(ctxWidth) 39 | def movey = r.nextInt(ctxHeight) 40 | def finalPoints = points.collect { 41 | [ 42 | x: it.x - maxWidth / 2 + movex, 43 | y: it.y - maxHeight / 2 + movey 44 | ] 45 | } 46 | 47 | drawBezier(finalPoints) 48 | } 49 | 50 | private void drawBezier(List points) { 51 | def xList = points.collect { it.x } 52 | def yList = points.collect { it.y } 53 | def color = colors[r.nextInt(4)] 54 | def width = r.nextInt(30) + 35 55 | (1..PRECISSION).each { it -> 56 | def posx = functions.nBezier(it / PRECISSION, xList) 57 | def posy = functions.nBezier(it / PRECISSION, yList) 58 | drawCircle(posx, posy, color, it / width) 59 | //Random drop 60 | if (r.nextInt(100) > 97) { 61 | drawCircle(posx + 20, posy + 20, color, it / width / 2) 62 | } 63 | } 64 | } 65 | 66 | @GsNative 67 | private void initCanvas(name) {/* 68 | var canvas = document.getElementById(name); 69 | this.ctxWidth = canvas.width; 70 | this.ctxHeight = canvas.height; 71 | this.ctx = canvas.getContext('2d'); 72 | */} 73 | 74 | @GsNative 75 | private void drawCircle(x, y, color, radius) {/* 76 | this.ctx.beginPath(); 77 | this.ctx.arc(x, y, radius, 0, 2 * Math.PI, false); 78 | this.ctx.fillStyle = "rgb("+color.r+", "+color.g+", "+ color.b +")"; 79 | this.ctx.fill(); 80 | */} 81 | } 82 | -------------------------------------------------------------------------------- /src/main/groovy/paint/Functions.groovy: -------------------------------------------------------------------------------- 1 | package paint 2 | 3 | class Functions { 4 | 5 | /** 6 | * Get bezier point in interval t 7 | * @param t [0, 1] 8 | * @param points List of values 9 | * @return Position at interval 10 | */ 11 | BigDecimal nBezier(t, List points) { 12 | def length = points.size() - 1 13 | points.inject([index: 0, sum: 0]) { acc, value -> 14 | acc.sum += coef(length, acc.index) * (value - (points[0])) * 15 | Math.pow((1 - t), length - acc.index) * 16 | Math.pow(t, acc.index) 17 | acc.index++ 18 | acc 19 | }.sum + points[0] 20 | } 21 | 22 | private coef(m, n) { 23 | if (m == n || n == 0) { 24 | return 1 25 | } else { 26 | return fact(m) / ( fact(n) * fact(m - n )) 27 | } 28 | } 29 | 30 | private fact(n) { 31 | def result 32 | switch (n) { 33 | case 2: 34 | result = 2 35 | break 36 | case 3: 37 | result = 3 38 | break 39 | case 4: 40 | result = 6 41 | break 42 | case 5: 43 | result = 24 44 | break 45 | case 6: 46 | result = 120 47 | break 48 | case 7: 49 | result = 720 50 | break 51 | case 8: 52 | result = 5040 53 | break 54 | case 9: 55 | result = 40320 56 | break 57 | case 10: 58 | result = 362880 59 | break 60 | default: 61 | result = 1 62 | } 63 | result 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/groovy/raphael/Stars.groovy: -------------------------------------------------------------------------------- 1 | package raphael 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | /** 6 | * Created by jorgefrancoleza on 19/1/15. 7 | */ 8 | class Stars { 9 | 10 | static final STARS_NUMBER = 1500 11 | 12 | def context 13 | def groovyImage 14 | def grailsImage 15 | def height 16 | def width 17 | def random = new Random() 18 | def stars = [] 19 | 20 | void start(id) { 21 | initCanvas(id) 22 | STARS_NUMBER.times { 23 | def size = (random.nextInt(10) / 10 + 0.5) * 3 24 | stars << [ 25 | x: random.nextInt(width), 26 | y: random.nextInt(height), 27 | speed: size * 3, 28 | size: size 29 | ] 30 | } 31 | draw(this.&initAndMove) 32 | } 33 | 34 | void initAndMove() { 35 | context.fillStyle = "#000000" 36 | context.fillRect(0, 0, width, height) 37 | context.fillStyle = "#FFFFFF" 38 | stars.each { star -> 39 | def newX = star.x + star.speed 40 | if (newX > width) { 41 | newX = 0 42 | } 43 | star.x = newX 44 | context.fillRect(star.x, star.y, star.size, star.size) 45 | } 46 | context.drawImage(groovyImage, width - 210, height -110) 47 | context.drawImage(grailsImage, 10, height -110, 100, 100) 48 | context.font = "48px serif" 49 | context.fillText("Keep on groovy'ing!", width / 2 - 190, height -50) 50 | context.font = "24px serif" 51 | context.fillText("While groovy and grails crew looking for a new home...", 50, 60) 52 | } 53 | 54 | @GsNative 55 | private draw(closure) {/* 56 | setInterval(closure, 1000/60); 57 | */} 58 | 59 | @GsNative 60 | private initCanvas(id) {/* 61 | var canvas = document.getElementById(id); 62 | canvas.width = document.body.clientWidth; 63 | canvas.height = document.body.clientHeight; 64 | gSobject.height = canvas.height; 65 | gSobject.width = canvas.width; 66 | gSobject.context = canvas.getContext("2d"); 67 | 68 | gSobject.groovyImage = document.getElementById("groovyImage"); 69 | gSobject.grailsImage = document.getElementById("grailsImage"); 70 | */} 71 | } -------------------------------------------------------------------------------- /src/main/groovy/react.groovy: -------------------------------------------------------------------------------- 1 | import org.grooscript.jquery.GQueryImpl //<1> 2 | import react.TodoApp 3 | 4 | def renderComponent = { component, selector -> 5 | def gQuery = new GQueryImpl() 6 | gQuery.onReady { 7 | component.start(selector) //<4> 8 | } 9 | } 10 | 11 | renderComponent(new TodoApp(), '#todos') //<5> 12 | -------------------------------------------------------------------------------- /src/main/groovy/react/Component.groovy: -------------------------------------------------------------------------------- 1 | package react 2 | 3 | import org.codehaus.groovy.transform.GroovyASTTransformationClass 4 | 5 | import java.lang.annotation.ElementType 6 | import java.lang.annotation.Retention 7 | import java.lang.annotation.RetentionPolicy 8 | import java.lang.annotation.Target 9 | 10 | @Retention(RetentionPolicy.SOURCE) 11 | @Target([ElementType.TYPE]) 12 | @GroovyASTTransformationClass(['react.ComponentImpl']) 13 | public @interface Component { 14 | } 15 | -------------------------------------------------------------------------------- /src/main/groovy/react/ComponentImpl.groovy: -------------------------------------------------------------------------------- 1 | package react 2 | 3 | import org.codehaus.groovy.ast.ASTNode 4 | import org.codehaus.groovy.ast.AnnotationNode 5 | import org.codehaus.groovy.ast.ClassHelper 6 | import org.codehaus.groovy.ast.ClassNode 7 | import org.codehaus.groovy.ast.MethodNode 8 | import org.codehaus.groovy.ast.Parameter 9 | import org.codehaus.groovy.ast.VariableScope 10 | import org.codehaus.groovy.ast.builder.AstBuilder 11 | import org.codehaus.groovy.ast.expr.ArgumentListExpression 12 | import org.codehaus.groovy.ast.expr.ClassExpression 13 | import org.codehaus.groovy.ast.expr.ClosureExpression 14 | import org.codehaus.groovy.ast.expr.ConstructorCallExpression 15 | import org.codehaus.groovy.ast.expr.MethodCallExpression 16 | import org.codehaus.groovy.ast.expr.PropertyExpression 17 | import org.codehaus.groovy.ast.expr.VariableExpression 18 | import org.codehaus.groovy.ast.stmt.BlockStatement 19 | import org.codehaus.groovy.ast.stmt.ExpressionStatement 20 | import org.codehaus.groovy.control.CompilePhase 21 | import org.codehaus.groovy.control.SourceUnit 22 | import org.codehaus.groovy.transform.ASTTransformation 23 | import org.codehaus.groovy.transform.GroovyASTTransformation 24 | import org.grooscript.builder.HtmlBuilder 25 | import org.grooscript.jquery.GQueryImpl 26 | 27 | import java.lang.reflect.Modifier 28 | 29 | @GroovyASTTransformation(phase=CompilePhase.SEMANTIC_ANALYSIS) 30 | public class ComponentImpl implements ASTTransformation { 31 | 32 | public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { 33 | //Start 34 | if (!nodes[0] instanceof AnnotationNode || !nodes[1] instanceof ClassNode) { 35 | return 36 | } 37 | 38 | ClassNode classNode = (ClassNode) nodes[1] 39 | ClassNode jQueryImpl = new ClassNode(GQueryImpl) 40 | 41 | addDrawMethod(classNode) 42 | 43 | addStartMethod(classNode) 44 | 45 | classNode.properties.each { propertyNode -> 46 | if (propertyNode.type.name == 'java.lang.String') { 47 | addSetMethod(classNode, propertyNode.name) 48 | } 49 | } 50 | 51 | classNode.addProperty('gQuery', Modifier.PUBLIC , jQueryImpl, 52 | new ConstructorCallExpression(jQueryImpl, ArgumentListExpression.EMPTY_ARGUMENTS), null, null) 53 | classNode.addProperty('selector', Modifier.PUBLIC , ClassHelper.STRING_TYPE, null, null, null) 54 | 55 | manageRenderMethod(classNode) 56 | } 57 | 58 | private addSetMethod(ClassNode classNode, String nameProperty) { 59 | def params = new Parameter[1] 60 | params[0] = new Parameter(ClassHelper.STRING_TYPE, nameProperty) 61 | classNode.addMethod("set${nameProperty.capitalize()}".toString(), Modifier.PUBLIC, null, params, 62 | ClassNode.EMPTY_ARRAY, new AstBuilder().buildFromString(""" 63 | this.${nameProperty} = ${nameProperty} 64 | this.draw() 65 | gQuery.focusEnd('#${nameProperty}') 66 | """)[0]) 67 | } 68 | 69 | private addDrawMethod(ClassNode classNode) { 70 | classNode.addMethod('draw', Modifier.PUBLIC, null, Parameter.EMPTY_ARRAY, 71 | ClassNode.EMPTY_ARRAY, new AstBuilder().buildFromString(''' 72 | this.render() 73 | gQuery.attachMethodsToDomEvents(this) 74 | ''')[0]) 75 | } 76 | 77 | private addStartMethod(ClassNode classNode) { 78 | def params = new Parameter[1] 79 | params[0] = new Parameter(ClassHelper.STRING_TYPE, 'selector') 80 | classNode.addMethod('start', Modifier.PUBLIC, null, params, 81 | ClassNode.EMPTY_ARRAY, new AstBuilder().buildFromString(''' 82 | this.selector = selector 83 | this.init() 84 | this.draw() 85 | ''')[0]) 86 | } 87 | 88 | private manageRenderMethod(ClassNode classNode) { 89 | MethodNode renderMethod = classNode.methods.find { it.name == 'render'} 90 | if (!renderMethod) { 91 | classNode.addMethod('render', Modifier.PUBLIC, null, Parameter.EMPTY_ARRAY, 92 | ClassNode.EMPTY_ARRAY, new AstBuilder().buildFromString(''' 93 | //Nothing to do 94 | ''')[0]) 95 | } else { 96 | BlockStatement actualCode = (BlockStatement)renderMethod.code 97 | 98 | VariableScope variableScope = actualCode.getVariableScope() 99 | VariableScope blockScope = variableScope.copy() 100 | 101 | ClosureExpression closure = new ClosureExpression(Parameter.EMPTY_ARRAY, actualCode) 102 | VariableScope closureScope = variableScope.copy() 103 | closure.setVariableScope(closureScope) 104 | 105 | renderMethod.setCode(new BlockStatement([ 106 | new ExpressionStatement( 107 | new MethodCallExpression( 108 | new MethodCallExpression( 109 | new PropertyExpression( 110 | new VariableExpression('this', ClassHelper.OBJECT_TYPE), 111 | 'gQuery' 112 | ), 113 | 'call', 114 | new ArgumentListExpression([ 115 | new VariableExpression('selector', ClassHelper.STRING_TYPE) 116 | ]) 117 | ), 118 | 'html', 119 | new ArgumentListExpression([ 120 | new MethodCallExpression( 121 | new ClassExpression(new ClassNode(HtmlBuilder)), 122 | 'build' , 123 | new ArgumentListExpression([ 124 | closure 125 | ]) 126 | ) 127 | ]) 128 | ) 129 | ) 130 | ], blockScope)) 131 | } 132 | } 133 | } -------------------------------------------------------------------------------- /src/main/groovy/react/TodoApp.groovy: -------------------------------------------------------------------------------- 1 | package react 2 | 3 | @Component //<1> 4 | class TodoApp { 5 | List todos //<2> 6 | String actualTodo //<3> 7 | 8 | void init() { //<4> 9 | todos = [] 10 | actualTodo = '' 11 | } 12 | 13 | void actualTodoChange(actualTodoValue) { //<5> 14 | setActualTodo(actualTodoValue) 15 | } 16 | 17 | void addTodosSubmit() { //<6> 18 | if (actualTodo) { 19 | todos << actualTodo 20 | setActualTodo('') 21 | } 22 | } 23 | 24 | void render() { //<7> 25 | form(id: 'addTodos') { 26 | h3 'TODO' 27 | ul { 28 | todos.each { 29 | li it 30 | } 31 | li { 32 | input(type: 'text', id: 'actualTodo', value: actualTodo) 33 | button { 34 | yield "Add #${todos.size() + 1}" 35 | } 36 | } 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/groovy/reactNative/awesome.groovy: -------------------------------------------------------------------------------- 1 | package reactNative 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | /** 6 | * Created by jorgefrancoleza on 27/3/15. 7 | */ 8 | import static org.grooscript.GrooScript.toJavascript 9 | 10 | class Components { 11 | def list = [] 12 | 13 | def methodMissing(String name, args) { 14 | list << React.createElement(component(name), toJavascript(args[0]), args[1]) 15 | } 16 | 17 | def image(Map args) { 18 | list << React.createElement(component('image'), toJavascript(args)) 19 | } 20 | 21 | @GsNative 22 | private component(name) {/* 23 | if (name == 'text') return Text; 24 | if (name == 'image') return Image; 25 | */} 26 | } 27 | 28 | class GroovyView { 29 | def data(map, Closure closure) { 30 | def allParams = [View, map] 31 | def components = new Components() 32 | closure.delegate = components 33 | closure() 34 | components.list.each { 35 | allParams << it 36 | } 37 | React.createElement.apply(React, allParams) 38 | } 39 | } 40 | 41 | def styles = StyleSheet.create toJavascript( 42 | container: [ 43 | flex: 1, 44 | justifyContent: 'center', 45 | alignItems: 'center', 46 | backgroundColor: '#ffffff', 47 | ], 48 | welcome: [ 49 | fontSize: 20, 50 | textAlign: 'center', 51 | margin: 10, 52 | ], 53 | image: [ 54 | width: 192, 55 | height: 96, 56 | ] 57 | ) 58 | 59 | def AwesomeProject = React.createClass( 60 | render: { 61 | def groovyView = new GroovyView() 62 | groovyView.data(style: styles.container) { 63 | image style: styles.image, source: [uri: 'http://grooscript.org/img/groovy.png'] 64 | text style: styles.welcome, "Hello #ios from #groovylang" 65 | text style: styles.welcome, "With @grooscript" 66 | text style: styles.welcome, "and @reactjs native" 67 | } 68 | }) -------------------------------------------------------------------------------- /src/main/groovy/rest/JQueryRestApi.groovy: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | trait JQueryRestApi { 6 | static String url 7 | static String resource 8 | 9 | void add(Closure onSuccess, Closure onError) { 10 | ajaxCall('POST', "${url}/${resource}", onSuccess, onError) 11 | } 12 | 13 | void one(Long id, Closure onSuccess, Closure onError) { 14 | ajaxCall('GET', "${url}/${resource}/${id}", onSuccess, onError) 15 | } 16 | 17 | void all(Closure onSuccess, Closure onError) { 18 | ajaxCall('GET', "${url}/${resource}", onSuccess, onError) 19 | } 20 | 21 | @GsNative 22 | void ajaxCall(String type, String url, Closure onSuccess, Closure onError) {/* 23 | jQuery.ajax({ 24 | type: type, 25 | url: url, 26 | data: (type == 'POST' ? JSON.stringify(gs.toJavascript($self)) : null), 27 | contentType: "application/json; charset=utf-8", 28 | dataType: "json", 29 | success: function (data, status, jqXHR) { 30 | onSuccess(data); 31 | }, 32 | error: function (jqXHR, status) { 33 | onError(jqXHR, status); 34 | } 35 | }); 36 | */} 37 | } 38 | -------------------------------------------------------------------------------- /src/main/groovy/rxjs/autocomplete.groovy: -------------------------------------------------------------------------------- 1 | package rxjs 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | import static org.grooscript.GrooScript.toJavascript 6 | import static rxjs.ReactiveResolver.reactive 7 | 8 | reactive { 9 | def searchWikipedia = { term -> 10 | jQuery.ajax(url: 'http://en.wikipedia.org/w/api.php', 11 | dataType: 'jsonp', 12 | data: toJavascript([ 13 | action: 'opensearch', 14 | format: 'json', 15 | search: window.encodeURI(term) 16 | ]) 17 | ).promise() 18 | } 19 | 20 | def results = $('#results') 21 | def textInput = $('#textInput') 22 | def main = { 23 | def keyUp = fromEvent(textInput, 'keyup') 24 | .map { it.target.value } 25 | .filter { text -> text.size() > 2 } 26 | .debounce(750) 27 | .distinctUntilChanged() 28 | 29 | def searcher = keyUp.flatMapLatest(searchWikipedia) 30 | 31 | searcher.subscribe( 32 | { data -> 33 | results.empty() 34 | data[1].each { 35 | results.append "
  • $it
  • " 36 | } 37 | }, 38 | { error -> 39 | results.empty() 40 | results.append "
  • Error: $error
  • " 41 | }) 42 | } 43 | main() 44 | } 45 | 46 | class ReactiveResolver { 47 | 48 | static reactive(@DelegatesTo(ReactiveResolver) Closure cl) { 49 | def resolver = new ReactiveResolver() 50 | cl.delegate = resolver 51 | cl() 52 | } 53 | 54 | @GsNative 55 | def fromEvent(domElement, String eventName) {/* 56 | return Rx.Observable.fromEvent(domElement, eventName) 57 | */} 58 | } -------------------------------------------------------------------------------- /src/main/groovy/rxjs/autocompleteTwo.groovy: -------------------------------------------------------------------------------- 1 | package rxjs 2 | 3 | import groovy.transform.BaseScript 4 | import org.grooscript.asts.GsNative 5 | 6 | import static org.grooscript.GrooScript.toJavascript 7 | 8 | @BaseScript 9 | ReactiveScript baseScript 10 | 11 | def keyUp = observeEvent(textInput, 'keyup') 12 | .map { it.target.value } 13 | .filter { text -> text.size() > 2 } 14 | .debounce(750) 15 | .distinctUntilChanged() 16 | 17 | def searcher = keyUp.flatMapLatest(searchWikipedia) 18 | 19 | searcher.subscribe( 20 | { terms, resultsDom -> 21 | resultsDom.empty() 22 | terms[1].each { resultsDom.append "
  • $it
  • " } 23 | }.rcurry(results), { errorMessage, resultsDom -> 24 | resultsDom.empty() 25 | resultsDom.append "
  • Error: $errorMessage
  • " 26 | }.rcurry(results) 27 | ) 28 | 29 | class ReactiveScript extends Script { 30 | 31 | def selectors = [:] 32 | 33 | @GsNative 34 | def observeEvent(domElement, String eventName) {/* 35 | return Rx.Observable.fromEvent(domElement, eventName) 36 | */} 37 | 38 | def searchWikipedia = { term -> 39 | jQuery.ajax(url: 'http://en.wikipedia.org/w/api.php', 40 | dataType: 'jsonp', 41 | data: toJavascript([ 42 | action: 'opensearch', 43 | format: 'json', 44 | search: window.encodeURI(term) 45 | ]) 46 | ).promise() 47 | } 48 | 49 | def propertyMissing(String name) { 50 | if (!selectors[name]) { 51 | selectors[name] = $("#$name") 52 | } 53 | selectors[name] 54 | } 55 | 56 | def run() { } 57 | } -------------------------------------------------------------------------------- /src/main/groovy/snap.groovy: -------------------------------------------------------------------------------- 1 | import static snap.SnapSvg.snapSvg 2 | 3 | snapSvg('svg') { 4 | def middle = [x: 150, y: 150] 5 | circle cx: middle.x, cy: middle.y, r:145, fill: "none", stroke: "#000", strokeWidth: 3 6 | circle cx: middle.x, cy: middle.y, r:76, fill: "none", stroke: "#000", strokeWidth: 1 7 | def hourText = text x: middle.x, y: 30, text: "XII", fontSize: '30px', "text-anchor": "middle", fill: "#666" 8 | hourText.verticalScale = 2.4 9 | //Numbers 10 | def romanNumbers = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI'] 11 | 11.times { val -> 12 | def newHour = hourText.copy() 13 | newHour.text = romanNumbers[val] 14 | newHour.rotateAndScale(30 * (val + 1), 2.4, middle.x, middle.y) 15 | } 16 | //Seconds points 17 | def secondPoint = circle cx: middle.x, cy: 13, r:3, fill: "black", stroke: "#000" 18 | 59.times { val -> 19 | secondPoint.copy().rotate(6 * (val + 1), middle.x, middle.y).r = ((val + 1) % 5 ? 2 : 3) 20 | } 21 | //Clock hands 22 | def hours = rect x: middle.x - 2, y: 65, width: 4, height: 85, fill: "#000" 23 | def minutes = rect x: middle.x - 1, y: 40, width: 2, height: 110, fill: "#000" 24 | def seconds = rect x: middle.x - 0.5, y: 13, width: 1, height: 150, fill: "red" 25 | def rotateClockHands = { 26 | def nowValues = new Date().format('HH:mm:ss').split(':').collect { it.toInteger() } 27 | def hour = nowValues[0] % 12 28 | def minute = nowValues[1] 29 | hours.rotate((hour * 30) + (minute / 2), middle.x, middle.y) 30 | minutes.rotate(minute * 6, middle.x, middle.y) 31 | seconds.rotate(nowValues[2] * 6, middle.x, middle.y) 32 | } 33 | rotateClockHands() 34 | 35 | //Refresh each second 36 | repeat(1000, rotateClockHands) 37 | } 38 | -------------------------------------------------------------------------------- /src/main/groovy/snap/SnapSvg.groovy: -------------------------------------------------------------------------------- 1 | package snap 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | /** 6 | * Created by jorgefrancoleza on 23/11/14. 7 | */ 8 | class SnapSvg { 9 | 10 | private snap 11 | 12 | SnapSvg(selector) { 13 | snap = createSnap(selector) 14 | } 15 | 16 | Element circle(Map attributes) { 17 | createElement('circle', attributes) 18 | } 19 | 20 | Element text(Map attributes) { 21 | createElement('text', attributes) 22 | } 23 | 24 | Element rect(Map attributes) { 25 | createElement('rect', attributes) 26 | } 27 | 28 | @GsNative 29 | private createSnap(selector) {/* 30 | return Snap(selector); 31 | */} 32 | 33 | @GsNative 34 | private Element createElement(String name, Map attributes) {/* 35 | var element = Element(); 36 | var newSnap = this.snap.el(name, gs.toJavascript(attributes)); 37 | for (var ob in element) { 38 | newSnap[ob] = element[ob]; 39 | } 40 | return newSnap; 41 | */} 42 | 43 | @GsNative 44 | private void repeat(time, closure) {/* 45 | window.setInterval(closure, time); 46 | */} 47 | 48 | static snapSvg(String selector, @DelegatesTo(SnapSvg) Closure cl) { 49 | cl.delegate = new SnapSvg(selector) 50 | cl() 51 | } 52 | } 53 | 54 | class Element { 55 | @GsNative 56 | void setVerticalScale(scale) {/* 57 | this.transform('scale(1,'+scale+')'); 58 | */} 59 | 60 | @GsNative 61 | Element rotate(degrees, x, y) {/* 62 | this.transform('r'+degrees+','+x+','+y); 63 | return this; 64 | */} 65 | 66 | @GsNative 67 | void rotateAndScale(degrees, scale, x, y) {/* 68 | var t = new Snap.Matrix() 69 | .rotate(degrees, x, y) 70 | .scale(1, scale); 71 | this.transform(t); 72 | */} 73 | 74 | @GsNative 75 | Element copy() {/* 76 | var element = Element(); 77 | var newSnap = this.clone(); 78 | for (var ob in element) { 79 | newSnap[ob] = element[ob]; 80 | } 81 | return newSnap; 82 | */} 83 | 84 | @GsNative 85 | void setProperty(String name, value) {/* 86 | if (name == 'verticalScale') { 87 | this.setVerticalScale(value); 88 | } else { 89 | this.attr(gs.toJavascript(gs.map().add(name, value))); 90 | } 91 | */} 92 | } 93 | -------------------------------------------------------------------------------- /src/main/groovy/startLiveAdoc.groovy: -------------------------------------------------------------------------------- 1 | import asciidoctor.AdocLive 2 | import org.grooscript.jquery.GQueryImpl 3 | 4 | def renderComponent = { component, selector -> 5 | def gQuery = new GQueryImpl() 6 | gQuery.onReady { 7 | component.start(selector) 8 | } 9 | } 10 | 11 | renderComponent(new AdocLive(), '#asciidoctor') 12 | -------------------------------------------------------------------------------- /src/main/groovy/startMap.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by jorgefrancoleza on 7/6/15. 3 | */ 4 | import maps.GoogleMap 5 | 6 | GoogleMap.init { 7 | options.zoom = 6 8 | options.center = ltlg(40.4379543,-3.6795367 ) 9 | putStyle([ 10 | [stylers: [ [ visibility: 'simplified' ],[ gamma: 0.5 ],[ weight: 0.5 ] ] ], 11 | [featureType: 'water', stylers: [ [color: '#b77fd7'] ] ] 12 | ]) 13 | mark(position: ltlg(40.4379543,-3.6795367), 14 | title: 'grooscript', 15 | icon: "img/gs.png" 16 | ) 17 | mark(position: ltlg(41.39479,2.1487679), 18 | title: 'Champions!', 19 | icon: "img/barcelona.png", 20 | infoWindow: '' 21 | ) 22 | }.start('map-canvas') -------------------------------------------------------------------------------- /src/main/groovy/startServer.groovy: -------------------------------------------------------------------------------- 1 | import org.grooscript.templates.Templates 2 | 3 | import static chat.NodeServer.server 4 | 5 | server { 6 | get('/') { 7 | render Templates.applyTemplate('index.gtpl') 8 | } 9 | on('login') { data, socket -> 10 | if (data.name && !socket.login) { 11 | socket.login = data.name 12 | socket.emit 'loginok', [name: data.name] 13 | socket.broadcast.emit 'loginok', [name: data.name] 14 | } 15 | } 16 | on('msg') { data, socket -> 17 | if (data.msg && socket.login) { 18 | socket.broadcast.emit 'msg', [from: socket.login, msg: data.msg] 19 | } 20 | } 21 | on('disconnect') { socket -> 22 | if (socket.login) { 23 | socket.broadcast.emit 'off', [name: socket.login] 24 | } 25 | } 26 | }.start() 27 | -------------------------------------------------------------------------------- /src/main/groovy/three/Three.groovy: -------------------------------------------------------------------------------- 1 | package three 2 | 3 | import org.grooscript.asts.GsNative 4 | 5 | /** 6 | * Created by jorgefrancoleza on 17/2/15. 7 | */ 8 | class Three { 9 | 10 | def scene, camera, items = [], renderer, actions, material, grooscriptMaterial 11 | 12 | static Three scene(@DelegatesTo(Three) Closure closure) { 13 | Three three = new Three() 14 | closure.delegate = three 15 | three.scene = three.defaultScene 16 | three.camera = three.defaultCamera 17 | closure() 18 | three.renderer = three.defaultRenderer 19 | three 20 | } 21 | 22 | void animate(Closure closure) { 23 | actions = actions ?: closure 24 | animationFrame this.&animate 25 | actions(items) 26 | renderer.render scene, camera 27 | } 28 | 29 | def methodMissing(String name, args) { 30 | def mesh = newMesh(name.capitalize(), *args) 31 | mesh.metaClass.rotateLeft = { ob -> ob.rotation.y -= 0.02 }.curry(mesh) 32 | mesh.metaClass.moveTo = { ob, x, y, z -> ob.position.set(x, y, z) }.curry(mesh) 33 | scene.add mesh 34 | items << mesh 35 | mesh 36 | } 37 | 38 | @GsNative 39 | private getDefaultScene() {/* 40 | var scene = new THREE.Scene(); 41 | //Default material 42 | var map = THREE.ImageUtils.loadTexture('img/texture.jpg'); 43 | map.wrapS = map.wrapT = THREE.RepeatWrapping; 44 | map.anisotropy = 16; 45 | gSobject.material = new THREE.MeshLambertMaterial( { ambient: 0xbbbbbb, map: map, side: THREE.DoubleSide } ); 46 | var grooscriptMap = THREE.ImageUtils.loadTexture('img/logo.png'); 47 | gSobject.grooscriptMaterial = new THREE.MeshLambertMaterial( { ambient: 0xbbbbbb, map: grooscriptMap, side: THREE.DoubleSide } ); 48 | //Light 49 | scene.add( new THREE.AmbientLight(0xF0F0F0)); 50 | return scene; 51 | */} 52 | 53 | @GsNative 54 | private getDefaultCamera() {/* 55 | var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 ); 56 | camera.position.z = 1000; 57 | return camera; 58 | */} 59 | 60 | @GsNative 61 | private getDefaultRenderer() {/* 62 | var renderer = new THREE.WebGLRenderer(); 63 | renderer.setSize( window.innerWidth, window.innerHeight ); 64 | document.body.appendChild( renderer.domElement ); 65 | return renderer; 66 | */} 67 | 68 | @GsNative 69 | private newMesh(name, ...args) {/* 70 | var geo = gSobject.construct(THREE[name + 'Geometry'], args); 71 | var object = new THREE.Mesh(geo, gSobject.material); 72 | object.name = name; 73 | object.position.set(0, 0, 0); 74 | return object; 75 | */} 76 | 77 | @GsNative 78 | private void animationFrame(func) {/* 79 | requestAnimationFrame(func); 80 | */} 81 | 82 | @GsNative 83 | private construct(constructor, args) {/* 84 | function F() { 85 | return constructor.apply(this, args); 86 | } 87 | F.prototype = constructor.prototype; 88 | return new F(); 89 | */} 90 | } 91 | -------------------------------------------------------------------------------- /src/main/groovy/three/startThree.groovy: -------------------------------------------------------------------------------- 1 | package three 2 | 3 | /** 4 | * Created by jorgefrancoleza on 17/2/15. 5 | */ 6 | 7 | Three.scene { 8 | tetrahedron 200 moveTo -360, 300, 300 9 | icosahedron 200 moveTo 360, 200, 300 10 | sphere 100, 50, 50 moveTo -300, -200, 100 11 | torus 200, 50, 50, 50 moveTo -300, -200, 100 12 | ring 20, 200, 50 moveTo 450, -200, 100 13 | setMaterial(grooscriptMaterial) 14 | box 200, 200, 200 15 | }.animate { items -> 16 | items.findAll { it.name != 'Box' }.each { 17 | it.rotation.x += it.name != 'Torus' ? 0.01 : -0.01 18 | it.rotation.y += 0.02 19 | } 20 | items.findAll { it.name == 'Box' }.each { 21 | it.rotateLeft() 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/webapp/angular.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 |

    Todo

    15 |
    16 | {{remaining()}} of {{todos.length}} remaining 17 | [ archive ] 18 |
      19 |
    • 20 | 21 | {{todo.text}} 22 |
    • 23 |
    24 |
    25 | 27 | 28 |
    29 |
    30 | 31 | -------------------------------------------------------------------------------- /src/main/webapp/angularTwo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 |

    Todo

    15 |
    16 | {{remaining()}} of {{todos.length}} remaining 17 | [ archive ] 18 |
      19 |
    • 20 | 21 | {{todo.text}} 22 |
    • 23 |
    24 |
    25 | 27 | 28 |
    29 |
    30 | 31 | -------------------------------------------------------------------------------- /src/main/webapp/asciidoctor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Initial static web page 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
    15 |

    Asciidoctor live conversion with grooscript

    16 |
    17 |
    18 | -------------------------------------------------------------------------------- /src/main/webapp/autocomplete.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | RxJs grooscript demo! 10 | 11 | 12 | 13 |
    14 | 18 |
    19 |
    20 |
    21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 |
      28 |
      29 |
      30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/webapp/autocompleteTwo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | RxJs grooscript demo! 10 | 11 | 12 | 13 |
      14 | 18 |
      19 |
      20 |
      21 | 22 | 23 |
      24 |
      25 |
      26 |
      27 |
        28 |
        29 |
        30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/webapp/bezier.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Initial static web page 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 32 | -------------------------------------------------------------------------------- /src/main/webapp/css/chat.css: -------------------------------------------------------------------------------- 1 | * { margin: 0; padding: 0; box-sizing: border-box; } 2 | body, input, button { font: 20px Helvetica, Arial; } 3 | #message { background: #000; padding: 3px; bottom: 0; width: 100%; } 4 | #chatArea { border: 0; padding: 10px; width: 600px; margin: auto; } 5 | #message input { width: 85%; border: none; padding: 0px; padding: 10px;} 6 | #message button { width: 15%; background: rgb(130, 224, 255); border: none; padding: 10px; } 7 | #messages { list-style-type: none; margin: 0; padding: 0; } 8 | #messages li { padding: 5px 10px; text-align: left } 9 | #messages li:nth-child(odd) { background: #eee; } 10 | 11 | header { 12 | padding: 50px; 13 | text-align: center; 14 | } 15 | header h2 { 16 | padding-bottom: 20px; 17 | } 18 | section { 19 | text-align: center; 20 | } 21 | 22 | #loginArea button { 23 | margin-left: 10px; 24 | padding: 2px; 25 | width: 150px; 26 | } -------------------------------------------------------------------------------- /src/main/webapp/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | width: 100%; 3 | margin: 0; 4 | font-family: Lato; 5 | font-size: 22px; 6 | } 7 | 8 | a { 9 | text-decoration: none; 10 | } 11 | 12 | ul { 13 | padding-left: 0px; 14 | } 15 | 16 | li { 17 | padding-top: 10px; 18 | width: 200px; 19 | text-align: center; 20 | list-style: none; 21 | display: inline-block; 22 | } 23 | 24 | #mainTitle { 25 | position: absolute; 26 | top: 75px; 27 | left: 600px; 28 | font-family: Monaco; 29 | font-size: 2em; 30 | } 31 | 32 | .cell { 33 | width: 100px; 34 | height: 100px; 35 | max-height: 100px; 36 | background-color: coral; 37 | font-family: Monaco; 38 | } 39 | 40 | .table { 41 | margin-left: auto; 42 | margin-right: auto; 43 | } 44 | 45 | .center { 46 | width: 100%; 47 | margin-left: auto; 48 | margin-right: auto; 49 | text-align: center; 50 | } 51 | 52 | td { 53 | text-align: center; 54 | vertical-align: middle; 55 | } -------------------------------------------------------------------------------- /src/main/webapp/css/todo.css: -------------------------------------------------------------------------------- 1 | .done-true { 2 | text-decoration: line-through; 3 | color: grey; 4 | } -------------------------------------------------------------------------------- /src/main/webapp/firebase.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Firebase demon 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 51 | -------------------------------------------------------------------------------- /src/main/webapp/game.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2048 Game 5 | 6 | 7 | 8 | 9 |
        10 |

        2048 with grooscript

        11 |
        12 |
        13 |
        14 |
        15 |
        16 | 17 | -------------------------------------------------------------------------------- /src/main/webapp/img/barcelona.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/src/main/webapp/img/barcelona.png -------------------------------------------------------------------------------- /src/main/webapp/img/campeon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/src/main/webapp/img/campeon.jpg -------------------------------------------------------------------------------- /src/main/webapp/img/grails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/src/main/webapp/img/grails.png -------------------------------------------------------------------------------- /src/main/webapp/img/groovy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/src/main/webapp/img/groovy.png -------------------------------------------------------------------------------- /src/main/webapp/img/gs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/src/main/webapp/img/gs.png -------------------------------------------------------------------------------- /src/main/webapp/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/src/main/webapp/img/logo.png -------------------------------------------------------------------------------- /src/main/webapp/img/texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiquitinxx/grooscript-demos/1d73fcfa90203d43262af543e6d332f0fe31e6ca/src/main/webapp/img/texture.jpg -------------------------------------------------------------------------------- /src/main/webapp/jqueryrest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Grooscript Map 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/webapp/js/AdocLive.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function AdocLive() { 3 | var gSobject = gs.init('AdocLive'); 4 | gSobject.clazz = { name: 'asciidoctor.AdocLive', simpleName: 'AdocLive'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.adocCode = null; 7 | gSobject.convertedCode = null; 8 | gSobject.gQuery = GQueryImpl(); 9 | gSobject.selector = null; 10 | gSobject['init'] = function(it) { 11 | gSobject.adocCode = "http://asciidoctor.org[*Asciidoctor*]\nrunning on http://opalrb.org[_Opal_]\nbrings AsciiDoc to the browser!"; 12 | return gSobject.convertedCode = gs.mc(gSobject,"convert",[gSobject.adocCode]); 13 | } 14 | gSobject.convert = function(toConvert) { 15 | var options = Opal.hash2(['attributes'], {attributes: ['showtitle']}); 16 | return Opal.Asciidoctor.$convert(toConvert, options); 17 | } 18 | gSobject['adocCodeChange'] = function(newText) { 19 | gSobject.convertedCode = gs.mc(gSobject,"convert",[newText]); 20 | return gs.mc(gSobject,"setAdocCode",[newText]); 21 | } 22 | gSobject['render'] = function(it) { 23 | return gs.mc(gs.execCall(gs.gp(gs.thisOrObject(this,gSobject),"gQuery"), this, [gSobject.selector]),"html",[gs.execStatic(HtmlBuilder,'build', this,[function(it) { 24 | gs.mc(this,"h3",["Asciidoctor code:"], gSobject); 25 | gs.mc(this,"p",["* Stay alert, your cursor move to the end after each change"], gSobject); 26 | gs.mc(this,"textarea",[gs.map().add("id","adocCode").add("cols",100).add("rows",14), function(it) { 27 | return gs.mc(this,"yieldUnescaped",[gSobject.adocCode], gSobject); 28 | }], gSobject); 29 | gs.mc(this,"h3",["Html Result:"], gSobject); 30 | gs.mc(this,"hr",[], gSobject); 31 | return gs.mc(this,"div",[function(it) { 32 | return gs.mc(this,"yieldUnescaped",[gSobject.convertedCode], gSobject); 33 | }], gSobject); 34 | }])]); 35 | } 36 | gSobject['draw'] = function(it) { 37 | gs.mc(gSobject,"render",[]); 38 | return gs.mc(gSobject.gQuery,"attachMethodsToDomEvents",[this]); 39 | } 40 | gSobject['start'] = function(selector) { 41 | gs.sp(this,"selector",selector); 42 | gs.mc(gSobject,"init",[]); 43 | return gs.mc(gSobject,"draw",[]); 44 | } 45 | gSobject['setAdocCode'] = function(adocCode) { 46 | this["adocCode"] = adocCode; 47 | gs.mc(gSobject,"draw",[]); 48 | return gs.mc(gSobject.gQuery,"focusEnd",["#adocCode"]); 49 | } 50 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 51 | 52 | return gSobject; 53 | }; 54 | -------------------------------------------------------------------------------- /src/main/webapp/js/BaseFirebase.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function BaseFirebase() { 3 | var gSobject = gs.init('BaseFirebase'); 4 | gSobject.clazz = { name: 'firebase.BaseFirebase', simpleName: 'BaseFirebase'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.dataRef = null; 7 | gSobject.setProperty = function(name, value) { 8 | this.dataRef.child(name).set(gs.toJavascript(value)); 9 | } 10 | gSobject.initFirebase = function(url) { 11 | this.dataRef = new Firebase(url); 12 | } 13 | gSobject.doOnEvent = function(name, nameMethod) { 14 | gSobject.dataRef.child(name).on('value', function(snapshot) { 15 | gSobject[nameMethod](gs.toGroovy(snapshot.val())); 16 | }); 17 | } 18 | gSobject['BaseFirebase1'] = function(url) { 19 | gs.mc(gSobject,"initFirebase",[url]); 20 | gs.mc(gs.gp(this,"methods"),"each",[function(it) { 21 | if (gs.mc(gs.gp(it,"name"),"startsWith",["on"])) { 22 | var nameProperty = gs.mc(gs.mc(gs.gp(it,"name"),"substring",[2]),"toLowerCase",[]); 23 | return gs.mc(gSobject,"doOnEvent",[nameProperty, gs.gp(it,"name")]); 24 | }; 25 | }]); 26 | return this; 27 | } 28 | if (arguments.length==1) {gSobject.BaseFirebase1(arguments[0]); } 29 | 30 | return gSobject; 31 | }; 32 | -------------------------------------------------------------------------------- /src/main/webapp/js/Cell.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function Cell() { 3 | var gSobject = gs.init('Cell'); 4 | gSobject.clazz = { name: 'game.Cell', simpleName: 'Cell'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.value = null; 7 | gSobject['reset'] = function(it) { 8 | return gSobject.value = null; 9 | } 10 | gSobject['equals'] = function(other) { 11 | return ((gs.bool(gs.gp(gs.thisOrObject(this,gSobject),"value"))) && (gs.bool(gs.gp(other,"value")))) && (gs.equals(gSobject.value, gs.gp(other,"value"))); 12 | } 13 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 14 | 15 | return gSobject; 16 | }; 17 | -------------------------------------------------------------------------------- /src/main/webapp/js/Client.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function Client() { 3 | var gSobject = gs.init('Client'); 4 | gSobject.clazz = { name: 'chat.Client', simpleName: 'Client'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.login = null; 7 | gSobject.chat = null; 8 | gSobject.socket = null; 9 | gSobject.gQuery = null; 10 | gSobject.socketInit = function() { 11 | this.socket = io(window.location.hostname); 12 | } 13 | gSobject['sendMessageClick'] = function(it) { 14 | gs.mc(gSobject.socket,"emit",["msg", gs.map().add("msg",gSobject.chat)]); 15 | gs.mc(gs.mc(gSobject,"gQuery",["#messages"]),"append",[gs.execStatic(Templates,'applyTemplate', this,["message.gtpl", gs.map().add("name",gSobject.login).add("msg",gSobject.chat)])]); 16 | return gs.mc(this,"setChat",[""], gSobject); 17 | } 18 | gSobject['loginButtonClick'] = function(it) { 19 | return gs.mc(gSobject.socket,"emit",["login", gs.map().add("name",gSobject.login)]); 20 | } 21 | gSobject['chatMode'] = function(login) { 22 | gs.mc(gs.mc(gSobject,"gQuery",["#chatArea"]),"show",[]); 23 | gs.mc(gs.mc(gSobject,"gQuery",["#loginArea"]),"hide",[]); 24 | gs.mc(gs.mc(gSobject,"gQuery",["#chat"]),"focus",[]); 25 | return gs.mc(gs.mc(gSobject,"gQuery",["title"]),"text",["Chat - " + (login) + ""]); 26 | } 27 | gSobject.init = function() { return Client.init(); } 28 | gSobject['bindEvents'] = function(it) { 29 | gs.mc(gs.mc(gSobject,"gQuery",["#chat"]),"keypress",[function(event) { 30 | if (gs.equals(gs.gp(event,"which"), 13)) { 31 | return gs.mc(gSobject,"sendMessageClick",[]); 32 | }; 33 | }]); 34 | return gs.mc(gs.mc(gSobject,"gQuery",["#login"]),"keypress",[function(event) { 35 | if (gs.equals(gs.gp(event,"which"), 13)) { 36 | return gs.mc(gSobject,"loginButtonClick",[]); 37 | }; 38 | }]); 39 | } 40 | gSobject['Client1'] = function(jQueryImpl) { 41 | gs.sp(this,"gQuery",jQueryImpl); 42 | gs.mc(gSobject,"socketInit",[]); 43 | gs.mc(gSobject.socket,"on",["msg", function(data) { 44 | return gs.mc(gs.mc(gSobject,"gQuery",["#messages"]),"append",[gs.execStatic(Templates,'applyTemplate', this,["message.gtpl", gs.map().add("name",gs.gp(data,"from")).add("msg",gs.gp(data,"msg"))])]); 45 | }]); 46 | gs.mc(gSobject.socket,"on",["loginok", function(data) { 47 | if (gs.equals(gs.gp(data,"name"), gSobject.login)) { 48 | gs.mc(gSobject,"chatMode",[gSobject.login]); 49 | }; 50 | return gs.mc(gs.mc(gSobject,"gQuery",["#messages"]),"append",[gs.execStatic(Templates,'applyTemplate', this,["join.gtpl", gs.map().add("name",gs.gp(data,"name"))])]); 51 | }]); 52 | gs.mc(gSobject.socket,"on",["off", function(data) { 53 | return gs.mc(gs.mc(gSobject,"gQuery",["#messages"]),"append",[gs.execStatic(Templates,'applyTemplate', this,["left.gtpl", gs.map().add("name",gs.gp(data,"name"))])]); 54 | }]); 55 | gs.mc(gs.mc(gSobject,"gQuery",["#chatArea"]),"hide",[]); 56 | gs.mc(gs.mc(gSobject,"gQuery",["#loginArea"]),"show",[]); 57 | gs.mc(gSobject,"bindEvents",[]); 58 | return this; 59 | } 60 | if (arguments.length==1) {gSobject.Client1(arguments[0]); } 61 | 62 | return gSobject; 63 | }; 64 | Client.init = function(it) { 65 | var gQuery = GQueryImpl(); 66 | return gs.mc(gQuery,"onReady",[function(it) { 67 | var client = Client(gQuery); 68 | gs.mc(gQuery,"bindAllProperties",[client]); 69 | return gs.mc(gQuery,"attachMethodsToDomEvents",[client]); 70 | }]); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/webapp/js/CountriesPresenter.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function CountriesPresenter() { 3 | var gSobject = gs.init('CountriesPresenter'); 4 | gSobject.clazz = { name: 'countries.CountriesPresenter', simpleName: 'CountriesPresenter'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.countries = null; 7 | gSobject.customSigma = null; 8 | gSobject.gQuery = null; 9 | gSobject.purpleColor = "#b0b"; 10 | gSobject.greyColor = "#aaa"; 11 | gSobject['start'] = function(it) { 12 | gSobject.countries = gs.mc(gs.mc(gs.mc(gSobject,"loadCountries",[]),"findAll",[function(it) { 13 | return (gs.gp(it,"population") > 100000) && (gs.gp(it,"alpha3Code") != "COD"); 14 | }]),"unique",[function(it) { 15 | return gs.gp(it,"alpha3Code"); 16 | }]); 17 | gs.mc(gSobject.countries,"each",[function(country) { 18 | return gs.mc(gSobject.customSigma,"addNode",[gs.map().add("id",gs.gp(country,"alpha3Code")).add("label",gs.gp(country,"name")).add("x",gs.gp(country,"latlng")[1]).add("y",gs.gp(country,"latlng")[0]).add("color",gSobject.purpleColor)]); 19 | }]); 20 | gs.mc(gSobject.countries,"each",[function(country) { 21 | return gs.mc(gs.gp(country,"borders"),"each",[function(border) { 22 | if (gs.mc(gSobject.countries,"find",[function(it) { 23 | return gs.equals(gs.gp(it,"alpha3Code"), border); 24 | }]) != null) { 25 | return gs.mc(gSobject.customSigma,"addEdge",[gs.plus(gs.gp(country,"alpha3Code"), border), gs.gp(country,"alpha3Code"), border]); 26 | }; 27 | }], null, true); 28 | }]); 29 | gs.mc(gSobject,"updateNumberCountries",[gs.mc(gSobject.countries,"size",[])]); 30 | return gs.mc(gSobject.customSigma,"refresh",[]); 31 | } 32 | gSobject['onChangeCountry'] = function(searchString) { 33 | var listMatches = gs.list([]); 34 | if (gs.bool(searchString)) { 35 | gs.mc(gSobject.customSigma,"applyToNodes",[function(node) { 36 | if (gs.mc(gs.mc(gs.gp(node,"label"),"toUpperCase",[]),"contains",[gs.mc(searchString,"toUpperCase",[])])) { 37 | gs.sp(node,"color",gSobject.purpleColor); 38 | return gs.mc(listMatches,'leftShift', gs.list([node])); 39 | } else { 40 | return gs.sp(node,"color",gSobject.greyColor); 41 | }; 42 | }]); 43 | gs.mc(gSobject,"updateNumberCountries",[gs.mc(listMatches,"size",[]), (gs.mc(listMatches,"size",[]) < 5 ? gs.mc(gs.mc(listMatches,"collect",[function(it) { 44 | return gs.gp(it,"label"); 45 | }]),"join",[", "]) : "")]); 46 | } else { 47 | gs.mc(gSobject.customSigma,"applyToNodes",[function(node) { 48 | return gs.sp(node,"color",gSobject.purpleColor); 49 | }]); 50 | gs.mc(gSobject,"updateNumberCountries",[gs.mc(gSobject.countries,"size",[])]); 51 | }; 52 | if ((gs.bool(listMatches)) && (gs.equals(gs.mc(listMatches,"size",[]), 1))) { 53 | var node = gs.mc(listMatches,"first",[]); 54 | gs.mc(gSobject.customSigma,"moveCamaraToNode",[node]); 55 | } else { 56 | gs.mc(gSobject.customSigma,"moveCamaraTo",[0, 0, 1]); 57 | }; 58 | return gs.mc(gSobject.customSigma,"refresh",[]); 59 | } 60 | gSobject['updateNumberCountries'] = function(number, message) { 61 | if (message === undefined) message = ""; 62 | return gs.mc(gs.mc(gSobject,"gQuery",["#searchResult"]),"html",["" + (number) + " found. " + (message) + ""]); 63 | } 64 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 65 | 66 | return gSobject; 67 | }; 68 | -------------------------------------------------------------------------------- /src/main/webapp/js/CustomSigma.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function CustomSigma() { 3 | var gSobject = gs.init('CustomSigma'); 4 | gSobject.clazz = { name: 'countries.CustomSigma', simpleName: 'CustomSigma'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.s = null; 7 | gSobject.init = function(container) { 8 | this.s = new sigma(container); 9 | this.s.settings({ 10 | edgeColor: 'default', 11 | defaultEdgeColor: 'grey' 12 | }); 13 | } 14 | gSobject.refresh = function() { 15 | this.s.refresh(); 16 | } 17 | gSobject.addNode = function(data) { 18 | this.s.graph.addNode({ 19 | // Main attributes: 20 | id: data.id, 21 | label: data.label, 22 | // Display attributes: 23 | x: data.x * 10, 24 | y: data.y * (-10), 25 | size: 1, 26 | color: data.color 27 | }); 28 | } 29 | gSobject.addEdge = function(id, source, target) { 30 | this.s.graph.addEdge({ 31 | id: id, 32 | // Reference extremities: 33 | source: source, 34 | target: target 35 | }); 36 | } 37 | gSobject['moveCamaraTo'] = function(x, y, ratio) { 38 | return gs.mc(gs.gp(gSobject.s,"cameras")[0],"goTo",[gs.map().add("x",x).add("y",y).add("ratio",ratio)]); 39 | } 40 | gSobject.moveCamaraToNode = function(node) { 41 | this.s.cameras[0].goTo({x:node['read_cam0:x'],y:node['read_cam0:y'],ratio:0.300}) 42 | } 43 | gSobject['applyToNodes'] = function(closure) { 44 | return gs.mc(gs.mc(gs.gp(gSobject.s,"graph"),"nodes",[]),"forEach",[closure]); 45 | } 46 | gSobject['CustomSigma1'] = function(container) { 47 | gs.mc(gSobject,"init",[container]); 48 | return this; 49 | } 50 | if (arguments.length==1) {gSobject.CustomSigma1(arguments[0]); } 51 | 52 | return gSobject; 53 | }; 54 | -------------------------------------------------------------------------------- /src/main/webapp/js/Draw.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function Draw() { 3 | var gSobject = gs.init('Draw'); 4 | gSobject.clazz = { name: 'paint.Draw', simpleName: 'Draw'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.functions = Functions(); 7 | gSobject.r = gs.random(); 8 | gSobject.colors = gs.list([gs.map().add("r",232).add("g",51).add("b",1) , gs.map().add("r",248).add("g",179).add("b",10) , gs.map().add("r",247).add("g",239).add("b",189) , gs.map().add("r",29).add("g",16).add("b",8)]); 9 | Object.defineProperty(gSobject, 'PRECISSION', { get: function() { return Draw.PRECISSION; }, set: function(gSval) { Draw.PRECISSION = gSval; }, enumerable: true }); 10 | Object.defineProperty(gSobject, 'N_GRADES', { get: function() { return Draw.N_GRADES; }, set: function(gSval) { Draw.N_GRADES = gSval; }, enumerable: true }); 11 | gSobject.maxWidth = 500; 12 | gSobject.maxHeight = 500; 13 | gSobject.ctx = null; 14 | gSobject.ctxWidth = null; 15 | gSobject.ctxHeight = null; 16 | gSobject['random'] = function(it) { 17 | var points = gs.list([]); 18 | gs.mc(Draw.N_GRADES,"times",[function(it) { 19 | return gs.mc(points,'leftShift', gs.list([gs.map().add("x",gs.mc(gSobject.r,"nextInt",[gSobject.maxWidth])).add("y",gs.mc(gSobject.r,"nextInt",[gSobject.maxHeight]))])); 20 | }]); 21 | var movex = gs.mc(gSobject.r,"nextInt",[gSobject.ctxWidth]); 22 | var movey = gs.mc(gSobject.r,"nextInt",[gSobject.ctxHeight]); 23 | var finalPoints = gs.mc(points,"collect",[function(it) { 24 | return gs.map().add("x",gs.plus((gs.minus(gs.gp(it,"x"), (gs.div(gSobject.maxWidth, 2)))), movex)).add("y",gs.plus((gs.minus(gs.gp(it,"y"), (gs.div(gSobject.maxHeight, 2)))), movey)); 25 | }]); 26 | return gs.mc(gSobject,"drawBezier",[finalPoints]); 27 | } 28 | gSobject['drawBezier'] = function(points) { 29 | var xList = gs.mc(points,"collect",[function(it) { 30 | return gs.gp(it,"x"); 31 | }]); 32 | var yList = gs.mc(points,"collect",[function(it) { 33 | return gs.gp(it,"y"); 34 | }]); 35 | var color = gSobject.colors[gs.mc(gSobject.r,"nextInt",[4])]; 36 | var width = gs.plus(gs.mc(gSobject.r,"nextInt",[30]), 35); 37 | return gs.mc(gs.range(1, Draw.PRECISSION, true),"each",[function(it) { 38 | var posx = gs.mc(gSobject.functions,"nBezier",[gs.div(it, Draw.PRECISSION), xList]); 39 | var posy = gs.mc(gSobject.functions,"nBezier",[gs.div(it, Draw.PRECISSION), yList]); 40 | gs.mc(gSobject,"drawCircle",[posx, posy, color, gs.div(it, width)]); 41 | if (gs.mc(gSobject.r,"nextInt",[100]) > 97) { 42 | return gs.mc(gSobject,"drawCircle",[gs.plus(posx, 20), gs.plus(posy, 20), color, gs.div((gs.div(it, width)), 2)]); 43 | }; 44 | }]); 45 | } 46 | gSobject.initCanvas = function(name) { 47 | var canvas = document.getElementById(name); 48 | this.ctxWidth = canvas.width; 49 | this.ctxHeight = canvas.height; 50 | this.ctx = canvas.getContext('2d'); 51 | } 52 | gSobject.drawCircle = function(x, y, color, radius) { 53 | this.ctx.beginPath(); 54 | this.ctx.arc(x, y, radius, 0, 2 * Math.PI, false); 55 | this.ctx.fillStyle = "rgb("+color.r+", "+color.g+", "+ color.b +")"; 56 | this.ctx.fill(); 57 | } 58 | gSobject['Draw1'] = function(idCanvas) { 59 | gs.mc(gSobject,"initCanvas",[idCanvas]); 60 | return this; 61 | } 62 | if (arguments.length==1) {gSobject.Draw1(arguments[0]); } 63 | 64 | return gSobject; 65 | }; 66 | Draw.PRECISSION = 800; 67 | Draw.N_GRADES = 9; 68 | -------------------------------------------------------------------------------- /src/main/webapp/js/Functions.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function Functions() { 3 | var gSobject = gs.init('Functions'); 4 | gSobject.clazz = { name: 'paint.Functions', simpleName: 'Functions'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject['nBezier'] = function(t, points) { 7 | var length = gs.minus(gs.mc(points,"size",[]), 1); 8 | return gs.plus(gs.gp(gs.mc(points,"inject",[gs.map().add("index",0).add("sum",0), function(acc, value) { 9 | gs.sp(acc,"sum",gs.gp(acc,"sum") + (gs.multiply((gs.multiply((gs.multiply(gs.mc(gSobject,"coef",[length, gs.gp(acc,"index")]), (gs.minus(value, (points[0]))))), Math.pow(gs.minus(1, t), gs.minus(length, gs.gp(acc,"index"))))), Math.pow(t, gs.gp(acc,"index"))))); 10 | gs.plusPlus(acc,"index",true,false); 11 | return acc; 12 | }]),"sum"), (points[0])); 13 | } 14 | gSobject['coef'] = function(m, n) { 15 | if ((gs.equals(m, n)) || (gs.equals(n, 0))) { 16 | return 1; 17 | } else { 18 | return gs.div(gs.mc(gSobject,"fact",[m]), (gs.multiply(gs.mc(gSobject,"fact",[n]), gs.mc(gSobject,"fact",[gs.minus(m, n)])))); 19 | }; 20 | } 21 | gSobject['fact'] = function(n) { 22 | var result = null; 23 | var gSswitch0 = n; 24 | if (gs.equals(gSswitch0, 2)) { 25 | result = 2; 26 | ; 27 | } else if (gs.equals(gSswitch0, 3)) { 28 | result = 3; 29 | ; 30 | } else if (gs.equals(gSswitch0, 4)) { 31 | result = 6; 32 | ; 33 | } else if (gs.equals(gSswitch0, 5)) { 34 | result = 24; 35 | ; 36 | } else if (gs.equals(gSswitch0, 6)) { 37 | result = 120; 38 | ; 39 | } else if (gs.equals(gSswitch0, 7)) { 40 | result = 720; 41 | ; 42 | } else if (gs.equals(gSswitch0, 8)) { 43 | result = 5040; 44 | ; 45 | } else if (gs.equals(gSswitch0, 9)) { 46 | result = 40320; 47 | ; 48 | } else if (gs.equals(gSswitch0, 10)) { 49 | result = 362880; 50 | ; 51 | } else { 52 | result = 1; 53 | }; 54 | return result; 55 | } 56 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 57 | 58 | return gSobject; 59 | }; 60 | -------------------------------------------------------------------------------- /src/main/webapp/js/Game.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function Game() { 3 | var gSobject = gs.init('Game'); 4 | gSobject.clazz = { name: 'game.Game', simpleName: 'Game'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.size = 4; 7 | gSobject.total = gs.multiply(gSobject.size, gSobject.size); 8 | gSobject.goal = 2048; 9 | gSobject.initialNumbers = 2; 10 | gSobject.cells = null; 11 | gSobject.rows = null; 12 | gSobject.columns = null; 13 | gSobject['processLine'] = function(line) { 14 | gs.mc(gSobject,"compressLine",[line]); 15 | gs.mc(gSobject,"joinLine",[line]); 16 | return gs.mc(gSobject,"compressLine",[line]); 17 | } 18 | gSobject['isDone'] = function(it) { 19 | return gs.mc(gSobject.cells,"any",[function(it) { 20 | return gs.gp(it,"value") >= gSobject.goal; 21 | }]); 22 | } 23 | gSobject['isFull'] = function(it) { 24 | return gs.mc(gSobject.cells,"every",[function(it) { 25 | return gs.gp(it,"value"); 26 | }]); 27 | } 28 | gSobject['addRandomNumber'] = function(it) { 29 | var empties = gs.mc(gSobject.cells,"findAll",[function(it) { 30 | return !gs.gp(it,"value"); 31 | }]); 32 | return gs.sp((empties[gs.mc(gs.random(),"nextInt",[gs.mc(empties,"size",[])])]),"value",2); 33 | } 34 | gSobject['moveRight'] = function(it) { 35 | return gs.mc(gSobject.rows,"each",[function(it) { 36 | return gs.mc(gSobject,"processLine",[gs.mc(it,"reverse",[])]); 37 | }]); 38 | } 39 | gSobject['moveLeft'] = function(it) { 40 | return gs.mc(gSobject.rows,"each",[function(it) { 41 | return gs.mc(gSobject,"processLine",[it]); 42 | }]); 43 | } 44 | gSobject['moveUp'] = function(it) { 45 | return gs.mc(gSobject.columns,"each",[function(it) { 46 | return gs.mc(gSobject,"processLine",[it]); 47 | }]); 48 | } 49 | gSobject['moveDown'] = function(it) { 50 | return gs.mc(gSobject.columns,"each",[function(it) { 51 | return gs.mc(gSobject,"processLine",[gs.mc(it,"reverse",[])]); 52 | }]); 53 | } 54 | gSobject['joinLine'] = function(line) { 55 | return gs.mc(gs.minus(gSobject.size, 1),"times",[function(number) { 56 | if (gs.equals((line[number]), (line[(gs.plus(number, 1))]))) { 57 | gs.sp((line[number]),"value",(gs.multiply(gs.gp(line[number],"value"), 2))); 58 | return gs.mc(line[(gs.plus(number, 1))],"reset",[]); 59 | }; 60 | }]); 61 | } 62 | gSobject['compressLine'] = function(line) { 63 | var lineCompressed = gs.mc(line,"findAll",[function(it) { 64 | return gs.gp(it,"value"); 65 | }]); 66 | return gs.mc(line,"eachWithIndex",[function(cell, i) { 67 | if (i < gs.mc(lineCompressed,"size",[])) { 68 | return gs.sp(cell,"value",gs.gp(lineCompressed[i],"value")); 69 | } else { 70 | return gs.mc(cell,"reset",[]); 71 | }; 72 | }]); 73 | } 74 | gSobject['Game0'] = function(it) { 75 | gSobject.cells = gs.list([]); 76 | gSobject.rows = gs.list([]); 77 | gSobject.columns = gs.list([]); 78 | gs.mc(gSobject.total,"times",[function(it) { 79 | return gs.mc(gSobject.cells,'leftShift', gs.list([Cell()])); 80 | }]); 81 | gs.mc(gSobject.size,"times",[function(number) { 82 | var row = gs.list([]); 83 | var column = gs.list([]); 84 | gs.mc(gSobject.size,"times",[function(it) { 85 | gs.mc(row,'leftShift', gs.list([(gSobject.cells[(gs.plus((gs.multiply(number, gSobject.size)), it))])])); 86 | return gs.mc(column,'leftShift', gs.list([(gSobject.cells[(gs.plus((gs.multiply(it, gSobject.size)), number))])])); 87 | }]); 88 | (gSobject.rows[number]) = row; 89 | return (gSobject.columns[number]) = column; 90 | }]); 91 | gs.mc(gSobject.initialNumbers,"times",[function(it) { 92 | return gs.mc(gSobject,"addRandomNumber",[]); 93 | }]); 94 | return this; 95 | } 96 | if (arguments.length==0) {gSobject.Game0(); } 97 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 98 | 99 | return gSobject; 100 | }; 101 | -------------------------------------------------------------------------------- /src/main/webapp/js/GamePresenter.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function GamePresenter() { 3 | var gSobject = gs.init('GamePresenter'); 4 | gSobject.clazz = { name: 'game.GamePresenter', simpleName: 'GamePresenter'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.game = null; 7 | gSobject.allowMove = true; 8 | gSobject['init'] = function(it) { 9 | gSobject.game = Game(); 10 | gs.mc(gs.mc(this,"$",["#result"], gSobject),"html",[""]); 11 | return gs.mc(gSobject,"drawGame",[]); 12 | } 13 | gSobject['drawGame'] = function(it) { 14 | return gs.mc(gs.mc(this,"$",["#gameTable"], gSobject),"html",[gs.fs('htmlFromGame', this, gSobject)]); 15 | } 16 | gSobject['getHtmlFromGame'] = function(it) { 17 | return gs.execStatic(HtmlBuilder,'build', this,[function(it) { 18 | return gs.mc(this,"table",[gs.map().add("class","table"), function(it) { 19 | return gs.mc(gs.gp(gSobject.game,"rows"),"each",[function(row) { 20 | return gs.mc(this,"tr",[function(it) { 21 | return gs.mc(row,"each",[function(cell) { 22 | return gs.mc(this,"td",[gs.map().add("class","cell"), function(it) { 23 | return gs.mc(this,"p",["" + (gs.elvis(gs.bool(gs.gp(cell,"value")) , gs.gp(cell,"value") , "")) + ""], gSobject); 24 | }], gSobject); 25 | }]); 26 | }], gSobject); 27 | }]); 28 | }], gSobject); 29 | }]); 30 | } 31 | gSobject['move'] = function(adress) { 32 | if (gs.bool(gSobject.allowMove)) { 33 | gs.mc(gSobject.game,"move" + (gs.mc(adress,"capitalize",[])) + "",[]); 34 | if (gs.mc(gSobject.game,"isFull",[])) { 35 | gSobject.allowMove = false; 36 | gs.mc(gs.mc(this,"$",["#result"], gSobject),"html",["

        You have lost

        "]); 37 | } else { 38 | if (gs.mc(gSobject.game,"isDone",[])) { 39 | gSobject.allowMove = false; 40 | gs.mc(gs.mc(this,"$",["#result"], gSobject),"html",["

        Congratulations, you have finished!

        "]); 41 | } else { 42 | gs.mc(gSobject.game,"addRandomNumber",[]); 43 | }; 44 | }; 45 | return gs.mc(gSobject,"drawGame",[]); 46 | }; 47 | } 48 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 49 | 50 | return gSobject; 51 | }; 52 | -------------------------------------------------------------------------------- /src/main/webapp/js/GrooscriptFirebase.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function GrooscriptFirebase() { 3 | var gSobject = BaseFirebase(); 4 | gSobject.clazz = { name: 'firebase.GrooscriptFirebase', simpleName: 'GrooscriptFirebase'}; 5 | gSobject.clazz.superclass = { name: 'firebase.BaseFirebase', simpleName: 'BaseFirebase'}; 6 | gSobject['onMessage'] = function(message) { 7 | gs.println("Message received: " + (message) + ""); 8 | return gs.mc(gs.mc(this,"$",["body"], gSobject),"append",["

        Message received: " + (message) + "

        "]); 9 | } 10 | gSobject['GrooscriptFirebase0'] = function(it) { 11 | gSobject.BaseFirebase1("https://vivid-fire-5565.firebaseio.com/"); 12 | return this; 13 | } 14 | if (arguments.length==0) {gSobject.GrooscriptFirebase0(); } 15 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 16 | 17 | return gSobject; 18 | }; 19 | -------------------------------------------------------------------------------- /src/main/webapp/js/SnapSvg.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function SnapSvg() { 3 | var gSobject = gs.init('SnapSvg'); 4 | gSobject.clazz = { name: 'snap.SnapSvg', simpleName: 'SnapSvg'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.snap = null; 7 | gSobject['circle'] = function(attributes) { 8 | return gs.mc(gSobject,"createElement",["circle", attributes]); 9 | } 10 | gSobject['text'] = function(attributes) { 11 | return gs.mc(gSobject,"createElement",["text", attributes]); 12 | } 13 | gSobject['rect'] = function(attributes) { 14 | return gs.mc(gSobject,"createElement",["rect", attributes]); 15 | } 16 | gSobject.createSnap = function(selector) { 17 | return Snap(selector); 18 | } 19 | gSobject.createElement = function(name, attributes) { 20 | var element = Element(); 21 | var newSnap = this.snap.el(name, gs.toJavascript(attributes)); 22 | for (var ob in element) { 23 | newSnap[ob] = element[ob]; 24 | } 25 | return newSnap; 26 | } 27 | gSobject.repeat = function(time, closure) { 28 | window.setInterval(closure, time); 29 | } 30 | gSobject.snapSvg = function(x0,x1) { return SnapSvg.snapSvg(x0,x1); } 31 | gSobject['SnapSvg1'] = function(selector) { 32 | gSobject.snap = gs.mc(gSobject,"createSnap",[selector]); 33 | return this; 34 | } 35 | if (arguments.length==1) {gSobject.SnapSvg1(arguments[0]); } 36 | 37 | return gSobject; 38 | }; 39 | SnapSvg.snapSvg = function(selector, cl) { 40 | gs.sp(cl,"delegate",SnapSvg(selector)); 41 | return gs.execCall(cl, this, []); 42 | } 43 | 44 | function Element() { 45 | var gSobject = gs.init('Element'); 46 | gSobject.clazz = { name: 'snap.Element', simpleName: 'Element'}; 47 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 48 | gSobject.setVerticalScale = function(scale) { 49 | this.transform('scale(1,'+scale+')'); 50 | } 51 | gSobject.rotate = function(degrees, x, y) { 52 | this.transform('r'+degrees+','+x+','+y); 53 | return this; 54 | } 55 | gSobject.rotateAndScale = function(degrees, scale, x, y) { 56 | var t = new Snap.Matrix() 57 | .rotate(degrees, x, y) 58 | .scale(1, scale); 59 | this.transform(t); 60 | } 61 | gSobject.copy = function() { 62 | var element = Element(); 63 | var newSnap = this.clone(); 64 | for (var ob in element) { 65 | newSnap[ob] = element[ob]; 66 | } 67 | return newSnap; 68 | } 69 | gSobject.setProperty = function(name, value) { 70 | if (name == 'verticalScale') { 71 | this.setVerticalScale(value); 72 | } else { 73 | this.attr(gs.toJavascript(gs.map().add(name, value))); 74 | } 75 | } 76 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 77 | 78 | return gSobject; 79 | }; 80 | -------------------------------------------------------------------------------- /src/main/webapp/js/Stars.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function Stars() { 3 | var gSobject = gs.init('Stars'); 4 | gSobject.clazz = { name: 'raphael.Stars', simpleName: 'Stars'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | Object.defineProperty(gSobject, 'STARS_NUMBER', { get: function() { return Stars.STARS_NUMBER; }, set: function(gSval) { Stars.STARS_NUMBER = gSval; }, enumerable: true }); 7 | gSobject.context = null; 8 | gSobject.groovyImage = null; 9 | gSobject.grailsImage = null; 10 | gSobject.height = null; 11 | gSobject.width = null; 12 | gSobject.random = gs.random(); 13 | gSobject.stars = gs.list([]); 14 | gSobject['start'] = function(id) { 15 | gs.mc(gSobject,"initCanvas",[id]); 16 | gs.mc(Stars.STARS_NUMBER,"times",[function(it) { 17 | var size = gs.multiply((gs.plus((gs.div(gs.mc(gSobject.random,"nextInt",[10]), 10)), 0.5)), 3); 18 | return gs.mc(gSobject.stars,'leftShift', gs.list([gs.map().add("x",gs.mc(gSobject.random,"nextInt",[gSobject.width])).add("y",gs.mc(gSobject.random,"nextInt",[gSobject.height])).add("speed",gs.multiply(size, 3)).add("size",size)])); 19 | }]); 20 | return gs.mc(gSobject,"draw",[gSobject["initAndMove"]]); 21 | } 22 | gSobject['initAndMove'] = function(it) { 23 | gs.sp(gSobject.context,"fillStyle","#000000"); 24 | gs.mc(gSobject.context,"fillRect",[0, 0, gSobject.width, gSobject.height]); 25 | gs.sp(gSobject.context,"fillStyle","#FFFFFF"); 26 | gs.mc(gSobject.stars,"each",[function(star) { 27 | var newX = gs.plus(gs.gp(star,"x"), gs.gp(star,"speed")); 28 | if (newX > gSobject.width) { 29 | newX = 0; 30 | }; 31 | gs.sp(star,"x",newX); 32 | return gs.mc(gSobject.context,"fillRect",[gs.gp(star,"x"), gs.gp(star,"y"), gs.gp(star,"size"), gs.gp(star,"size")]); 33 | }]); 34 | gs.mc(gSobject.context,"drawImage",[gSobject.groovyImage, gs.minus(gSobject.width, 210), gs.minus(gSobject.height, 110)]); 35 | gs.mc(gSobject.context,"drawImage",[gSobject.grailsImage, 10, gs.minus(gSobject.height, 110), 100, 100]); 36 | gs.sp(gSobject.context,"font","48px serif"); 37 | gs.mc(gSobject.context,"fillText",["Keep on groovy'ing!", gs.minus((gs.div(gSobject.width, 2)), 190), gs.minus(gSobject.height, 50)]); 38 | gs.sp(gSobject.context,"font","24px serif"); 39 | return gs.mc(gSobject.context,"fillText",["While groovy and grails crew looking for a new home...", 50, 60]); 40 | } 41 | gSobject.draw = function(closure) { 42 | setInterval(closure, 1000/60); 43 | } 44 | gSobject.initCanvas = function(id) { 45 | var canvas = document.getElementById(id); 46 | canvas.width = document.body.clientWidth; 47 | canvas.height = document.body.clientHeight; 48 | gSobject.height = canvas.height; 49 | gSobject.width = canvas.width; 50 | gSobject.context = canvas.getContext("2d"); 51 | 52 | gSobject.groovyImage = document.getElementById("groovyImage"); 53 | gSobject.grailsImage = document.getElementById("grailsImage"); 54 | } 55 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 56 | 57 | return gSobject; 58 | }; 59 | Stars.STARS_NUMBER = 1500; 60 | -------------------------------------------------------------------------------- /src/main/webapp/js/Three.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function Three() { 3 | var gSobject = gs.init('Three'); 4 | gSobject.clazz = { name: 'three.Three', simpleName: 'Three'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.scene = null; 7 | gSobject.camera = null; 8 | gSobject.items = gs.list([]); 9 | gSobject.renderer = null; 10 | gSobject.actions = null; 11 | gSobject.material = null; 12 | gSobject.grooscriptMaterial = null; 13 | gSobject.scene = function(x0) { return Three.scene(x0); } 14 | gSobject['animate'] = function(closure) { 15 | gSobject.actions = gs.elvis(gs.bool(gSobject.actions) , gSobject.actions , closure); 16 | gs.mc(gSobject,"animationFrame",[gSobject["animate"]]); 17 | gs.mc(gSobject,"actions",[gSobject.items]); 18 | return gs.mc(gSobject.renderer,"render",[gSobject.scene, gSobject.camera]); 19 | } 20 | gSobject['methodMissing'] = function(name, args) { 21 | var mesh = gs.mc(gSobject,"newMesh",gs.list([gs.mc(name,"capitalize",[]), new gs.spread(args)])); 22 | gs.sp((mesh = gs.metaClass(mesh)),"rotateLeft",gs.mc(function(ob) { 23 | return gs.sp(gs.gp(ob,"rotation"),"y",gs.gp(gs.gp(ob,"rotation"),"y") - 0.02); 24 | },"curry",[mesh])); 25 | gs.sp((mesh = gs.metaClass(mesh)),"moveTo",gs.mc(function(ob, x, y, z) { 26 | return gs.mc(gs.gp(ob,"position"),"set",[x, y, z]); 27 | },"curry",[mesh])); 28 | gs.mc(gSobject.scene,"add",[mesh]); 29 | gs.mc(gSobject.items,'leftShift', gs.list([mesh])); 30 | return mesh; 31 | } 32 | gSobject.getDefaultScene = function() { 33 | var scene = new THREE.Scene(); 34 | //Default material 35 | var map = THREE.ImageUtils.loadTexture('img/texture.jpg'); 36 | map.wrapS = map.wrapT = THREE.RepeatWrapping; 37 | map.anisotropy = 16; 38 | gSobject.material = new THREE.MeshLambertMaterial( { ambient: 0xbbbbbb, map: map, side: THREE.DoubleSide } ); 39 | var grooscriptMap = THREE.ImageUtils.loadTexture('img/logo.png'); 40 | gSobject.grooscriptMaterial = new THREE.MeshLambertMaterial( { ambient: 0xbbbbbb, map: grooscriptMap, side: THREE.DoubleSide } ); 41 | //Light 42 | scene.add( new THREE.AmbientLight(0xF0F0F0)); 43 | return scene; 44 | } 45 | gSobject.getDefaultCamera = function() { 46 | var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 ); 47 | camera.position.z = 1000; 48 | return camera; 49 | } 50 | gSobject.getDefaultRenderer = function() { 51 | var renderer = new THREE.WebGLRenderer(); 52 | renderer.setSize( window.innerWidth, window.innerHeight ); 53 | document.body.appendChild( renderer.domElement ); 54 | return renderer; 55 | } 56 | gSobject.newMesh = function(name, args) { 57 | if (arguments.length == 1 && arguments[0] instanceof Array) { args=gs.list(arguments[0]); } else 58 | if (arguments.length == 2) { args=gs.list([arguments[2 - 1]]); } else 59 | if (arguments.length < 2) { args=gs.list([]); } else 60 | if (arguments.length > 2) { 61 | args=gs.list([args]); 62 | for (gScount=2;gScount < arguments.length; gScount++) { 63 | args.add(arguments[gScount]); 64 | } 65 | } 66 | var geo = gSobject.construct(THREE[name + 'Geometry'], args); 67 | var object = new THREE.Mesh(geo, gSobject.material); 68 | object.name = name; 69 | object.position.set(0, 0, 0); 70 | return object; 71 | } 72 | gSobject.animationFrame = function(func) { 73 | requestAnimationFrame(func); 74 | } 75 | gSobject.construct = function(constructor, args) { 76 | function F() { 77 | return constructor.apply(this, args); 78 | } 79 | F.prototype = constructor.prototype; 80 | return new F(); 81 | } 82 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 83 | 84 | return gSobject; 85 | }; 86 | Three.scene = function(closure) { 87 | var three = Three(); 88 | gs.sp(closure,"delegate",three); 89 | gs.sp(three,"scene",gs.gp(three,"defaultScene")); 90 | gs.sp(three,"camera",gs.gp(three,"defaultCamera")); 91 | gs.execCall(closure, this, []); 92 | gs.sp(three,"renderer",gs.gp(three,"defaultRenderer")); 93 | return three; 94 | } 95 | -------------------------------------------------------------------------------- /src/main/webapp/js/autocomplete.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function ReactiveResolver() { 3 | var gSobject = gs.init('ReactiveResolver'); 4 | gSobject.clazz = { name: 'rxjs.ReactiveResolver', simpleName: 'ReactiveResolver'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.reactive = function(x0) { return ReactiveResolver.reactive(x0); } 7 | gSobject.fromEvent = function(domElement, eventName) { 8 | return Rx.Observable.fromEvent(domElement, eventName) 9 | } 10 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 11 | 12 | return gSobject; 13 | }; 14 | ReactiveResolver.reactive = function(cl) { 15 | var resolver = ReactiveResolver(); 16 | gs.sp(cl,"delegate",resolver); 17 | return gs.execCall(cl, this, []); 18 | } 19 | 20 | 21 | ReactiveResolver.reactive(function(it) { 22 | var searchWikipedia = function(term) { 23 | return gs.mc(gs.mc(gs.fs('jQuery', this),"ajax",[gs.map().add("url","http://en.wikipedia.org/w/api.php").add("dataType","jsonp").add("data",gs.toJavascript(gs.map().add("action","opensearch").add("format","json").add("search",gs.mc(gs.fs('window', this),"encodeURI",[term]))))]),"promise",[]); 24 | }; 25 | var results = gs.mc(this,"$",["#results"]); 26 | var textInput = gs.mc(this,"$",["#textInput"]); 27 | var main = function(it) { 28 | var keyUp = gs.mc(gs.mc(gs.mc(gs.mc(gs.mc(this,"fromEvent",[textInput, "keyup"]),"map",[function(it) { 29 | return gs.gp(gs.gp(it,"target"),"value"); 30 | }]),"filter",[function(text) { 31 | return gs.mc(text,"size",[]) > 2; 32 | }]),"debounce",[750]),"distinctUntilChanged",[]); 33 | var searcher = gs.mc(keyUp,"flatMapLatest",[searchWikipedia]); 34 | return gs.mc(searcher,"subscribe",[function(data) { 35 | gs.mc(results,"empty",[]); 36 | return gs.mc(data[1],"each",[function(it) { 37 | return gs.mc(results,"append",["
      • " + (it) + "
      • "]); 38 | }]); 39 | }, function(error) { 40 | gs.mc(results,"empty",[]); 41 | return gs.mc(results,"append",["
      • Error: " + (error) + "
      • "]); 42 | }]); 43 | }; 44 | return gs.execCall(main, this, []); 45 | }); 46 | -------------------------------------------------------------------------------- /src/main/webapp/js/autocompleteTwo.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function ReactiveScript() { 3 | var gSobject = gs.init('ReactiveScript'); 4 | gSobject.clazz = { name: 'rxjs.ReactiveScript', simpleName: 'ReactiveScript'}; 5 | gSobject.clazz.superclass = { name: 'groovy.lang.Script', simpleName: 'Script'}; 6 | gSobject.selectors = gs.map(); 7 | gSobject.searchWikipedia = function(term) { 8 | return gs.mc(gs.mc(gs.fs('jQuery', this, gSobject),"ajax",[gs.map().add("url","http://en.wikipedia.org/w/api.php").add("dataType","jsonp").add("data",gs.toJavascript(gs.map().add("action","opensearch").add("format","json").add("search",gs.mc(gs.fs('window', this, gSobject),"encodeURI",[term]))))]),"promise",[]); 9 | }; 10 | gSobject.observeEvent = function(domElement, eventName) { 11 | return Rx.Observable.fromEvent(domElement, eventName) 12 | } 13 | gSobject['propertyMissing'] = function(name) { 14 | if (!gs.bool(gSobject.selectors[name])) { 15 | (gSobject.selectors[name]) = gs.mc(this,"$",["#" + (name) + ""], gSobject); 16 | }; 17 | return gSobject.selectors[name]; 18 | } 19 | gSobject['run'] = function(it) { 20 | } 21 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 22 | 23 | return gSobject; 24 | }; 25 | 26 | 27 | var baseScript = ReactiveScript(); 28 | baseScript.withz(function() {; 29 | var keyUp = gs.mc(gs.mc(gs.mc(gs.mc(gs.mc(this,"observeEvent",[gs.fs('textInput', this), "keyup"]),"map",[function(it) { 30 | return gs.gp(gs.gp(it,"target"),"value"); 31 | }]),"filter",[function(text) { 32 | return gs.mc(text,"size",[]) > 2; 33 | }]),"debounce",[750]),"distinctUntilChanged",[]); 34 | var searcher = gs.mc(keyUp,"flatMapLatest",[gs.fs('searchWikipedia', this)]); 35 | gs.mc(searcher,"subscribe",[gs.mc(function(terms, resultsDom) { 36 | gs.mc(resultsDom,"empty",[]); 37 | return gs.mc(terms[1],"each",[function(it) { 38 | return gs.mc(resultsDom,"append",["
      • " + (it) + "
      • "]); 39 | }]); 40 | },"rcurry",[gs.fs('results', this)]), gs.mc(function(errorMessage, resultsDom) { 41 | gs.mc(resultsDom,"empty",[]); 42 | return gs.mc(resultsDom,"append",["
      • Error: " + (errorMessage) + "
      • "]); 43 | },"rcurry",[gs.fs('results', this)])]); 44 | }); 45 | -------------------------------------------------------------------------------- /src/main/webapp/js/common.js: -------------------------------------------------------------------------------- 1 | requirejs.config({ 2 | baseUrl: 'js', 3 | paths: { 4 | jquery: 'jquery.min' 5 | } 6 | }); 7 | -------------------------------------------------------------------------------- /src/main/webapp/js/firebaseAction.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | var firebase = GrooscriptFirebase(); 3 | var message = gs.map().add("list",gs.list([1 , 2 , 3])).add("number",5).add("name","grooscript"); 4 | gs.mc(gs.mc(this,"$",["body"]),"append",["

        Send message: " + (message) + "

        "]); 5 | gs.sp(firebase,"message",message); 6 | gs.mc(gs.mc(this,"$",["body"]),"append",["

        Done synchronous!

        "]); 7 | -------------------------------------------------------------------------------- /src/main/webapp/js/gstemplates.js: -------------------------------------------------------------------------------- 1 | function Templates() { 2 | var gSobject = gs.init('Templates'); 3 | gSobject.clazz = { name: 'org.grooscript.gradle.template.Templates', simpleName: 'Templates'}; 4 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 5 | Object.defineProperty(gSobject, 'templates', { get: function() { return Templates.templates; }, set: function(gSval) { Templates.templates = gSval; }, enumerable: true }); 6 | gSobject.applyTemplate = function(x0,x1) { return Templates.applyTemplate(x0,x1); } 7 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 8 | 9 | return gSobject; 10 | }; 11 | Templates.applyTemplate = function(name, model) { 12 | if (model === undefined) model = gs.map(); 13 | var cl = Templates.templates[name]; 14 | if (!gs.bool(cl)) { 15 | return gs.plus((gs.plus("

        Not found template: ", name)), "

        "); 16 | } else { 17 | gs.sp(cl,"delegate",model); 18 | return gs.execCall(cl, this, [model]); 19 | }; 20 | } 21 | Templates.templates = gs.map().add("join.gtpl",function(model) { 22 | if (model === undefined) model = gs.map(); 23 | return gs.mc(HtmlBuilder,"build",[function(it) { 24 | return gs.mc(Templates,"li",[function(it) { 25 | if (gs.equals(gs.fs('name', this), "Groovy")) { 26 | return (3).times(function(it) { 27 | return gs.mc(Templates,"img",[gs.map().add("src","img/groovy.png").add("height",20)]); 28 | }); 29 | } else { 30 | gs.mc(Templates,"b",["" + (gs.gp(model,"name")) + " "]); 31 | return gs.mc(Templates,"yield",["joined the chat!"]); 32 | }; 33 | }]); 34 | }]); 35 | }).add("left.gtpl",function(model) { 36 | if (model === undefined) model = gs.map(); 37 | return gs.mc(HtmlBuilder,"build",[function(it) { 38 | return gs.mc(Templates,"li",[function(it) { 39 | if (gs.mc(gs.mc(gs.gp(model,"name"),"toLowerCase",[]),"contains",["danveloper"])) { 40 | return gs.mc(Templates,"b",["#unfollowdanveloper"]); 41 | } else { 42 | gs.mc(Templates,"b",["" + (gs.gp(model,"name")) + " "]); 43 | return gs.mc(Templates,"yield",["left the chat."]); 44 | }; 45 | }]); 46 | }]); 47 | }).add("message.gtpl",function(model) { 48 | if (model === undefined) model = gs.map(); 49 | return gs.mc(HtmlBuilder,"build",[function(it) { 50 | var pirateMessages = gs.list(["YARRRRR!" , "YO-HO!" , "Ahoy Boys!" , "Surrrrrender the booty!"]); 51 | return gs.mc(Templates,"li",[function(it) { 52 | gs.mc(Templates,"b",["" + (gs.gp(model,"name")) + ": "]); 53 | if (gs.mc(gs.mc(gs.gp(model,"name"),"toLowerCase",[]),"contains",["pirate"])) { 54 | var randomNumber = gs.mc(gs.random(),"nextInt",[gs.mc(pirateMessages,"size",[])]); 55 | return gs.mc(Templates,"yield",["" + (gs.gp(model,"msg")) + " " + (pirateMessages[randomNumber]) + ""]); 56 | } else { 57 | return gs.mc(Templates,"yield",[gs.gp(model,"msg")]); 58 | }; 59 | }]); 60 | }]); 61 | }).add("index.gtpl",function(model) { 62 | if (model === undefined) model = gs.map(); 63 | return gs.mc(HtmlBuilder,"build",[function(it) { 64 | gs.mc(Templates,"yieldUnescaped",[""]); 65 | return gs.mc(Templates,"html",[function(it) { 66 | gs.mc(Templates,"head",[function(it) { 67 | gs.mc(Templates,"title",["Chat"]); 68 | gs.mc(gs.list(["js/jquery.min.js" , "js/grooscript.min.js" , "js/grooscript-tools.js" , "js/Client.js" , "js/gstemplates.js" , "https://cdn.socket.io/socket.io-1.2.0.js"]),"each",[function(it) { 69 | return gs.mc(Templates,"script",[gs.map().add("type","text/javascript").add("src",it), function(it) { 70 | }]); 71 | }]); 72 | return gs.mc(Templates,"link",[gs.map().add("rel","stylesheet").add("type","text/css").add("href","css/chat.css")]); 73 | }]); 74 | return gs.mc(Templates,"body",[function(it) { 75 | gs.mc(Templates,"header",[function(it) { 76 | gs.mc(Templates,"h2",[function(it) { 77 | gs.mc(Templates,"a",[gs.map().add("href","http://grooscript.org"), function(it) { 78 | return gs.mc(Templates,"yield",["grooscript"]); 79 | }]); 80 | return gs.mc(Templates,"yield",[" chat demo"]); 81 | }]); 82 | return gs.mc(Templates,"h4",[function(it) { 83 | return gs.mc(Templates,"a",[gs.map().add("href","https://github.com/chiquitinxx/grooscript-demos"), function(it) { 84 | return gs.mc(Templates,"yield",["GitHub source demos"]); 85 | }]); 86 | }]); 87 | }]); 88 | gs.mc(Templates,"section",[function(it) { 89 | gs.mc(Templates,"div",[gs.map().add("id","loginArea"), function(it) { 90 | return gs.mc(Templates,"input",[gs.map().add("id","login").add("autocomplete","off").add("autofocus","true"), function(it) { 91 | return gs.mc(Templates,"button",[gs.map().add("id","loginButton"), function(it) { 92 | return gs.mc(Templates,"yield",["Login"]); 93 | }]); 94 | }]); 95 | }]); 96 | return gs.mc(Templates,"div",[gs.map().add("id","chatArea"), function(it) { 97 | gs.mc(Templates,"ul",[gs.map().add("id","messages")]); 98 | return gs.mc(Templates,"div",[gs.map().add("id","message"), function(it) { 99 | return gs.mc(Templates,"input",[gs.map().add("id","chat").add("autocomplete","off"), function(it) { 100 | return gs.mc(Templates,"button",[gs.map().add("id","sendMessage"), function(it) { 101 | return gs.mc(Templates,"yield",["Send"]); 102 | }]); 103 | }]); 104 | }]); 105 | }]); 106 | }]); 107 | return gs.mc(Templates,"script",[function(it) { 108 | return gs.mc(Templates,"yield",["Client.init();"]); 109 | }]); 110 | }]); 111 | }]); 112 | }]); 113 | }); 114 | -------------------------------------------------------------------------------- /src/main/webapp/js/jqueryrest/JQueryRestApi.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | JQueryRestApi = function() {}; 3 | JQueryRestApi.gSaT = function(target) { 4 | target.add = function(x0, x1, x2) { return JQueryRestApi.add(target, x0, x1, x2); }; 5 | target.one = function(x0, x1, x2, x3) { return JQueryRestApi.one(target, x0, x1, x2, x3); }; 6 | target.all = function(x0, x1, x2) { return JQueryRestApi.all(target, x0, x1, x2); }; 7 | target.ajaxCall = function(x0, x1, x2, x3, x4) { return JQueryRestApi.ajaxCall(target, x0, x1, x2, x3, x4); }; 8 | }; 9 | JQueryRestApi.$init$ = function($self) { 10 | } 11 | function JQueryRestApi$static$init$($static$self){ 12 | 13 | }; 14 | JQueryRestApi.add = function($self, onSuccess, onError) { 15 | return gs.mc($self,"ajaxCall",["POST", "" + (gs.gp($self,'url')) + "/" + (gs.gp($self,'resource')) + "", onSuccess, onError]); 16 | } 17 | JQueryRestApi.one = function($self, id, onSuccess, onError) { 18 | return gs.mc($self,"ajaxCall",["GET", "" + (gs.gp($self,'url')) + "/" + (gs.gp($self,'resource')) + "/" + (id) + "", onSuccess, onError]); 19 | } 20 | JQueryRestApi.all = function($self, onSuccess, onError) { 21 | return gs.mc($self,"ajaxCall",["GET", "" + (gs.gp($self,'url')) + "/" + (gs.gp($self,'resource')) + "", onSuccess, onError]); 22 | } 23 | JQueryRestApi.ajaxCall = function($self, type, url, onSuccess, onError) { 24 | jQuery.ajax({ 25 | type: type, 26 | url: url, 27 | data: (type == 'POST' ? JSON.stringify(gs.toJavascript($self)) : null), 28 | contentType: "application/json; charset=utf-8", 29 | dataType: "json", 30 | success: function (data, status, jqXHR) { 31 | onSuccess(data); 32 | }, 33 | error: function (jqXHR, status) { 34 | onError(jqXHR, status); 35 | } 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/webapp/js/jqueryrest/jQueryRest.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function Author() { 3 | var gSobject = gs.inherit(gs.baseClass,'Author'); 4 | gSobject.clazz = { name: 'Author', simpleName: 'Author'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.clazz.interfaces = [{ name: 'rest.JQueryRestApi', simpleName: 'JQueryRestApi'}]; 7 | gSobject.add = function(x1,x2) { return JQueryRestApi.add(gSobject,x1,x2); } 8 | if (JQueryRestApi['setProperty']) { 9 | gSobject.setProperty = function(x1) { return JQueryRestApi.setProperty(gSobject,x1); } 10 | } 11 | if (JQueryRestApi['getProperty']) { 12 | gSobject.getProperty = function() { return JQueryRestApi.getProperty(gSobject); } 13 | } 14 | gSobject.getResource = function() { return Author.resource }; 15 | gSobject.all = function(x1,x2) { return JQueryRestApi.all(gSobject,x1,x2); } 16 | gSobject.setUrl = function(x0) { Author.url = x0 }; 17 | gSobject.getUrl = function() { return Author.url }; 18 | gSobject.one = function(x1,x2,x3) { return JQueryRestApi.one(gSobject,x1,x2,x3); } 19 | gSobject.setResource = function(x0) { Author.resource = x0 }; 20 | JQueryRestApi.$init$(gSobject); 21 | gSobject.ajaxCall = function(x1,x2,x3,x4) { return JQueryRestApi.ajaxCall(gSobject,x1,x2,x3,x4); } 22 | gSobject.id = null; 23 | gSobject.name = null; 24 | gSobject.city = null; 25 | gSobject.image = null; 26 | gSobject.age = null; 27 | gSobject['toString'] = function(it) { 28 | return "id: " + (gSobject.id) + " name: " + (gSobject.name) + ""; 29 | } 30 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 31 | 32 | return gSobject; 33 | }; 34 | JQueryRestApi$static$init$(Author); 35 | var onError = function(jqXHR, status) { 36 | return gs.println("Error jqXHR: " + (jqXHR) + " status: " + (status) + ""); 37 | }; 38 | gs.sp(Author,"url","http://localhost:3000"); 39 | gs.sp(Author,"resource","authors"); 40 | var api = Author(); 41 | gs.mc(api,"one",[1, function(data) { 42 | var author = Author(data); 43 | return gs.println("Success one: " + (author) + ""); 44 | }, onError]); 45 | gs.mc(api,"all",[function(authors) { 46 | gs.println("Success all: " + (gs.mc(authors,"size",[])) + ""); 47 | return gs.mc(gs.mc(authors,"findAll",[function(it) { 48 | return gs.gp(it,"image"); 49 | }]),"each",[function(it) { 50 | return gs.mc(gs.mc(this,"$",["body"]),"append",[""]); 51 | }]); 52 | }, onError]); 53 | var newAuthor = Author(gs.map().add("name","Jorge Franco").add("city","Madrid / Sevilla").add("image","img/logo.png")); 54 | gs.mc(newAuthor,"add",[function(data) { 55 | gs.println("Success add: " + (gs.gp(data,"id")) + ""); 56 | return gs.mc(api,"all",[function(authors) { 57 | return gs.println("Success after insert " + (gs.gp(data,"name")) + ": " + (gs.mc(authors,"size",[])) + ""); 58 | }, onError]); 59 | }, onError]); 60 | -------------------------------------------------------------------------------- /src/main/webapp/js/map/GoogleMap.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function GoogleMap() { 3 | var gSobject = gs.init('GoogleMap'); 4 | gSobject.clazz = { name: 'maps.GoogleMap', simpleName: 'GoogleMap'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.options = gs.map().add("zoom",8); 7 | gSobject._style = null; 8 | gSobject._marks = gs.list([]); 9 | gSobject.init = function(x0) { return GoogleMap.init(x0); } 10 | gSobject.ltlg = function(latitude, longitude) { 11 | return new google.maps.LatLng(latitude, longitude); 12 | } 13 | gSobject['putStyle'] = function(styles) { 14 | return gSobject._style = styles; 15 | } 16 | gSobject['mark'] = function(options) { 17 | return gs.mc(gSobject._marks,'leftShift', gs.list([options])); 18 | } 19 | gSobject.start = function(selectorId) { 20 | var style = this._style; 21 | var options = this.options; 22 | var marks = this._marks; 23 | google.maps.event.addDomListener(window, 'load', function() { 24 | var MY_MAPTYPE_ID = 'custom_style'; 25 | if (style) { 26 | options['mapTypeControlOptions'] = { 27 | mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID] 28 | } 29 | options['mapTypeId'] = MY_MAPTYPE_ID; 30 | } 31 | var map = new google.maps.Map(document.getElementById(selectorId), gs.toJavascript(options)); 32 | if (style) { 33 | var styledMapOptions = {name: 'Custom Style'}; 34 | var customMapType = new google.maps.StyledMapType(gs.toJavascript(style), styledMapOptions); 35 | map.mapTypes.set(MY_MAPTYPE_ID, customMapType); 36 | } 37 | marks.each(function(mark) { 38 | mark.map = map; 39 | var googleMark = new google.maps.Marker(gs.toJavascript(mark)); 40 | if (mark.infoWindow) { 41 | var infowindow = new google.maps.InfoWindow({content: mark.infoWindow}); 42 | google.maps.event.addListener(googleMark, 'click', function() { 43 | infowindow.open(map, googleMark); 44 | }); 45 | } 46 | }); 47 | }); 48 | } 49 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 50 | 51 | return gSobject; 52 | }; 53 | GoogleMap.init = function(actions) { 54 | var map = GoogleMap(); 55 | gs.sp(actions,"delegate",map); 56 | gs.execCall(actions, this, []); 57 | return map; 58 | } 59 | -------------------------------------------------------------------------------- /src/main/webapp/js/map/startMap.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | gs.mc(gs.execStatic(GoogleMap,'init', this,[function(it) { 3 | gs.sp(gs.fs('options', this),"zoom",6); 4 | gs.sp(gs.fs('options', this),"center",gs.mc(this,"ltlg",[40.4379543, -3.6795367])); 5 | gs.mc(this,"putStyle",[gs.list([gs.map().add("stylers",gs.list([gs.map().add("visibility","simplified") , gs.map().add("gamma",0.5) , gs.map().add("weight",0.5)])) , gs.map().add("featureType","water").add("stylers",gs.list([gs.map().add("color","#b77fd7")]))])]); 6 | gs.mc(this,"mark",[gs.map().add("position",gs.mc(this,"ltlg",[40.4379543, -3.6795367])).add("title","grooscript").add("icon","img/gs.png")]); 7 | return gs.mc(this,"mark",[gs.map().add("position",gs.mc(this,"ltlg",[41.39479, 2.1487679])).add("title","Champions!").add("icon","img/barcelona.png").add("infoWindow","")]); 8 | }]),"start",["map-canvas"]); 9 | -------------------------------------------------------------------------------- /src/main/webapp/js/react.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function TodoApp() { 3 | var gSobject = gs.init('TodoApp'); 4 | gSobject.clazz = { name: 'react.TodoApp', simpleName: 'TodoApp'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.todos = null; 7 | gSobject.actualTodo = null; 8 | gSobject.gQuery = GQueryImpl(); 9 | gSobject.selector = null; 10 | gSobject['init'] = function(it) { 11 | gSobject.todos = gs.list([]); 12 | return gSobject.actualTodo = ""; 13 | } 14 | gSobject['actualTodoChange'] = function(actualTodoValue) { 15 | return gs.mc(gSobject,"setActualTodo",[actualTodoValue]); 16 | } 17 | gSobject['addTodosSubmit'] = function(it) { 18 | if (gs.bool(gSobject.actualTodo)) { 19 | gs.mc(gSobject.todos,'leftShift', gs.list([gSobject.actualTodo])); 20 | return gs.mc(gSobject,"setActualTodo",[""]); 21 | }; 22 | } 23 | gSobject['render'] = function(it) { 24 | return gs.mc(gs.execCall(gs.gp(gs.thisOrObject(this,gSobject),"gQuery"), this, [gSobject.selector]),"html",[gs.execStatic(HtmlBuilder,'build', this,[function(it) { 25 | return gs.mc(this,"form",[gs.map().add("id","addTodos"), function(it) { 26 | gs.mc(this,"h3",["TODO"], gSobject); 27 | return gs.mc(this,"ul",[function(it) { 28 | gs.mc(gSobject.todos,"each",[function(it) { 29 | return gs.mc(this,"li",[it], gSobject); 30 | }]); 31 | return gs.mc(this,"li",[function(it) { 32 | gs.mc(this,"input",[gs.map().add("type","text").add("id","actualTodo").add("value",gSobject.actualTodo)], gSobject); 33 | return gs.mc(this,"button",[function(it) { 34 | return gs.mc(this,"yield",["Add #" + (gs.plus(gs.mc(gSobject.todos,"size",[]), 1)) + ""], gSobject); 35 | }], gSobject); 36 | }], gSobject); 37 | }], gSobject); 38 | }], gSobject); 39 | }])]); 40 | } 41 | gSobject['draw'] = function(it) { 42 | gs.mc(gSobject,"render",[]); 43 | return gs.mc(gSobject.gQuery,"attachMethodsToDomEvents",[this]); 44 | } 45 | gSobject['start'] = function(selector) { 46 | gs.sp(this,"selector",selector); 47 | gs.mc(gSobject,"init",[]); 48 | return gs.mc(gSobject,"draw",[]); 49 | } 50 | gSobject['setActualTodo'] = function(actualTodo) { 51 | this["actualTodo"] = actualTodo; 52 | gs.mc(gSobject,"draw",[]); 53 | return gs.mc(gSobject.gQuery,"focusEnd",["#actualTodo"]); 54 | } 55 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 56 | 57 | return gSobject; 58 | }; 59 | var renderComponent = function(component, selector) { 60 | var gQuery = GQueryImpl(); 61 | return gs.mc(gQuery,"onReady",[function(it) { 62 | return gs.mc(component,"start",[selector]); 63 | }]); 64 | }; 65 | gs.execCall(renderComponent, this, [TodoApp(), "#todos"]); 66 | -------------------------------------------------------------------------------- /src/main/webapp/js/requireGame.js: -------------------------------------------------------------------------------- 1 | require(['./common'], function () { 2 | requirejs(['jquery', 'grooscript.min', 'grooscript-tools'], function($) { 3 | require(['Cell', 'Game', 'GamePresenter'], function() { 4 | 5 | $(document).ready(function() { 6 | presenter = GamePresenter(); 7 | presenter.init(); 8 | }); 9 | 10 | $(document).keydown(function(event) { 11 | if (event.which == 37) { 12 | presenter.move('left'); 13 | }; 14 | if (event.which == 38) { 15 | presenter.move('up'); 16 | }; 17 | if (event.which == 39) { 18 | presenter.move('right'); 19 | }; 20 | if (event.which == 40) { 21 | presenter.move('down'); 22 | }; 23 | }); 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /src/main/webapp/js/snap.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | SnapSvg.snapSvg("svg", function(it) { 3 | var middle = gs.map().add("x",150).add("y",150); 4 | gs.mc(this,"circle",[gs.map().add("cx",gs.gp(middle,"x")).add("cy",gs.gp(middle,"y")).add("r",145).add("fill","none").add("stroke","#000").add("strokeWidth",3)]); 5 | gs.mc(this,"circle",[gs.map().add("cx",gs.gp(middle,"x")).add("cy",gs.gp(middle,"y")).add("r",76).add("fill","none").add("stroke","#000").add("strokeWidth",1)]); 6 | var hourText = gs.mc(this,"text",[gs.map().add("x",gs.gp(middle,"x")).add("y",30).add("text","XII").add("fontSize","30px").add("text-anchor","middle").add("fill","#666")]); 7 | gs.sp(hourText,"verticalScale",2.4); 8 | var romanNumbers = gs.list(["I" , "II" , "III" , "IV" , "V" , "VI" , "VII" , "VIII" , "IX" , "X" , "XI"]); 9 | (11).times(function(val) { 10 | var newHour = gs.mc(hourText,"copy",[]); 11 | gs.sp(newHour,"text",(romanNumbers[val])); 12 | return gs.mc(newHour,"rotateAndScale",[gs.multiply(30, (gs.plus(val, 1))), 2.4, gs.gp(middle,"x"), gs.gp(middle,"y")]); 13 | }); 14 | var secondPoint = gs.mc(this,"circle",[gs.map().add("cx",gs.gp(middle,"x")).add("cy",13).add("r",3).add("fill","black").add("stroke","#000")]); 15 | (59).times(function(val) { 16 | return gs.sp(gs.mc(gs.mc(secondPoint,"copy",[]),"rotate",[gs.multiply(6, (gs.plus(val, 1))), gs.gp(middle,"x"), gs.gp(middle,"y")]),"r",(gs.mod((gs.plus(val, 1)), 5) ? 2 : 3)); 17 | }); 18 | var hours = gs.mc(this,"rect",[gs.map().add("x",gs.minus(gs.gp(middle,"x"), 2)).add("y",65).add("width",4).add("height",85).add("fill","#000")]); 19 | var minutes = gs.mc(this,"rect",[gs.map().add("x",gs.minus(gs.gp(middle,"x"), 1)).add("y",40).add("width",2).add("height",110).add("fill","#000")]); 20 | var seconds = gs.mc(this,"rect",[gs.map().add("x",gs.minus(gs.gp(middle,"x"), 0.5)).add("y",13).add("width",1).add("height",150).add("fill","red")]); 21 | var rotateClockHands = function(it) { 22 | var nowValues = gs.mc(gs.mc(gs.mc(gs.date(),"format",["HH:mm:ss"]),"split",[":"]),"collect",[function(it) { 23 | return gs.mc(it,"toInteger",[]); 24 | }]); 25 | var hour = gs.mod((nowValues[0]), 12); 26 | var minute = nowValues[1]; 27 | gs.mc(hours,"rotate",[gs.plus((gs.multiply(hour, 30)), (gs.div(minute, 2))), gs.gp(middle,"x"), gs.gp(middle,"y")]); 28 | gs.mc(minutes,"rotate",[gs.multiply(minute, 6), gs.gp(middle,"x"), gs.gp(middle,"y")]); 29 | return gs.mc(seconds,"rotate",[gs.multiply((nowValues[2]), 6), gs.gp(middle,"x"), gs.gp(middle,"y")]); 30 | }; 31 | gs.execCall(rotateClockHands, this, []); 32 | return gs.mc(this,"repeat",[1000, rotateClockHands]); 33 | }); 34 | -------------------------------------------------------------------------------- /src/main/webapp/js/startLiveAdoc.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | var renderComponent = function(component, selector) { 3 | var gQuery = GQueryImpl(); 4 | return gs.mc(gQuery,"onReady",[function(it) { 5 | return gs.mc(component,"start",[selector]); 6 | }]); 7 | }; 8 | gs.execCall(renderComponent, this, [AdocLive(), "#asciidoctor"]); 9 | -------------------------------------------------------------------------------- /src/main/webapp/js/startThree.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | gs.mc(gs.execStatic(Three,'scene', this,[function(it) { 3 | gs.mc(gs.mc(this,"tetrahedron",[200]),"moveTo",[-360, 300, 300]); 4 | gs.mc(gs.mc(this,"icosahedron",[200]),"moveTo",[360, 200, 300]); 5 | gs.mc(gs.mc(this,"sphere",[100, 50, 50]),"moveTo",[-300, -200, 100]); 6 | gs.mc(gs.mc(this,"torus",[200, 50, 50, 50]),"moveTo",[-300, -200, 100]); 7 | gs.mc(gs.mc(this,"ring",[20, 200, 50]),"moveTo",[450, -200, 100]); 8 | gs.mc(this,"setMaterial",[gs.fs('grooscriptMaterial', this)]); 9 | return gs.mc(this,"box",[200, 200, 200]); 10 | }]),"animate",[function(items) { 11 | gs.mc(gs.mc(items,"findAll",[function(it) { 12 | return gs.gp(it,"name") != "Box"; 13 | }]),"each",[function(it) { 14 | gs.sp(gs.gp(it,"rotation"),"x",gs.gp(gs.gp(it,"rotation"),"x") + (gs.gp(it,"name") != "Torus" ? 0.01 : -0.01)); 15 | return gs.sp(gs.gp(it,"rotation"),"y",gs.gp(gs.gp(it,"rotation"),"y") + 0.02); 16 | }]); 17 | return gs.mc(gs.mc(items,"findAll",[function(it) { 18 | return gs.equals(gs.gp(it,"name"), "Box"); 19 | }]),"each",[function(it) { 20 | return gs.mc(it,"rotateLeft",[]); 21 | }]); 22 | }]); 23 | -------------------------------------------------------------------------------- /src/main/webapp/js/todo.js: -------------------------------------------------------------------------------- 1 | angular.module('todoApp', []) 2 | .controller('TodoController', ['$scope', function($scope) { 3 | $scope.todos = [ 4 | {text:'learn angular', done:true}, 5 | {text:'build an angular app', done:false}]; 6 | 7 | $scope.addTodo = function() { 8 | $scope.todos.push({text:$scope.todoText, done:false}); 9 | $scope.todoText = ''; 10 | }; 11 | 12 | $scope.remaining = function() { 13 | var count = 0; 14 | angular.forEach($scope.todos, function(todo) { 15 | count += todo.done ? 0 : 1; 16 | }); 17 | return count; 18 | }; 19 | 20 | $scope.archive = function() { 21 | var oldTodos = $scope.todos; 22 | $scope.todos = []; 23 | angular.forEach(oldTodos, function(todo) { 24 | if (!todo.done) $scope.todos.push(todo); 25 | }); 26 | }; 27 | }]); -------------------------------------------------------------------------------- /src/main/webapp/js/todoAngular.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | var todoAngular = function($scope) { 3 | gs.sp($scope,"todos",gs.list([gs.map().add("text","learn angular").add("done",true) , gs.map().add("text","build an angular app").add("done",false)])); 4 | gs.sp($scope,"addTodo",function(it) { 5 | gs.mc(gs.gp($scope,"todos"),'leftShift', gs.list([gs.map().add("text",gs.gp($scope,"todoText")).add("done",false)])); 6 | return gs.sp($scope,"todoText",""); 7 | }); 8 | gs.sp($scope,"remaining",function(it) { 9 | return gs.mc(gs.gp($scope,"todos"),"inject",[0, function(acc, todo) { 10 | return (gs.bool(gs.gp(todo,"done")) ? gs.plus(acc, 1) : acc); 11 | }]); 12 | }); 13 | return gs.sp($scope,"archive",function(it) { 14 | return gs.sp($scope,"todos",gs.mc(gs.gp($scope,"todos"),"findAll",[function(it) { 15 | return !gs.gp(it,"done"); 16 | }])); 17 | }); 18 | }; 19 | -------------------------------------------------------------------------------- /src/main/webapp/js/todoAngularTwo.js: -------------------------------------------------------------------------------- 1 | //Grooscript converted file 2 | function TodoController() { 3 | var gSobject = gs.init('TodoController'); 4 | gSobject.clazz = { name: 'angular.TodoController', simpleName: 'TodoController'}; 5 | gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; 6 | gSobject.clazz.interfaces = [{ name: 'angular.AngularController', simpleName: 'AngularController'}]; 7 | gSobject.init = function() { return AngularController.init(gSobject); } 8 | gSobject.controllerProperties = function(x1) { return AngularController.controllerProperties(gSobject,x1); } 9 | gSobject.controllerMethods = function(x1) { return AngularController.controllerMethods(gSobject,x1); } 10 | gSobject.getScope = function() { return AngularController.getScope(gSobject); } 11 | gSobject.setScope = function(x1) { return AngularController.setScope(gSobject,x1); } 12 | gSobject.todos = gs.list([gs.map().add("text","learn angular").add("done",true) , gs.map().add("text","build an angular app").add("done",false)]); 13 | gSobject['addTodo'] = function(it) { 14 | gs.mc(gs.gp(gSobject.getScope(),"todos"),'leftShift', gs.list([gs.map().add("text",gs.gp(gSobject.getScope(),"todoText")).add("done",false)])); 15 | return gs.sp(gSobject.getScope(),"todoText",""); 16 | } 17 | gSobject['remaining'] = function(it) { 18 | return gs.mc(gs.gp(gSobject.getScope(),"todos"),"count",[function(it) { 19 | return gs.gp(it,"done"); 20 | }]); 21 | } 22 | gSobject['archive'] = function(it) { 23 | return gs.sp(gSobject.getScope(),"todos",gs.mc(gSobject.todos,"findAll",[function(it) { 24 | return !gs.gp(it,"done"); 25 | }])); 26 | } 27 | if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; 28 | 29 | return gSobject; 30 | }; 31 | TodoController.controllerProperties = function() { return AngularController.controllerProperties.apply(TodoController, [TodoController].concat(Array.prototype.slice.call(arguments)));} 32 | TodoController.controllerMethods = function() { return AngularController.controllerMethods.apply(TodoController, [TodoController].concat(Array.prototype.slice.call(arguments)));} 33 | AngularController = function() {}; 34 | AngularController.gSaT = function(target) { 35 | target.init = function(x0) { return AngularController.init(target, x0); }; 36 | target.controllerProperties = function(x0, x1) { return AngularController.controllerProperties(target, x0, x1); }; 37 | target.controllerMethods = function(x0, x1) { return AngularController.controllerMethods(target, x0, x1); }; 38 | target.getScope = function(x0) { return AngularController.getScope(target, x0); }; 39 | target.setScope = function(x0, x1) { return AngularController.setScope(target, x0, x1); }; 40 | }; 41 | AngularController.$init$ = function($self) { 42 | } 43 | function AngularController$static$init$($static$self){ 44 | 45 | }; 46 | AngularController.init = function($self) { 47 | return gs.mc(function(controller, angularScope) { 48 | gs.sp(controller,"scope",angularScope); 49 | gs.mc(gs.mc($self,"controllerProperties",[controller]),"each",[function(nameProperty) { 50 | return gs.sp(angularScope,"" + (nameProperty) + "",gs.gp(controller,"" + (nameProperty) + "")); 51 | }]); 52 | return gs.mc(gs.mc($self,"controllerMethods",[controller]),"each",[function(nameMethod) { 53 | return gs.sp(angularScope,"" + (nameMethod) + "",controller["" + (nameMethod) + ""]); 54 | }]); 55 | },"curry",[$self]); 56 | } 57 | AngularController.controllerProperties = function($static$self, controller) { 58 | return gs.mc(gs.mc(gs.gp(controller,"properties"),"findAll",[function(key, value) { 59 | return !gs.gSin(key, gs.list(["class" , "scope"])); 60 | }]),"collect",[function(key, value) { 61 | return key; 62 | }]); 63 | } 64 | AngularController.controllerMethods = function($static$self, controller) { 65 | return gs.mc(gs.mc(gs.gp((controller = gs.metaClass(controller)),"methods"),"findAll",[function(method) { 66 | return (((!gs.bool(gs.mc(gs.gp(method,"name"),"startsWith",["set"]))) && (!gs.bool(gs.mc(gs.gp(method,"name"),"startsWith",["get"])))) && (!gs.bool(gs.mc(gs.gp(method,"name"),"contains",["$"])))) && (!gs.bool(gs.gSin(gs.gp(method,"name"), gs.list(["equals" , "hashCode" , "notify" , "notifyAll" , "toString" , "wait" , "controllerMethods" , "controllerProperties" , "init" , "invokeMethod"])))); 67 | }]),"collect",[function(it) { 68 | return gs.gp(it,"name"); 69 | }]); 70 | } 71 | AngularController.getScope = function($self) { return $self.angular_AngularController__scope; } 72 | AngularController.setScope = function($self, value) { $self.angular_AngularController__scope = value; } 73 | -------------------------------------------------------------------------------- /src/main/webapp/maps.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Grooscript Map 5 | 6 | 7 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
        25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/webapp/react.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Initial static web page 4 | 5 | 6 | 7 | 8 | 9 | 10 |
        11 | -------------------------------------------------------------------------------- /src/main/webapp/sigma.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 |

        Search countries: Loading...

        14 |

        Countries data from REST countries API. 15 | Graphs powered by sigma.js. Use the mouse in the canvas to zoom or move.

        16 |
        17 |

        Source code

        18 |

        grooscript powered.

        19 | 20 | 21 | 22 | 23 | 24 | 25 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/webapp/snapsvg.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Initial static web page 4 | 5 | 6 | 7 | 8 | 18 | 19 | 20 |

        Clock!

        21 | 22 | 23 | 24 | 25 | 50 | -------------------------------------------------------------------------------- /src/main/webapp/stars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Initial static web page 4 | 5 | 6 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/webapp/templates/index.gtpl: -------------------------------------------------------------------------------- 1 | yieldUnescaped '' 2 | html { 3 | head { 4 | title 'Chat' 5 | ['js/jquery.min.js','js/grooscript.min.js','js/grooscript-tools.js', 6 | 'js/Client.js','js/gstemplates.js','https://cdn.socket.io/socket.io-1.2.0.js'].each { 7 | script(type: 'text/javascript', src: it) {} 8 | } 9 | link(rel: 'stylesheet', type: 'text/css', href: 'css/chat.css') 10 | } 11 | 12 | body { 13 | header { 14 | h2 { 15 | a(href: 'http://grooscript.org') { 16 | yield 'grooscript' 17 | } 18 | yield ' chat demo' 19 | } 20 | h4 { 21 | a(href: 'https://github.com/chiquitinxx/grooscript-demos') { 22 | yield 'GitHub source demos' 23 | } 24 | } 25 | } 26 | section { 27 | div (id: 'loginArea') { 28 | input (id: 'login', autocomplete: 'off', autofocus: "true") { 29 | button (id: 'loginButton') { 30 | yield 'Login' 31 | } 32 | } 33 | } 34 | div (id: 'chatArea') { 35 | ul id: 'messages' 36 | div (id: 'message') { 37 | input (id: 'chat', autocomplete: 'off') { 38 | button (id: 'sendMessage') { 39 | yield 'Send' 40 | } 41 | } 42 | } 43 | } 44 | } 45 | script { 46 | yield 'Client.init();' 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/webapp/templates/join.gtpl: -------------------------------------------------------------------------------- 1 | li { 2 | if (name == 'Groovy') { 3 | 3.times { 4 | img src: 'img/groovy.png', height: 20 5 | } 6 | } else { 7 | b "${model.name} " 8 | yield 'joined the chat!' 9 | } 10 | } -------------------------------------------------------------------------------- /src/main/webapp/templates/left.gtpl: -------------------------------------------------------------------------------- 1 | li { 2 | if (model.name.toLowerCase().contains('danveloper')) { 3 | b '#unfollowdanveloper' 4 | } else { 5 | b "${model.name} " 6 | yield 'left the chat.' 7 | } 8 | } -------------------------------------------------------------------------------- /src/main/webapp/templates/message.gtpl: -------------------------------------------------------------------------------- 1 | def pirateMessages = ['YARRRRR!', 'YO-HO!', 'Ahoy Boys!', 'Surrrrrender the booty!'] 2 | 3 | li { 4 | b "${model.name}: " 5 | if (model.name.toLowerCase().contains('pirate')) { 6 | def randomNumber = new Random().nextInt(pirateMessages.size()) 7 | yield "${model.msg} ${pirateMessages[randomNumber]}" 8 | } else { 9 | yield model.msg 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/webapp/three.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Three.js grooscript demo 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/groovy/countries/CountriesPresenterSpec.groovy: -------------------------------------------------------------------------------- 1 | package countries 2 | 3 | import org.grooscript.jquery.GQuery 4 | import org.grooscript.jquery.GQueryImpl 5 | import org.grooscript.jquery.GQueryList 6 | import spock.lang.Specification 7 | 8 | /** 9 | * User: jorgefrancoleza 10 | * Date: 19/10/14 11 | */ 12 | class CountriesPresenterSpec extends Specification { 13 | 14 | def 'start presenter'() { 15 | when: 16 | presenter.start() 17 | 18 | then: 19 | presenter.countries.size() == 1 20 | 1 * sigma.addNode([id: 'AFG', label: 'Afghanistan', x: 65.0, y: 33.0, color: presenter.purpleColor]) 21 | 1 * sigma.addEdge('AFGAFG', 'AFG', 'AFG') 22 | 1 * sigma.refresh() 23 | 1 * gQueryList.methodMissing('html', ['1 found. ']) 24 | 0 * _ 25 | } 26 | 27 | def 'on change to empty country'() { 28 | when: 29 | presenter.countries = presenter.loadCountries() 30 | presenter.onChangeCountry('') 31 | 32 | then: 33 | 1 * sigma.applyToNodes(_) 34 | 1 * gQueryList.methodMissing('html', ['1 found. ']) 35 | 1 * sigma.moveCamaraTo(0, 0, 1) 36 | 1 * sigma.refresh() 37 | 0 * _ 38 | } 39 | 40 | def 'on change to non existing country'() { 41 | when: 42 | presenter.countries = presenter.loadCountries() 43 | presenter.onChangeCountry('NULL') 44 | 45 | then: 46 | 1 * sigma.applyToNodes(_) 47 | 1 * gQueryList.methodMissing('html', ['0 found. ']) 48 | 1 * sigma.moveCamaraTo(0, 0, 1) 49 | 1 * sigma.refresh() 50 | 0 * _ 51 | } 52 | 53 | private CustomSigma sigma = Mock() 54 | private gQueryList = Mock(GQueryList) 55 | private GQuery gQuery = Stub(GQueryImpl) { 56 | call('#searchResult') >> gQueryList 57 | } 58 | CountriesPresenter presenter = new CountriesPresenter(customSigma: sigma, gQuery: gQuery) 59 | } 60 | -------------------------------------------------------------------------------- /src/test/groovy/react/TodoAppTest.groovy: -------------------------------------------------------------------------------- 1 | package react 2 | 3 | import org.grooscript.GrooScript 4 | 5 | /** 6 | * User: jorgefrancoleza 7 | * Date: 20/09/14 8 | */ 9 | class TodoAppTest extends GroovyTestCase { 10 | 11 | TodoApp todoApp = new TodoApp() 12 | 13 | void testInit() { 14 | todoApp.init() 15 | assert todoApp.actualTodo == '' 16 | assert todoApp.todos == [] 17 | } 18 | 19 | void testAddTodosSubmit() { 20 | todoApp.init() 21 | todoApp.addTodosSubmit() 22 | assert todoApp.todos == [] 23 | todoApp.actualTodo = 'New' 24 | todoApp.addTodosSubmit() 25 | assert todoApp.todos == ['New'] 26 | assert todoApp.actualTodo == '' 27 | } 28 | 29 | void testActualTodoChange() { 30 | todoApp.actualTodo = 'initial' 31 | todoApp.actualTodoChange('final') 32 | assert todoApp.actualTodo == 'final' 33 | } 34 | 35 | void testAstAddProperties() { 36 | assertScript ''' 37 | import org.grooscript.jquery.GQueryImpl 38 | 39 | @react.Component 40 | class Comp {} 41 | 42 | def comp = new Comp() 43 | assert comp.gQuery 44 | assert comp.gQuery instanceof GQueryImpl 45 | assert comp.selector == null 46 | ''' 47 | } 48 | 49 | void testCreateSetMethodForString() { 50 | assertScript ''' 51 | import org.grooscript.jquery.GQueryImpl 52 | 53 | @react.Component 54 | class Comp { 55 | String name 56 | boolean calledRender = false 57 | 58 | void render() { 59 | calledRender = true 60 | } 61 | } 62 | 63 | def comp = new Comp() 64 | comp.setName('newName') 65 | assert comp.name == 'newName' 66 | assert comp.calledRender == true 67 | ''' 68 | } 69 | 70 | void testCreateStartMethod() { 71 | assertScript ''' 72 | import org.grooscript.jquery.GQueryImpl 73 | 74 | @react.Component 75 | class Comp { 76 | String name 77 | boolean calledRender = false 78 | boolean initialized = false 79 | 80 | void init() { 81 | initialized = true 82 | } 83 | 84 | void render() { 85 | calledRender = true 86 | } 87 | } 88 | 89 | def comp = new Comp() 90 | comp.start('selector') 91 | assert comp.selector == 'selector' 92 | assert comp.initialized == true 93 | assert comp.calledRender == true 94 | ''' 95 | } 96 | 97 | void testCreateMethodRenderIfNotExist() { 98 | assertScript ''' 99 | import org.grooscript.jquery.GQueryImpl 100 | 101 | @react.Component 102 | class Comp { 103 | } 104 | 105 | def comp = new Comp() 106 | comp.render() 107 | ''' 108 | } 109 | 110 | void testChangeMethodRenderIfAlreadyExists() { 111 | assertScript ''' 112 | import org.grooscript.jquery.GQueryImpl 113 | 114 | @react.Component 115 | class Comp { 116 | void render() { 117 | p 'hola' 118 | } 119 | } 120 | 121 | def comp = new Comp(selector: 'selector') 122 | comp.render() 123 | ''' 124 | } 125 | 126 | void testConvertAst() { 127 | try { 128 | GrooScript.convert(['src/main/groovy/react/TodoApp.groovy'], '.', [classpath: 'src/main/groovy']) 129 | assert new File('TodoApp.js').text.contains('gSobject.gQuery = GQueryImpl();') 130 | } finally { 131 | new File('TodoApp.js')?.delete() 132 | } 133 | } 134 | } -------------------------------------------------------------------------------- /src/test/resources/miniCountries.json: -------------------------------------------------------------------------------- 1 | [{"name":"Afghanistan","capital":"Kabul","altSpellings":["AF","Afġānistān"], 2 | "relevance":"0","region":"Asia","subregion":"Southern Asia", 3 | "translations":{"de":"Afghanistan","es":"Afganistán","fr":"Afghanistan", 4 | "ja":"アフガニスタン","it":"Afghanistan"}, 5 | "population":26023100,"latlng":[33.0,65.0],"demonym":"Afghan","area":652230.0, 6 | "gini":27.8,"timezones":["UTC+04:30"],"borders":["AFG"], 7 | "nativeName":"افغانستان","callingCodes":["93"],"topLevelDomain":[".af"], 8 | "alpha2Code":"AF","alpha3Code":"AFG","currencies":["AFN"],"languages":["ps","uz","tk"] 9 | }] -------------------------------------------------------------------------------- /startChat.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var gs = require('grooscript'); 3 | 4 | eval(fs.readFileSync('src/main/webapp/js/grooscript-tools.js')+''); 5 | eval(fs.readFileSync('src/main/webapp/js/gstemplates.js')+''); 6 | eval(fs.readFileSync('js/NodeServer.js')+''); 7 | eval(fs.readFileSync('js/startServer.js')+''); --------------------------------------------------------------------------------