This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4798797
commit c75bba9
Showing
8 changed files
with
147 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/groovy/org/grooscript/convert/packages/DojoHandler.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.grooscript.convert.packages | ||
|
||
import org.codehaus.groovy.ast.expr.MethodCallExpression | ||
import org.codehaus.groovy.ast.expr.PropertyExpression | ||
import org.codehaus.groovy.ast.expr.StaticMethodCallExpression | ||
import org.grooscript.convert.ConversionFactory | ||
|
||
/** | ||
* Created by jorgefrancoleza on 19/11/14. | ||
*/ | ||
class DojoHandler { | ||
|
||
def packages = [] | ||
def variableName | ||
ConversionFactory factory | ||
|
||
boolean handle(node) { | ||
if (node instanceof StaticMethodCallExpression && | ||
node.method == 'require' && | ||
node.ownerType.name == 'org.grooscript.packages.DojoPackage') { | ||
packages << node.arguments[0].value.replaceAll('/','.') | ||
return true | ||
} | ||
if (node instanceof MethodCallExpression && | ||
node.objectExpression instanceof PropertyExpression && | ||
node.objectExpression.text in packages) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
boolean process(node) { | ||
if (node instanceof StaticMethodCallExpression && | ||
node.method == 'require' && | ||
node.ownerType.name == 'org.grooscript.packages.DojoPackage') { | ||
def pack = node.arguments[0].value | ||
variableName = pack.split('/').last() | ||
factory.out.indent++ | ||
factory.out.addScript("require([\"${pack}\"], function(${variableName}) {", true) | ||
factory.visitNode(node.arguments[1].code, false) | ||
factory.out.indent-- | ||
factory.out.removeTabScript() | ||
factory.out.addScript("})") | ||
} | ||
if (node instanceof MethodCallExpression && | ||
node.objectExpression instanceof PropertyExpression && | ||
node.objectExpression.text in packages) { | ||
factory.out.addScript("${variableName}.${node.methodAsString}(") | ||
factory.convert(node.arguments, false) | ||
factory.out.addScript(")") | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/groovy/org/grooscript/packages/DojoPackage.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.grooscript.packages | ||
|
||
/** | ||
* Created by jorgefrancoleza on 19/11/14. | ||
*/ | ||
class DojoPackage { | ||
Dojo dojo = new Dojo() | ||
|
||
static require(String pack, @DelegatesTo(DojoPackage) Closure cl) { | ||
def dojoPackage = new DojoPackage() | ||
cl.delegate = dojoPackage | ||
cl() | ||
} | ||
} | ||
|
||
class Dojo { | ||
Cldr cldr = new Cldr() | ||
} | ||
|
||
class Cldr { | ||
Monetary monetary = new Monetary() | ||
} | ||
|
||
class Monetary { | ||
def getData(String currency) { | ||
[ places: currency + new Random().nextInt(50), round: currency + new Random().nextInt(50) ] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package packages | ||
|
||
/** | ||
* Created by jorgefrancoleza on 18/11/14. | ||
*/ | ||
import static org.grooscript.packages.DojoPackage.require | ||
|
||
require("dojo/cldr/monetary") { | ||
["EUR", "USD", "GBP", "JPY"].each { | ||
def cldrMonetaryData = dojo.cldr.monetary.getData(it) | ||
println "Places: $cldrMonetaryData.places" | ||
println "Round: $cldrMonetaryData.round" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.