<commit_before>module MacrosHelper

  include PluginsHelper

  def macros_in_menu
    plugins_macros.reject{ |macro| macro.configuration[:icon_path] }
  end

  def macros_with_buttons
    plugins_macros.reject{ |macro| !macro.configuration[:icon_path] }
  end

  def macro_title(macro)
    macro.configuration[:title] || macro.name.humanize
  end

  def generate_macro_config_dialog(macro)
    if macro.configuration[:skip_dialog]
      "function(){#{macro_generator(macro)}}"
    else
      "function(){
        jQuery('<div>'+#{macro_configuration_dialog(macro).to_json}+'</div>').dialog({
          title: #{macro_title(macro).to_json},
          modal: true,
          buttons: {
            #{_('Ok').to_json}: function(){
              tinyMCE.activeEditor.execCommand('mceInsertContent', false,
              (function(dialog){ #{macro_generator(macro)} })(this));
              jQuery(this).dialog('close');
            },
            #{_('Cancel').to_json}: function(){
              jQuery(this).dialog('close');
            }
          }
        });
      }"
    end
  end

  def include_macro_js_files
    plugins_javascripts = []
    plugins_macros.map do |macro|
      if macro.configuration[:js_files]
        [macro.configuration[:js_files]].flatten.map { |js| plugins_javascripts << macro.plugin.public_path(js) }
      end
    end
    unless plugins_javascripts.empty?
      javascript_include_tag *plugins_javascripts
    end
  end

  def macro_css_files
    plugins_css = []
    plugins_macros.map do |macro|
      if macro.configuration[:css_files]
        [macro.configuration[:css_files]].flatten.map { |css| plugins_css << macro.plugin.public_path(css) }
      end
    end
    plugins_css.join(',')
  end

  protected

  def macro_generator(macro)
    if macro.configuration[:generator]
      if macro.configuration[:generator].respond_to?(:call)
        macro.configuration[:generator].call(macro)
      else
        macro.configuration[:generator]
      end
    else
      macro_default_generator(macro)
    end

  end
<commit_msg>macros: revert plugins dispatch<commit_after>module MacrosHelper

  include PluginsHelper

  def macros_in_menu
    @plugins.dispatch(:macros).reject{ |macro| macro.configuration[:icon_path] }
  end

  def macros_with_buttons
    @plugins.dispatch(:macros).reject{ |macro| !macro.configuration[:icon_path] }
  end

  def macro_title(macro)
    macro.configuration[:title] || macro.name.humanize
  end

  def generate_macro_config_dialog(macro)
    if macro.configuration[:skip_dialog]
      "function(){#{macro_generator(macro)}}"
    else
      "function(){
        jQuery('<div>'+#{macro_configuration_dialog(macro).to_json}+'</div>').dialog({
          title: #{macro_title(macro).to_json},
          modal: true,
          buttons: {
            #{_('Ok').to_json}: function(){
              tinyMCE.activeEditor.execCommand('mceInsertContent', false,
              (function(dialog){ #{macro_generator(macro)} })(this));
              jQuery(this).dialog('close');
            },
            #{_('Cancel').to_json}: function(){
              jQuery(this).dialog('close');
            }
          }
        });
      }"
    end
  end

  def include_macro_js_files
    plugins_javascripts = []
    @plugins.dispatch(:macros).map do |macro|
      if macro.configuration[:js_files]
        [macro.configuration[:js_files]].flatten.map { |js| plugins_javascripts << macro.plugin.public_path(js) }
      end
    end
    unless plugins_javascripts.empty?
      javascript_include_tag *plugins_javascripts
    end
  end

  def macro_css_files
    plugins_css = []
    @plugins.dispatch(:macros).map do |macro|
      if macro.configuration[:css_files]
        [macro.configuration[:css_files]].flatten.map { |css| plugins_css << macro.plugin.public_path(css) }
      end
    end
    plugins_css.join(',')
  end

  protected

  def macro_generator(macro)
    if macro.configuration[:generator]
      if macro.configuration[:generator].respond_to?(:call)
        macro.configuration[:generator].call(macro)
      else
        macro.configuration[:generator]
      end
    else
      macro_default_generator(macro)
    end

  end

{'fraction_non_alphanumeric': 0.12511961722488038, 'fraction_numerical': 0.0, 'mean_word_length': 2.87847866419295, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3192954', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1221, 'n_words': 199}