<commit_before>{View} = require 'atom-space-pen-views'
ContextVariableListView = require './context-variable-list-view'

module.exports =
class ContextView extends View

  @content: =>
    @div =>
      @span outlet: 'contextListView'

  initialize: (@context,@autoopen) ->
    @render()

  render: ->
    if @context.context
      openChildren = false
      if @autoopen?
        for open in @autoopen
          if (open.indexOf(@context.name) == 0)
            openChildren = true
            break

      @contextListView.append(new ContextVariableListView( {name: @context.name, summary: null, variables: @context.context.variables, autoopen: openChildren, openpaths:@autoopen, parent:null}))<commit_msg>cherry picked array object sort<commit_after>{View} = require 'atom-space-pen-views'
ContextVariableListView = require './context-variable-list-view'

module.exports =
class ContextView extends View

  @content: =>
    @div =>
      @span outlet: 'contextListView'

  initialize: (@context,@autoopen) ->
    @render()

  render: ->
    if @context.context
      openChildren = false
      if @autoopen?
        for open in @autoopen
          if (open.indexOf(@context.name) == 0)
            openChildren = true
            break

      cbDeepNaturalSort = (a,b) ->
        aIsNumeric = /^\d+$/.test(a.name)
        bIsNumeric = /^\d+$/.test(b.name)
        # cannot exist two equal keys, so skip case of returning 0
        if aIsNumeric && bIsNumeric # order numbers
          return if (parseInt(a.name, 10) < parseInt(b.name, 10)) then -1 else 1
        else if !aIsNumeric && !bIsNumeric # order strings
          return if (a.name < b.name) then -1 else 1
        else # string first (same behavior that PHP's `ksort`)
          return if aIsNumeric then 1 else -1

      fnWalkVar = (contextVar) ->
        if Array.isArray(contextVar)
          for item in contextVar
            if Array.isArray(item.value)
              fnWalkVar(item.value)
          contextVar.sort(cbDeepNaturalSort)

      fnWalkVar(@context.context.variables)
      @contextListView.append(new ContextVariableListView( {name: @context.name, summary: null, variables: @context.context.variables, autoopen: openChildren, openpaths:@autoopen, parent:null}))
{'fraction_non_alphanumeric': 0.1157613535173642, 'fraction_numerical': 0.00578806767586821, 'mean_word_length': 2.7512520868113524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '2990673', 'n_tokens_mistral': 675, 'n_tokens_neox': 641, 'n_words': 174}