<commit_before>require 'omf_base/lobject'


module LabWiki
  module Plugin; end # Put all plugins under this module

  class PluginManager < OMF::Base::LObject
    @@plugins = {}
    @@plugins_for_col = { plan: [], prepare: [], execute: []}

    def self.init
      info "INITIALIZING PLUGINS"
      require 'labwiki/plugins/experiment/init'
      require 'labwiki/plugins/source_edit/init'
      require 'labwiki/plugins/plan_text/init'
    end

    #
    # description:
    #  - widget
    #  - renderer
    #
    def self.register name, description
      info "Loading plugin '#{name}'"
      name = name.to_sym
      if @@plugins[name]
        warn "Plugin '#{name}' is already registered. Overiding previous settings"
      end
      description[:name] = name
      @@plugins[name] = description
      (description[:widgets] || {}).each do |wdescr|
        # :context => :execute,
        # :priority => lambda(),
        # :widget_class => Class
        wdescr[:config_name] ||= name
        if ctxt = @@plugins_for_col[wdescr[:context]]
          ctxt << wdescr
        else
          warn "Ignoring plugin '#{name} for context '#{wdescr[:context]}'"<commit_msg>Dynamically loading plugins from configuration file<commit_after>require 'omf_base/lobject'
require 'omf_web'
require 'omf-web/theme'

module LabWiki
  module Plugin; end # Put all plugins under this module

  class PluginManager < OMF::Base::LObject
    @@plugins = {}
    @@plugins_for_col = { plan: [], prepare: [], execute: []}

    def self.init
      info "INITIALIZING PLUGINS"
      require 'labwiki/plugin/source_edit/init'
      require 'labwiki/plugin/plan_text/init'

      LabWiki::Configurator[:plugins].each do |name, opts|
        #puts ">>> #{name} ::: #{opts}"
        if plugin_dir = opts.delete(:plugin_dir)
          lib_dir = File.expand_path(File.join(plugin_dir, 'lib'))
          unless File.readable? lib_dir
            error "Can't find lib directory '#{lib_dir}' for plugin '#{name}'"
            next
          end
          $: << lib_dir
          require "labwiki/plugin/#{name}/init"
        end
      end
    end

    #
    # description:
    #  - widget
    #  - renderer
    #
    def self.register name, description
      info "Loading plugin '#{name}'"
      name = name.to_sym
      if @@plugins[name]
        warn "Plugin '#{name}' is already registered. Overiding previous settings"
      end
      description[:name] = name
      @@plugins[name] = description
      (description[:widgets] || {}).each do |wdescr|
        # :context => :execute,
        # :priority => lambda(),
        # :widget_class => Class
        wdescr[:config_name] ||= name
        if ctxt = @@plugins_for_col[wdescr[:context]]
          ctxt << wdescr
        else
          warn "Ignoring plugin '#{name} for context '#{wdescr[:context]}'"
{'fraction_non_alphanumeric': 0.13052706048815, 'fraction_numerical': 0.0, 'mean_word_length': 2.5043370508054523, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '493646', 'n_tokens_mistral': 872, 'n_tokens_neox': 846, 'n_words': 212}