<commit_before>var Arkansas = require('./')
  , Model = require('./model')
  , utils = require('./utils')

var Fragment = module.exports = function(id, template, context) {
  this.id = id
  this.template = template
  this.context = context
  this.children = []
  this.parent = null
}
  
utils.eventify(Fragment)
require('./implode').register('Fragment', Fragment, ['id', 'template', 'context', 'events', 'parent', 'children'])

Fragment.prototype.observe = function(model, property) {
  if (this.silent) return
  var event = 'changed' + (property ? '.' + property : '')
  model.on(event, this, 'refresh')
  this.once('delete', model, 'off', model, event, this)
}

Fragment.prototype.render = function() {
  this.template.fn.fragment = this
  return this.template.fn(this.context)
}

Fragment.queue = []
Fragment.queue.push = function(fragment) {
  Array.prototype.push.call(Fragment.queue, fragment)
}
Fragment.refresh = function() {
  if (Fragment.queue.length === 0) return
  var fragment
  while ((fragment = Fragment.queue.shift()))
    fragment.refresh(true)
}

Fragment.prototype.refresh = function(force) {
  if (utils.isServer) return
  if (!force && Fragment.queue.indexOf(this) === -1) {
    Fragment.queue.push(this)
    setTimeout(Fragment.refresh)
    return
  }
  utils.debug('[Fragment] #%s refreshing', this.id)
  var that = this
  // delete Contents
  this.deleteContents()
  // initialize DOMFragment and an empty DIV 
  var DOMFragment = document.createDocumentFragment()
    , tmp = document.createElement('div')
    , child
  // render the fragment into the DIV
  tmp.innerHTML = this.render()
  // to transfer its content to the DOMFragment afterwards
  while ((child = tmp.firstChild)) {<commit_msg>fix fragment#render to support tr and td fragments<commit_after>var Arkansas = require('./')
  , Model = require('./model')
  , utils = require('./utils')

var Fragment = module.exports = function(id, template, context) {
  this.id = id
  this.template = template
  this.context = context
  this.children = []
  this.parent = null
}
  
utils.eventify(Fragment)
require('./implode').register('Fragment', Fragment, ['id', 'template', 'context', 'events', 'parent', 'children'])

Fragment.prototype.observe = function(model, property) {
  if (this.silent) return
  var event = 'changed' + (property ? '.' + property : '')
  model.on(event, this, 'refresh')
  this.once('delete', model, 'off', model, event, this)
}

Fragment.prototype.render = function() {
  this.template.fn.fragment = this
  return this.template.fn(this.context)
}

Fragment.queue = []
Fragment.queue.push = function(fragment) {
  Array.prototype.push.call(Fragment.queue, fragment)
}
Fragment.refresh = function() {
  if (Fragment.queue.length === 0) return
  var fragment
  while ((fragment = Fragment.queue.shift()))
    fragment.refresh(true)
}

Fragment.prototype.refresh = function(force) {
  if (utils.isServer) return
  if (!force && Fragment.queue.indexOf(this) === -1) {
    Fragment.queue.push(this)
    setTimeout(Fragment.refresh)
    return
  }
  utils.debug('[Fragment] #%s refreshing', this.id)
  var that = this
  // delete Contents
  this.deleteContents()
  // initialize DOMFragment and an empty DIV 
  var DOMFragment = document.createDocumentFragment()
  // render the fragment
  var rendered = this.render()
    , reg = rendered.match(/^[^<]*<([a-z]+)/i)
    , tmp, child
  switch (reg[1]) {
    case 'tr': tmp = document.createElement('tbody'); break
    case 'td': tmp = document.createElement('tr'); break
    default: tmp = document.createElement('div')
  }
  tmp.innerHTML = rendered
  // to transfer its content to the DOMFragment afterwards
  while ((child = tmp.firstChild)) {
{'fraction_non_alphanumeric': 0.15565782349756363, 'fraction_numerical': 0.0013535462912831618, 'mean_word_length': 3.9797843665768196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1251663', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1099, 'n_words': 277}