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
define('view/person', ['domain/person', 'jQuery', 'window'], function(Person, $, Win) { | |
var person = Person.createPerson(); | |
return { | |
showPerson: function() { | |
$('#person-div').html(person.name); | |
Win.alert('Person updated!'); | |
} | |
}; |
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
<script src="js/lib/require-2.1.2.js" | |
data-main="js/bootstrap${grailsApplication.isWarDeployed() ? '-build' : ''}"> | |
</script> |
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
eventCreateWarStart = { warName, stagingDir -> | |
def curDir = new File('Scripts'); | |
ant.exec(outputproperty: "cmdOut", errorproperty: "cmdErr", resultproperty: "cmdExit", failonerror: "false", executable: "java") { | |
arg(line: "-cp ${new File(curDir, 'js.jar').absolutePath}") | |
arg(line: "org.mozilla.javascript.tools.shell.Main") | |
arg(line: "${new File(curDir, 'r.js').absolutePath}") | |
arg(line: "-o") | |
arg(line: "name=bootstrap") | |
arg(line: "baseUrl=${stagingDir}/js") | |
arg(line: "out=${stagingDir}/js/bootstrap-build.js") |
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
eventWebXmlEnd = { String tmpfile -> | |
def contextParam = '''<context-param> | |
<description>Spring Expression Language Support</description> | |
<param-name>springJspExpressionSupport</param-name> | |
<param-value>false</param-value> | |
</context-param>''' | |
def root = new XmlParser().parse(webXmlFile) | |
root.children().add(0, new XmlParser().parseText(contextParam)) | |
new XmlNodePrinter(new PrintWriter(new FileWriter(webXmlFile))).print(root) | |
} |
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
Ant.java(classname: "com.sun.tools.internal.xjc.XJCFacade") { | |
arg(value: "-d") | |
arg(value: "src/java") | |
arg(value: "-p") | |
arg(value: "com.microsoft.books") | |
arg(value: "etc/schema/books.xsd") | |
} |
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
// Add the following to BuildConfig.groovy: | |
// build('com.sun.xml.bind:jaxb-xjc:2.1') | |
// build('com.sun.xml.bind:jaxb-impl:2.1') | |
target('generateSources': "Generate JAXB classes from a schema") { | |
def classpath = grailsSettings | |
.getBuildDependencies() | |
.join(System.getProperty("path.separator")) | |
Ant.taskdef(name: "xjc", | |
classname: "com.sun.tools.xjc.XJCTask", | |
classpath: classpath) |
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
def mapping = [[closure: { book.@id.text() }, length: 5], | |
[closure: { book.author.text().split(',')[0] }, length: 15], | |
[closure: { book.author.text().split(',')[1] }, length: 10]] |
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
def data = '''<?xml version="1.0"?> | |
<catalog> | |
<book id="bk101"> | |
<author>Gambardella, Matthew</author> | |
<title>XML Developer's Guide</title> | |
<genre>Computer</genre> | |
<price>44.95</price> | |
<publish_date>2000-10-01</publish_date> | |
</book> | |
<book id="bk102"> |
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
def xmlToFlatFile(xml, tag, mapping) { | |
def flatFile = new StringBuffer() | |
xml[tag].each { row -> | |
mapping.each { col -> | |
col.closure.delegate = [(tag): row] | |
def result = col.closure() ?: '' | |
flatFile << result | |
.trim() | |
.padRight(col.length) | |
.substring(0, col.length) |
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
def sep = System.getProperty('line.separator') | |
def expected = | |
"bk101Gambardella Matthew " + sep + | |
"bk102Ralls Kim " + sep + | |
"bk103Corets Eva " + sep | |
void testParsing() { | |
def books = new XmlSlurper().parseText(data) | |
assertEquals expected, xmlToFlatFile(books, 'book', mapping) | |
} |