Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Renderer
- # Escapes a text for a regex.
- @escapeRegex = (text) ->
- return text.replace /[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"
- mapImports: (template) ->
- regex = /\(import ([^\)]+)\)/g
- matches = _.uniq(template.match(regex) || [ ])
- map = [ ]
- matches.forEach (match, i) =>
- random = i + "." + Math.round(Math.random() * 10000000000).toString()
- templateName = match.replace regex, "$1"
- map.push templateName: templateName, randomHash: random
- template = template.replace new RegExp(@::escapeRegex(match), 'g'), random
- { template: template, map: map }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement