<commit_before>_.def("Luca.components.TableView").extends("Luca.components.CollectionView").with
  additionalClassNames: "table"
  tagName: "table"
  bodyTemplate: "table_view"
  bodyTagName: "tbody"
  bodyClassName: "table-body"
  itemTagName: "tr"
  stateful: true
  observeChanges: true

  columns:[]

  emptyText: "There are no results to display"

  itemRenderer: (item, model)->
    Luca.components.TableView.rowRenderer.call(@, item, model)

  emptyResults: ()->
    @$('tbody').append("<tr><td colspan=#{ @columns.length }>#{ @emptyText }</td></tr>")

  initialize: (@options={})->
    Luca.components.CollectionView::initialize.apply(@, arguments)
    @defer ()=> 
      Luca.components.TableView.renderHeader.call(@, @columns, @$('thead') )
      # TEMP
      # This is a result of the @additionalClassNames inheritance bug
      @$el.removeClass('row-fluid')
    .until("before:render")


make = Backbone.View::make

Luca.components.TableView.renderHeader = (columns, targetElement)->
  index = 0

  content = for column in columns
    "<th data-col-index='#{ index }'>#{ column.header }</th>"

  $( targetElement ).append(make "tr",{}, content)

  index = 0

  for column in columns when column.width?
    @$("th[data-col-index='#{ index }']",targetElement).css('width', column.width)


Luca.components.TableView.rowRenderer = (item, model, index)->
  for columnConfig in @columns
    Luca.components.TableView.renderColumn.call(@, columnConfig, item, model, index) 

Luca.components.TableView.renderColumn = (column, item, model, index)->
  cellValue = model.read( column.reader )
  make("td", {}, cellValue)
<commit_msg>adds ability to pass a custom renderer function<commit_after>_.def("Luca.components.TableView").extends("Luca.components.CollectionView").with
  additionalClassNames: "table"
  tagName: "table"
  bodyTemplate: "table_view"
  bodyTagName: "tbody"
  bodyClassName: "table-body"
  itemTagName: "tr"
  stateful: true
  observeChanges: true

  columns:[]

  emptyText: "There are no results to display"

  itemRenderer: (item, model)->
    Luca.components.TableView.rowRenderer.call(@, item, model)

  emptyResults: ()->
    @$('tbody').append("<tr><td colspan=#{ @columns.length }>#{ @emptyText }</td></tr>")

  initialize: (@options={})->
    Luca.components.CollectionView::initialize.apply(@, arguments)
    @defer ()=> 
      Luca.components.TableView.renderHeader.call(@, @columns, @$('thead') )
      # TEMP
      # This is a result of the @additionalClassNames inheritance bug
      @$el.removeClass('row-fluid')
    .until("before:render")


make = Backbone.View::make

Luca.components.TableView.renderHeader = (columns, targetElement)->
  index = 0

  content = for column in columns
    "<th data-col-index='#{ index }'>#{ column.header }</th>"

  $( targetElement ).append(make "tr",{}, content)

  index = 0

  for column in columns when column.width?
    @$("th[data-col-index='#{ index }']",targetElement).css('width', column.width)


Luca.components.TableView.rowRenderer = (item, model, index)->
  for columnConfig in @columns
    Luca.components.TableView.renderColumn.call(@, columnConfig, item, model, index) 

Luca.components.TableView.renderColumn = (column, item, model, index)->
  cellValue = model.read( column.reader )

  if _.isFunction( column.renderer )
    cellValue = column.renderer.call @, cellValue, model, column 

  make("td", {}, cellValue)

{'fraction_non_alphanumeric': 0.16231288523627824, 'fraction_numerical': 0.001174053419430584, 'mean_word_length': 4.325, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, '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': '2741673', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1068, 'n_words': 241}