<commit_before># frozen_string_literal: true

module ElmHelper
  def elm_component(name, props = {}, options = {}, &block)
    options = { tag: options } if options.is_a?(Symbol)

    html_options = options.reverse_merge(data: {})
    html_tag = html_options[:tag] || :div

    # remove internally used properties so they aren't rendered to DOM
    html_options.except!(:tag)
    id = [name, rand(10_000_000)].join('-')
    html_options[:id] = id

    html = content_tag(html_tag, '', html_options, false, &block)
    html << elm_js_tag(name, props)
  end

  def elm_js_tag(name, props)
    if (flags = props[:flags])
      javascript_tag("window.Elm.#{name}.init({ node: document.getElementById('#{id}'), flags: #{flags.to_json} })")
    else
      javascript_tag("window.Elm.#{name}.init({ node: document.getElementById('#{id}') })")<commit_msg>Fix elm helper<commit_after># frozen_string_literal: true

module ElmHelper
  def elm_component(name, props = {}, options = {}, &block)
    options = { tag: options } if options.is_a?(Symbol)

    html_options = options.reverse_merge(data: {})
    html_tag = html_options[:tag] || :div

    # remove internally used properties so they aren't rendered to DOM
    html_options.except!(:tag)
    id = [name, rand(10_000_000)].join('-')
    html_options[:id] = id

    html = content_tag(html_tag, '', html_options, false, &block)
    html << elm_js_tag(id, name, props)
  end

  def elm_js_tag(id, name, props)
    if (flags = props[:flags])
      javascript_tag("window.Elm.#{name}.init({ node: document.getElementById('#{id}'), flags: #{flags.to_json} })")
    else
      javascript_tag("window.Elm.#{name}.init({ node: document.getElementById('#{id}') })")
{'fraction_non_alphanumeric': 0.1632413388138579, 'fraction_numerical': 0.009395184967704051, 'mean_word_length': 4.243076923076923, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6926930', 'n_tokens_mistral': 590, 'n_tokens_neox': 565, 'n_words': 124}