Created
October 30, 2012 18:03
-
-
Save dtanner/3981914 to your computer and use it in GitHub Desktop.
Groovy script to generate addition table quizzes for kids.
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 getRandomNumber() { | |
randomInt = new Random().nextInt(11) | |
} | |
def buildCell() { | |
"""${getRandomNumber()} <br> | |
+ ${getRandomNumber()} <br> | |
<hr width=40px> | |
""" | |
} | |
def createHtmlFile(String fileName){ | |
int rows = 5 | |
int colsPerRow = 8 | |
def writer = new StringWriter() | |
def builder = new groovy.xml.MarkupBuilder(writer) | |
builder.html(){ | |
body { | |
table(cellpadding:'20px') { | |
rows.times { | |
tr { | |
colsPerRow.times { | |
td([align:'right', style:'font-size:18px'], { mkp.yieldUnescaped (buildCell()) }) | |
} | |
} | |
} | |
} | |
} | |
} | |
def f = new File("/tmp/$fileName") | |
f.delete() | |
f << writer.toString() | |
} | |
40.times { | |
createHtmlFile("${it}.html") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment