<commit_before># LessAssets helper methods to render less css.
#
class window.LessAssets

  # Render less css with its variables to plain css
  #
  # @param [String] css the less css
  # @param [Object] variables the less variables
  # @param [HTMLDocument] element a target element to add the styles
  # @return [String] the css styles
  #
  @render: (name, css, variables = {}, doc = undefined) ->
    result = undefined
    newVariables = {}

    # Replace existing less variables
    #
    for variable, value of variables
      existing = ///@#{ variable }:\s*[^;]+;///

      if existing.test css
        css = css.replace existing, "@#{ variable }: #{ value };"
      else
        newVariables[variable] = value

    # Add bew less variables
    #
    style = ''
    style += "@#{ variable }: #{ value };\n" for variable, value of newVariables
    style += css

    # Compile the less stylesheet
    #
    less.Parser().parse style, (err, tree) ->
      throw err if err

      result = tree.toCSS()

    # Add a style tag with the css when a document is given
    #
    if doc instanceof HTMLDocument || Object.prototype.toString.call(doc) is '[object HTMLDocument]'
      id = "less_asset_#{ name.replace(/[^A-Za-z0-1_/-]/, '').replace(/[/-]/, '_') }"

      style = doc.getElementById(id) || doc.createElement 'style'
      style.type = 'text/css'
      style.id = id

      rules = doc.createTextNode result

      if style.styleSheet
        style.styleSheet.cssText = rules.nodeValue
      else
        while style.hasChildNodes()
          style.removeChild style.lastChild

        style.appendChild rules

      head = doc.getElementsByTagName('head')[0]
      head.appendChild style

    result<commit_msg>Don't add existing style tag again.<commit_after># LessAssets helper methods to render less css.
#
class window.LessAssets

  # Render less css with its variables to plain css
  #
  # @param [String] css the less css
  # @param [Object] variables the less variables
  # @param [HTMLDocument] element a target element to add the styles
  # @return [String] the css styles
  #
  @render: (name, css, variables = {}, doc = undefined) ->
    result = undefined
    newVariables = {}

    # Replace existing less variables
    #
    for variable, value of variables
      existing = ///@#{ variable }:\s*[^;]+;///

      if existing.test css
        css = css.replace existing, "@#{ variable }: #{ value };"
      else
        newVariables[variable] = value

    # Add bew less variables
    #
    style = ''
    style += "@#{ variable }: #{ value };\n" for variable, value of newVariables
    style += css

    # Compile the less stylesheet
    #
    less.Parser().parse style, (err, tree) ->
      throw err if err

      result = tree.toCSS()

    # Add a style tag with the css when a document is given
    #
    if doc instanceof HTMLDocument || Object.prototype.toString.call(doc) is '[object HTMLDocument]'
      id = "less_asset_#{ name.replace(/[^A-Za-z0-1_/-]/, '').replace(/[/-]/, '_') }"

      style = doc.getElementById(id) || doc.createElement 'style'
      style.type = 'text/css'
      style.id = id

      rules = doc.createTextNode result

      if style.styleSheet
        style.styleSheet.cssText = rules.nodeValue
      else
        while style.hasChildNodes()
          style.removeChild style.lastChild

        style.appendChild rules

      unless doc.getElementById(id)
        head = doc.getElementsByTagName('head')[0]
        head.appendChild style

    result
{'fraction_non_alphanumeric': 0.11944127708095781, 'fraction_numerical': 0.0017103762827822121, 'mean_word_length': 2.5160320641282565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5621262', 'n_tokens_mistral': 1025, 'n_tokens_neox': 993, 'n_words': 324}