 
 interpolated = file
   .replace(/<[^>]*?ng\-repeat="(.*?)">([\S\s]+)/gi, (match, text, post) ->
-    varName = text.split(' in ')[1]
+    varName = text
+    # varName = text.split(' in ')[1]
     close = getCloseTag match
     if close
-      "{{##{varName}}}\n#{close.before}\n{{/#{varName}}}\n#{close.after}"
+      "{{#each #{varName}}}\n#{close.before}\n{{/each}}\n#{close.after}"
     else
-      throw new Error 'Parse error! Coudlnt find close tag for ng-repeat'
+      throw new Error 'Parse error! Could not find close tag for ng-repeat'
   )
   .replace(/<[^>]*?ng\-if="(.*)".*?>([\S\s]+)/, (match, varName, post) ->
     # Unless

      varName = varName.substr 1
      close = getCloseTag match
      if close
        "{{##{varName}}}\n#{close.before}\n{{/#{varName}}}\n#{close.after}"
      else
        throw new Error 'Parse error! Coudlnt find close tag for ng-repeat'
    else
      close = getCloseTag match
      if close
        "{{##{varName}}}\n#{close.before}\n{{/#{varName}}}\n#{close.after}"
      else
        throw new Error 'Parse error! Coudlnt find close tag for ng-repeat'
  )
  .replace(/<[^>]*?ng\-show="(.*)".*?>([\S\s]+)/g, (match, varName, post) ->
    close = getCloseTag match
    if close
      "{{##{varName}}}\n#{close.before}\n{{/#{varName}}}\n#{close.after}"
    else
      throw new Error 'Parse error! Coudlnt find close tag for ng-repeat'
  )
  .replace(/<[^>]*?ng\-hide="(.*)".*?>([\S\s]+)/g, (match, varName, post) ->
    close = getCloseTag match
    if close
      "{{##{varName}}}\n#{close.before}\n{{/#{varName}}}\n#{close.after}"
    else
      throw new Error 'Parse error! Coudlnt find close tag for ng-repeat'
  )

console.log '\n\n\n\n\n\n\NINTERPOLATED:\n\n', interpolated

#!/usr/bin/env coffee

# TODO:
#   partials (crawl and map directory this script gets pointed to)
#   flask server render whole app backend a page at a time
#   angular hook into page post-render

argv = require('optimist').argv
fs = require 'fs'

if argv.file
  file = fs.readFileSync argv.file, 'utf8'
else
  console.warn 'you must specify a file with "--file="'
  return

selfClosingTags = 'area, base, br, col, command, embed, hr, img, input,
keygen, link, meta, param, source, track, wbr'.split /,\s*/

# TODO: pretty format
#   replace '\n' with '\n  ' where '  ' is 2 spaces * depth
#   Maybe prettify at very end instead
getCloseTag = (string) ->
  index = 0
  depth = 0
