 _modules = {}
 _i18n = {}
 _sortedRoutes = []
+
+exports._replaceVariableHolder = (haystack, needle, replacement) ->
+  haystack.replace(new RegExp("\\$#{needle}([^\\w]+.*|)$", "g"), replacement+'$1')
+##replace(/\$module([^\w]+.*|)$/g, moduleName+'$1')
+exports._replaceModuleVariable = (str, moduleName, needle = 'module') ->
+  @_replaceVariableHolder(str, needle, moduleName)
+exports._replaceThemeVariable = (str, moduleName, needle = 'theme') ->
+  @_replaceVariableHolder(str, needle, moduleName)
+
 
 module.exports = (options = {}, app = null) ->
   exports.setOptions(options)


    # apply views
    viewFiles = glob.sync("#{moduleName}/#{options.viewFolderPattern}")
    views.push(path.dirname(viewFiles[0])) if viewFiles?.length > 0
    #app.set('views',path.dirname(viewFiles[0])) if viewFiles?.length > 0

    # mount to (parent/main) app
    if mountToApp
      mountpoint = if @getConfig()[moduleName]?.mountpoint then @getConfig()[moduleName]?.mountpoint else options.defaultMountpoint
      mountpoint = mountpoint.replace(/\$module([^\w]+.*|)$/g, moduleName+'$1')
      mainApp.use(mountpoint, app)

    views.push(path.dirname(templates[0])) if templates?.length > 0

    app.set('views', views)


  routesFile: 'routes.yml'
  codeFilePattern: 'code/**/*.@(coffee|js)'
  i18nFilePattern: 'i18n/**/*.@(yml|yaml)'
  viewFolderPattern: 'views/'#'views/*.@(jade)'
  themeFolder: 'themes'
  theme: ''
  defaultHTTPMethod: '*' # can be get|put|post|delete|patch|all|*(is for all)
  debug: true
  encoding: 'utf8'
