<commit_before># Orchestra adaptation of the jQuery templateLoader plugin found at
# https://github.com/Gazler/Underscore-Template-Loader

do ->
  templateLoader =

    templates: {}
    templateVersion: undefined
    environment: undefined

    init: (templateVersion, environment) ->
      @templateVersion = templateVersion
      @environment = environment

      if @isAvailableLocalStorage
        storageTemplateVersion = localStorage.getItem 'templateVersion'

        if storageTemplateVersion and storageTemplateVersion == @templateVersion
          templates = localStorage.getItem 'templates-' + @environment

          if templates
            templates = JSON.parse templates
            for language of templates
              if !@templates[language]
                @addLanguage language
              for templateName of templates[language]
                if !@templates[language][templateName]
                  @addTemplate templateName, language, templates[language][templateName]
        else
          localStorage.removeItem 'templates-' + @environment
          localStorage.removeItem 'templateVersion'
      return

    loadRemoteTemplate: (templateName, language, view) ->
      if !@templates[language]
        @addLanguage language
      if !@templates[language][templateName]
        templateLoader = this
        filename = appRouter.generateUrl('loadUnderscoreTemplate')
        jQuery.ajax {
          method: "GET"
          url: filename
          data: { 'language': language,'templateId': templateName }
          success: (tpl, textStatus, xhr) ->
              templateLoader.addTemplate templateName, language, tpl
              templateLoader.storeTemplates
              view.onTemplateLoaded templateName, tpl
              return
        }
      else
        view.onTemplateLoaded templateName, @templates[language][templateName]
      return

    addTemplate: (templateName, language, tpl) ->
      if !@templates[language]
        @addLanguage language
      @templates[language][templateName] = tpl
      return

    addLanguage: (language) ->
      @templates[language] = {}
      return

    isAvailableLocalStorage: ->
      try
        return 'localStorage' of window and window['localStorage'] != null<commit_msg>add constraint on http code 200<commit_after># Orchestra adaptation of the jQuery templateLoader plugin found at
# https://github.com/Gazler/Underscore-Template-Loader

do ->
  templateLoader =

    templates: {}
    templateVersion: undefined
    environment: undefined

    init: (templateVersion, environment) ->
      @templateVersion = templateVersion
      @environment = environment

      if @isAvailableLocalStorage
        storageTemplateVersion = localStorage.getItem 'templateVersion'

        if storageTemplateVersion and storageTemplateVersion == @templateVersion
          templates = localStorage.getItem 'templates-' + @environment

          if templates
            templates = JSON.parse templates
            for language of templates
              if !@templates[language]
                @addLanguage language
              for templateName of templates[language]
                if !@templates[language][templateName]
                  @addTemplate templateName, language, templates[language][templateName]
        else
          localStorage.removeItem 'templates-' + @environment
          localStorage.removeItem 'templateVersion'
      return

    loadRemoteTemplate: (templateName, language, view) ->
      if !@templates[language]
        @addLanguage language
      if !@templates[language][templateName]
        templateLoader = this
        filename = appRouter.generateUrl('loadUnderscoreTemplate')
        jQuery.ajax {
          method: "GET"
          url: filename
          data: { 'language': language,'templateId': templateName }
          success: (tpl, textStatus, xhr) ->
            if 200 == xhr.status
              templateLoader.addTemplate templateName, language, tpl
              templateLoader.storeTemplates
            view.onTemplateLoaded templateName, tpl
            return
        }
      else
        view.onTemplateLoaded templateName, @templates[language][templateName]
      return

    addTemplate: (templateName, language, tpl) ->
      if !@templates[language]
        @addLanguage language
      @templates[language][templateName] = tpl
      return

    addLanguage: (language) ->
      @templates[language] = {}
      return

    isAvailableLocalStorage: ->
      try
        return 'localStorage' of window and window['localStorage'] != null
{'fraction_non_alphanumeric': 0.07883817427385892, 'fraction_numerical': 0.001310329766324525, 'mean_word_length': 2.5149654643131236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1374767', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1042, 'n_words': 275}