Brauhaus BeerXML Calculator Example (Coffeescript)
An example showing how to use Brauhaus to calculate OG, FG, IBU, and ABV from BeerXML input.
HTML
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
<script src="https://rawgithub.com/homebrewing/brauhausjs/master/dist/brauhaus.min.js"></script>
<script src="https://rawgithub.com/homebrewing/brauhaus-beerxml/master/dist/brauhaus-beerxml.min.js"></script>
<textarea id="beerxml" placeholder="BeerXML goes here..."><?xml version="1.0" encoding="utf-8"?><RECIPES><RECIPE><VERSION>1</VERSION><NAME>Aramis Saison</NAME><TYPE>Extract</TYPE><STYLE></STYLE><BREWER>danielgtaylor</BREWER><BATCH_SIZE>18.92705</BATCH_SIZE><BOIL_SIZE>11.35623</BOIL_SIZE><EFFICIENCY>75</EFFICIENCY><HOPS><HOP><VERSION>1</VERSION><NAME>Aramis hops</NAME><ALPHA>8.1</ALPHA><AMOUNT>0.0212615166549</AMOUNT><AMOUNT_IS_WEIGHT>TRUE</AMOUNT_IS_WEIGHT><USE>Boil</USE><TIME>60</TIME><FORM>Pellet</FORM></HOP><HOP><VERSION>1</VERSION><NAME>Aramis hops</NAME><ALPHA>8.1</ALPHA><AMOUNT>0.00708717221828</AMOUNT><AMOUNT_IS_WEIGHT>TRUE</AMOUNT_IS_WEIGHT><USE>Boil</USE><TIME>5</TIME><FORM>Pellet</FORM></HOP></HOPS><FERMENTABLES><FERMENTABLE><VERSION>1</VERSION><NAME>Munich liquid extract</NAME><AMOUNT>2.26795</AMOUNT><YIELD>75.7346258709</YIELD><COLOR>10</COLOR><ADD_AFTER_BOIL>FALSE</ADD_AFTER_BOIL></FERMENTABLE><FERMENTABLE><VERSION>1</VERSION><NAME>Wheat liquid...
CSS
textarea {
width: 98%;
height: 200px;
margin-top: 1em;
}
th {
display: inline-block;
text-align: left;
margin-right: 0.5em;
}
CoffeeScript
# Create and calculate recipe when button is clicked
$('#calc').click ->
# Get a list of recipes from the BeerXML
beerxml = $('#beerxml').val()
recipes = Brauhaus.Recipe.fromBeerXml(beerxml)
# We only care about the first recipe...
# Let's calculate and display some values!
recipe = recipes[0]
recipe.calculate()
# Display calculated recipe stats
$('#og').html "#{recipe.og.toFixed 3} (#{recipe.ogPlato.toFixed 1}° Plato)"
$('#fg').html "#{recipe.fg.toFixed 3} (#{recipe.fgPlato.toFixed 1}° Plato)"
$('#ibu').html "#{recipe.ibu.toFixed 1}"
$('#color').html "#{Math.round recipe.color}° SRM (#{Math.round Brauhaus.srmToEbc(recipe.color)}° EBC)"
$('#abv').html "#{recipe.abv.toFixed 2}%"