<commit_before>import {readFileSync} from 'fs'
import textfit from 'textfit'
import ellipsis from 'html-ellipsis'

export default function eeTile(module) {
  module.directive('eeTile', directive)
}

if ('angular' in global) {
  eeTile(angular.module('eeTile', []))
}

export function directive($timeout) {
  return {
    scope: {
      options: '&'
    },
    restrict: 'E',
    controller: ctrl,
    controllerAs: 'ctrl',
    template: readFileSync(__dirname + '/template.html', 'utf8'),
    link: function(scope, element) {
      let options = scope.options
      if (options.fitText !== false) {
        $timeout(function() {
          let el = element[0].querySelector('.ee-tile-content')
          let settings = {
            minFontSize: 10,
            maxFontSize: 100
          }
          textfit(el, settings)
        })
      }
      if (options.ellipsis !== false) {
        let count = 150
        if ('number' === typeof scope.options.ellipsis) {
          count = scope.options.ellipsis
        }
        $timeout(function() {
          let content = element[0].querySelector('.ee-tile-content')
          let html = content.innerHTML
          let ellipsed = ellipsis(html, count)
          if (ellipsed.length < html.length)  {
            content.innerHTML = ellipsed
          }
        })
      }
    }
  }
}

export function ctrl($scope, $element) {
  let options = this.options = $scope.options()

  this.mainStyle = getMainStyles(options)
  this.barStyle = getBarStyles(options)
  this.barRendered = options.bar !== false
}

export function getMainStyles(options = {}) {
  let background = options.background
  let image = options.image
  let styles = {}

  if (typeof image === 'string') {
    styles.backgroundImage = `url(${ image })`
    styles.backgroundSize = 'cover'
  }

  if (typeof background === 'string') {
    styles.background = background
  }

  return styles
}

export function getBarStyles(options = {}) {
  let background = options.bar

  if ('string' !== typeof background) {
    return {}
  }
  return {
    background: background
  }
}
<commit_msg>refactor(es6): extract link method<commit_after>import {readFileSync} from 'fs'
import textfit from 'textfit'
import ellipsis from 'html-ellipsis'

export default function eeTile(module) {
  module.directive('eeTile', directive)
}

if ('angular' in global) {
  eeTile(angular.module('eeTile', []))
}

export function directive($timeout) {
  function link(scope, element) {
    let options = scope.options
    if (options.fitText !== false) {
      $timeout(() => {
        let el = element[0].querySelector('.ee-tile-content')
        let settings = {
          minFontSize: 10,
          maxFontSize: 100
        }
        textfit(el, settings)
      })
    }
    if (options.ellipsis === false) return
    let count = 150
    if (typeof scope.options.ellipsis === 'number') {
      count = scope.options.ellipsis
    }
    $timeout(() => {
      let content = element[0].querySelector('.ee-tile-content')
      let html = content.innerHTML
      let ellipsed = ellipsis(html, count)
      if (ellipsed.length < html.length)  {
        content.innerHTML = ellipsed
      }
    })
  }

  return {
    scope: {
      options: '&'
    },
    restrict: 'E',
    controller: ctrl,
    controllerAs: 'ctrl',
    template: readFileSync(__dirname + '/template.html', 'utf8'),
    link: link
  }
}

export function ctrl($scope, $element) {
  let options = this.options = $scope.options()

  this.mainStyle = getMainStyles(options)
  this.barStyle = getBarStyles(options)
  this.barRendered = options.bar !== false
}

export function getMainStyles(options = {}) {
  let background = options.background
  let image = options.image
  let styles = {}

  if (typeof image === 'string') {
    styles.backgroundImage = `url(${ image })`
    styles.backgroundSize = 'cover'
  }

  if (typeof background === 'string') {
    styles.background = background
  }

  return styles
}

export function getBarStyles(options = {}) {
  let background = options.bar

  if (typeof background !== 'string') {
    return {}
  }
  return {
    background: background
  }
}

{'fraction_non_alphanumeric': 0.13276904474002418, 'fraction_numerical': 0.005562273276904474, 'mean_word_length': 2.699463327370304, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1934892', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1253, 'n_words': 296}