       "#{escaped}_v#{version}"
     else
       escaped
-  makeDOM: ->
+  makeDOM: -> runWithRender @, => runWithContext (new Context @), =>
     ###
     Main rendering engine, returning an xmldom object for the whole document.
     Also saves the table of tiles in `@tiles`, the corresponding

class Styles extends ArrayWrapper
  @itemClass: Style

getMapping = ->
  ## Returns current `Mapping` object,
  ## when used at top level of a JS/CS mapping file.
  currentMapping
runWithMapping = (mapping, fn) ->
  ## Runs the specified function `fn` as if it were called
  ## at the top level of the specified mapping.
  oldMapping = currentMapping
  currentMapping = mapping
  try
    fn()
  finally
    currentMapping = oldMapping

beforeRender = (fn) ->
  unless currentMapping?
    throw new SVGTilerError "svgtiler.beforeRender called outside mapping file"
  currentMapping.beforeRender fn
afterRender = (fn) ->
  unless currentMapping?
    throw new SVGTilerError "svgtiler.afterRender called outside mapping file"
  currentMapping.afterRender fn

class Mapping extends Input
  ###
  Base Mapping class.

  Style, CSSStyle, StylusStyle,
  SVGFile,
  extensionMap, Input, DummyInput, ArrayWrapper, Mappings,
  Render, getRender, runWithRender, beforeRender, afterRender,
  Context, getContext, runWithContext,
  SVGTilerError, SVGNS, XLINKNS, escapeId,
  main, renderDOM, defaultSettings, convert,
