     @unsetClass "kdcustomhtml"
 
     {content, syntax, title} = data = @getData()
-
-    # @codeView = new NonEditableAceField defaultValue: Encoder.htmlDecode(content), autoGrow: yes, afterOpen: =>
-    #   syntax or= 'javascript'
-    #   @codeView.setTheme 'merbivore'
-    #   @codeView.setSyntax syntax
-    #
-    # @codeView.on 'sizes.height.change', ({height}) =>
-    #   @$('.wrapper').height height
 
     hjsSyntax = __aceSettings.aceToHighlightJsSyntaxMap[syntax]
 


  pistachio:->
    """
    <div class='kdview'>
      {{> @codeView}}
    </div>
    """

class CodeBinSnippetView extends KDCustomHTMLView

    super options, data
    data = @getData()

    @codeViewContainer = new KDCustomHTMLView
      cssClass : "result-frame-container"

    @kiteController = @getSingleton('kiteController')

    @on "CodeBinSourceHasChanges",=>

      codebin = @getData()

      @iframeContents = "<html><head>"

      @iframeContents+= "<script src='//cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.6/prefixfree.min.js'></script>"
      @iframeContents+= "<script src='//code.jquery.com/jquery-latest.js'></script>"
      @iframeContents+= "<style>"+Encoder.htmlDecode(codebin.attachments[1].content)+"</style>"

      @iframeContents+= "</head><body>"

      @iframeContents+= Encoder.htmlDecode(codebin.attachments[0].content)
      @iframeContents+= "<script type='text/javascript'>"+Encoder.htmlDecode(codebin.attachments[2].content)+"</script>"

      @iframeContents+= "</body></html>"

      @iframeUsername = KD.whoami().profile.nickname
      @iframeTimestamp = new Date().getTime()


      # these are production paths and names! beware  --arvid
      @iframePath = "/Users/#{@iframeUsername}/Sites/#{@iframeUsername}.koding.com/website/codeshare_temp"
      @iframeFileName = 'codeshare_'+@iframeTimestamp+'.html'

      # remove this line when using on live servers --arvid
      @appendResultFrame "//lampuki.de/iframe.html"

      ###//////////////////////////////////////////////////////////////////////
      #
      # this block is also production logic. --arvid

      @kiteController.run
        withArgs  :
          command : "stat #{FSHelper.escapeFilePath(@iframePath)}"
      , (err, stderr, response)=>
        if err or stderr
          # log "temp directory not found, trying mkdir - response is",response
          @kiteController.run
            withArgs  :
              command : "mkdir #{FSHelper.escapeFilePath(@iframePath)}"
            ,(err, stderr, response)=>
              if err or stderr
                # log "Could not mkdir - response is",response
              else
                @uploadFileAndUpdateView()
        else
          @uploadFileAndUpdateView()


  uploadFileAndUpdateView:->
    @kiteController.run
       toDo           :  "uploadFile"
       withArgs       : {
         path         : FSHelper.escapeFilePath @iframePath+"/"+@iframeFileName
         contents     : @iframeContents
         username     : @iframeUsername
       }
    , (err, res)=>
      if err
        warn err
      else
        appendResultFrame "//#{@iframeUsername}.koding.com/codeshare_temp/"+@iframeFileName
      #
      #
      ///////////////////////////////////////////////////////////////////// ###


  appendResultFrame:(url)=>

    @codeView?.destroy()

    @codeView = new KDCustomHTMLView
      tagName  : "iframe"
      cssClass : "result-frame"
      name : "result-frame"
      attributes:
        src: url
        sandbox : "allow-scripts"
    @codeViewContainer.addSubView @codeView

  viewAppended: ->

