coffee to multiple divs

class which prints to multiple output divs

by Andy Bulka

HTML

<h1>Coffeescript outputting to multiple divs</h1>
<h2>output:</h2>
<div id="out"></div>
<div id="out3"></div>
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

CSS

div#out {
  background-color: #FAD3A9;
  font-size: 1.2em;
  margin:12px;
  padding:4px;
}
h1              { font-size: 2em; margin-left: .67em 0 }
h2              { font-size: 1.5em; margin-left: .75em 0 }
h3              { font-size: 1.17em; margin: .83em 0 }

div#out3 {
    margin:12px;
    -moz-column-count: 3;
    -moz-column-gap: px;
    -webkit-column-count: 3;
    -webkit-column-gap: px;
    column-count: 3;
    column-gap: px;
}

CoffeeScript

class PrintToDiv
  constructor: (currdiv=$('#out')) ->
    this.setdiv(currdiv)
    
  setdiv: (currdiv) ->
    @currdiv = currdiv
    
  pr: (msg='', crlf=true, hr=false) ->
    crlf=true if msg==''
    @currdiv.append msg
    @currdiv.append ' ' if not crlf and not hr
    @currdiv.append '<br>' if crlf
    @currdiv.append '<hr>' if hr

p = new PrintToDiv()
  
p.pr(num, crlf=false) for num in [50..1]  
p.pr(hr=true)
p.setdiv($('#out3'))
p.pr(num, crlf=false) for num in [300..1]  
p.setdiv($('#out'))
p.pr('hi andy')
p.setdiv($('#out3'))
p.pr()
p.pr('hi again')
  
###
class A
  constructor: (name) ->
    @name = name+'s'
  pr: ->
    @name+='z'
    @name+'Z'

square = (x) -> 
  z = x * x
  z2 = "hi"
  100

a = new A('fred')
alert(a.pr())
alert(square(10))
###