<commit_before>$ = jQuery

assign = (node, attribute, value) ->
  if attribute
    node.attr attribute, value
  else
    children = node.children().detach()
    node.text value
    node.append(children)

select = (object, fn) ->
  result = {}
  for key, value of object
    (result[key] = value) if fn key, value
  result

$.fn.render = (data) ->
  context  = if $.isArray(data) then this.children().first() else this
  template = context.clone()
  data     = [data] unless $.isArray(data)

  # Iterate over the list of objects
  for object in data
    values  = select(object, (key, value) -> typeof value == "string")
    objects = select(object, (key, value) -> typeof value == "object"  && not $.isArray(value))
    lists   = select(object, (key, value) -> $.isArray(value) )
    result  = template.clone()

    for key, value of values
      [klass, attribute] = key.split('@')
      assign result, attribute, value if result.hasClass klass
      result.find(".#{klass}").each ->
        assign $(this), attribute, value

    for key, value of lists
      result.find(".#{key}").render(value)

    for key, value of objects
      result.find(".#{key}").render(value)

    # Add rendered template to dom
    context.before(result)

  return context.remove() # Remove the original template from dom















<commit_msg>No need to separate between child objects and lists anymore<commit_after>$ = jQuery

assign = (node, attribute, value) ->
  if attribute
    node.attr attribute, value
  else
    children = node.children().detach()
    node.text value
    node.append(children)

select = (object, fn) ->
  result = {}
  for key, value of object
    (result[key] = value) if fn key, value
  result

$.fn.render = (data) ->
  context  = if $.isArray(data) then this.children().first() else this
  template = context.clone()
  data     = [data] unless $.isArray(data)

  for object in data
    values  = select(object, (key, value) -> typeof value == "string")
    objects = select(object, (key, value) -> typeof value == "object")
    result  = template.clone()

    for key, value of values
      [klass, attribute] = key.split('@')
      assign result, attribute, value if result.hasClass klass
      result.find(".#{klass}").each ->
        assign $(this), attribute, value

    for key, value of objects
      result.find(".#{key}").render(value)

    # Add rendered template to dom
    context.before(result)

  return context.remove() # Remove the original template from dom

{'fraction_non_alphanumeric': 0.13608992372541148, 'fraction_numerical': 0.0, 'mean_word_length': 2.9618441971383147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '89995', 'n_tokens_mistral': 728, 'n_tokens_neox': 731, 'n_words': 244}