<commit_before>class App.Setup
  constructor: (@opts) ->
    @_set_name_properties()
    @_set_self()
    @route ||= App[@constructor.name].route
    @route ||= "/" + @snake_name + "s"

    @opts ||= {}

    @attributes = {}
    template = @opts.template || App[@constructor.name].template

    @_set_opts_to_attributes()

    @uuid = @opts.uuid || @attributes.uuid || App.UUID.generate()
    @id = @opts.id || @attributes.id
    @target_uuid = @opts.target_uuid || @attributes.target_uuid

    @attributes["uuid"] = @uuid

    if template?
      @template = template.replace(/\b(data-k-uuid)\.?[^\s|>]+/g, "data-k-uuid=" + @uuid)
      @template = @template.replace(/\b(data-id)\.?[^\s|>]+/g, "data-id=" + @id)
      @_build_attrs_template()
      @_setup_interpolated_vars()

  @set_class_name: (class_name) ->
    @class_name = class_name
    @dash_name =  @_get_dash_name(class_name)
    @snake_name = @_get_snake_name(class_name)

  @_get_class_name: ->
    @name

  @_get_dash_name: (name) ->
    dash_str = name.replace /([A-Z])/g, ($1) ->
      "-" + $1.toLowerCase()
    dash_str[1 .. dash_str.length - 1]

  @_get_snake_name: (name) ->
    under_str = name.replace /([A-Z])/g, ($1) ->
      "_" + $1.toLowerCase()
    under_str[1 .. under_str.length - 1]

  _set_self: ->
    @_self = @

  _set_name_properties: =>
    @class_name ||= App[@constructor.name].class_name
    @dash_name =  App[@constructor.name]._get_dash_name(@class_name)
    @snake_name = App[@constructor.name].snake_name

  _build_attrs_template: ->
    $.each @attributes, (attr, val) =>
      j_attr = $(@template).find("[data-k-uuid='" + @uuid + "'][data-attr='" + attr + "']")
      clone = j_attr.clone()

      replace_string = clone.wrap('<span/>').parent().html()

      cloned_template = $(@template).clone()
      updated_template = $("<div />").append($(@template).clone()).html()

      if replace_string? && replace_string.length
        replace_regex = new RegExp(replace_string)

        new_attr_string = replace_string.replace(/\b(data-val)\.?[^\s]+/g, "data-val='" + val + "'")

        @template = updated_template.replace(replace_regex, new_attr_string)

  _setup_interpolated_vars: =>
    template_match = new RegExp(/{{([^{}]+)}}/g)

    new_template = @template.replace(template_match, (match, p1) =>
      class_name = match.split(".")[0].substr(2)
      attribute = match.split(".")[1].slice(0, - 2)

      if class_name == @snake_name && (typeof @get(attribute) != 'undefined')
        @get(attribute)
      else
        match
    )

    @template = new_template

  _set_opts_to_attributes: ->
    if @opts?
      $.each @opts, (key, val) =>
        @set key, val<commit_msg>Set routes in constructor allowing nested resources<commit_after>class App.Setup
  constructor: (@opts) ->
    @_set_name_properties()
    @_set_self()

    @opts ||= {}

    @attributes = {}
    template = @opts.template || App[@constructor.name].template

    @_set_opts_to_attributes()

    @_setup_route()

    @uuid = @opts.uuid || @attributes.uuid || App.UUID.generate()
    @id = @opts.id || @attributes.id
    @target_uuid = @opts.target_uuid || @attributes.target_uuid

    @attributes["uuid"] = @uuid

    if template?
      @template = template.replace(/\b(data-k-uuid)\.?[^\s|>]+/g, "data-k-uuid=" + @uuid)
      @template = @template.replace(/\b(data-id)\.?[^\s|>]+/g, "data-id=" + @id)
      @_build_attrs_template()
      @_setup_interpolated_vars()

  @set_class_name: (class_name) ->
    @class_name = class_name
    @dash_name =  @_get_dash_name(class_name)
    @snake_name = @_get_snake_name(class_name)

  @_get_class_name: ->
    @name

  @_get_dash_name: (name) ->
    dash_str = name.replace /([A-Z])/g, ($1) ->
      "-" + $1.toLowerCase()
    dash_str[1 .. dash_str.length - 1]

  @_get_snake_name: (name) ->
    under_str = name.replace /([A-Z])/g, ($1) ->
      "_" + $1.toLowerCase()
    under_str[1 .. under_str.length - 1]

  _set_self: ->
    @_self = @

  _set_name_properties: =>
    @class_name ||= App[@constructor.name].class_name
    @dash_name =  App[@constructor.name]._get_dash_name(@class_name)
    @snake_name = App[@constructor.name].snake_name

  _build_attrs_template: ->
    $.each @attributes, (attr, val) =>
      j_attr = $(@template).find("[data-k-uuid='" + @uuid + "'][data-attr='" + attr + "']")
      clone = j_attr.clone()

      replace_string = clone.wrap('<span/>').parent().html()

      cloned_template = $(@template).clone()
      updated_template = $("<div />").append($(@template).clone()).html()

      if replace_string? && replace_string.length
        replace_regex = new RegExp(replace_string)

        new_attr_string = replace_string.replace(/\b(data-val)\.?[^\s]+/g, "data-val='" + val + "'")

        @template = updated_template.replace(replace_regex, new_attr_string)

  _setup_interpolated_vars: =>
    template_match = new RegExp(/{{([^{}]+)}}/g)

    new_template = @template.replace(template_match, (match, p1) =>
      class_name = match.split(".")[0].substr(2)
      attribute = match.split(".")[1].slice(0, - 2)

      if class_name == @snake_name && (typeof @get(attribute) != 'undefined')
        @get(attribute)
      else
        match
    )

    @template = new_template

  _set_opts_to_attributes: ->
    if @opts?
      $.each @opts, (key, val) =>
        @set key, val

  _setup_route: =>
    url_match = new RegExp(/{{([^{}]+)}}/g)
    @route ||= App[@constructor.name].route
    @route ||= "/" + @snake_name + "s"
    @route = @route.replace(url_match, (match, p1) =>
      attribute = match.slice(2, - 2)
      @get(attribute)
    )
{'fraction_non_alphanumeric': 0.19239693021595575, 'fraction_numerical': 0.005532750312332679, 'mean_word_length': 3.0845481049562684, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, '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': '1776798', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1994, 'n_words': 310}