Advertisement
enyo

Untitled

May 15th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Renderer
  2.  
  3.  
  4.   # Escapes a text for a regex.
  5.   @escapeRegex = (text) ->
  6.     return text.replace /[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"
  7.  
  8.   mapImports: (template) ->
  9.     regex = /\(import ([^\)]+)\)/g
  10.     matches = _.uniq(template.match(regex) || [ ])
  11.     map = [ ]
  12.  
  13.     matches.forEach (match, i) =>
  14.       random = i + "." + Math.round(Math.random() * 10000000000).toString()
  15.       templateName = match.replace regex, "$1"
  16.       map.push templateName: templateName, randomHash: random
  17.       template = template.replace new RegExp(@::escapeRegex(match), 'g'), random
  18.  
  19.     { template: template, map: map }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement