Brauhaus.js Timeline Exmaple (CoffeeScript)

by danielgtaylor

HTML

<script src="https://rawgithub.com/homebrewing/brauhausjs/master/dist/brauhaus.min.js"></script>
<h3>Test Recipe Timeline (metric units)</h3>
<table id="timelineMetric"></table>
<h3>Test Recipe Timeline (imperial units)</h3>
<table id="timelineImperial"></table>

CoffeeScript

# Create a new recipe
recipe = new Brauhaus.Recipe
    name: 'Test Recipe'
    batchSize: 20.0
    primaryDays: 10
    secondaryDays: 5

# Add 4kg of pale extract
recipe.add 'fermentable',
    name: 'Extra pale extract'
    weight: 4.0
    color: 2.5
    yield: 75.0

# Add 0.5kg of steeped caramel malt
recipe.add 'fermentable',
    name: 'Caramel 40L'
    weight: 0.5
    color: 40.0
    yield: 75.0

# Add 1oz of cascade at 60 minutes
recipe.add 'spice',
    name: "Cascade hops"
    weight: Brauhaus.lbOzToKg 0, 1.0
    time: 60
    aa: 4.5
    form: 'pellet'

# Add some liquid yeast
recipe.add 'yeast',
    name: 'Wyeast 3052'
    type: 'ale'
    form: 'liquid'
    attenuation: 74

# Calculate the recipe values!
recipe.calculate()

# Generate and print the timeline!
for [duration, description] in recipe.timeline()
    $('#timelineMetric').append "<tr><td>#{Brauhaus.displayDuration duration, 2}</td><td>#{description}</td></tr>"

for [duration, description] in recipe.timeline(false)
    $('#timelineImperial').append "<tr><td>#{Brauhaus.displayDuration duration, 2}</td><td>#{description}</td></tr>"