Sha256: 88f12786d025dd01b94329302dcca1d22446c9cc279e30c27834efed5dab884c

Contents?: true

Size: 1.79 KB

Versions: 13

Compression:

Stored size: 1.79 KB

Contents

# encoding: utf-8

module Slideshow

module PluginHelper

  def find_plugin_patterns
    patterns = []

    ###
    #  todo/fix: only include rb files listed in plugin manifests!
    #  - for now load all ruby files in plugins folder

    patterns << "#{config.config_dir}/plugins/**/*.rb"

    ######
    # also allow "ad-hoc" plugins e.g. no manifest required (not installed)
    #   just ruby scripts in lib in config folder or working folder

    patterns << "#{config.config_dir}/lib/**/*.rb"

    #########
    #  todo/fix: only include rb files listed in plugin manifest (see above!)

    patterns << 'plugins/**/*.rb'

    patterns << 'lib/**/*.rb' unless Slideshow.root == File.expand_path( '.' )  # don't include lib if we are in repo (don't include slideshow/lib)    
    patterns
  end

  def find_plugins
    patterns = find_plugin_patterns

    plugins=[]
    patterns.each do |pattern|
      pattern.gsub!( '\\', '/')  # normalize path; make sure all path use / only
      Dir.glob( pattern ) do |plugin|
        plugins << plugin
      end
    end
    plugins
  end

  def load_plugins
    patterns = find_plugin_patterns
  
    patterns.each do |pattern|
      pattern.gsub!( '\\', '/')  # normalize path; make sure all path use / only
      Dir.glob( pattern ) do |plugin|
        begin
          ## NB: use full_path - since Ruby 1.9.2 - ./ no longer included in load path for security
          plugin_fullpath = File.expand_path( plugin )  # nb: will use Dir.pwd (e.g. ./) as second arg
          puts "Loading plugins in '#{plugin}' (#{plugin_fullpath})..."
          require( plugin_fullpath )
        rescue Exception => e
          puts "** error: failed loading plugins in '#{plugin}': #{e}"
        end
      end
    end
  end  # method load_plugins


end # module PluginHelper
end # module Slideshow

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
slideshow-models-4.1.0 lib/slideshow/plugin_helpers.rb
slideshow-models-4.0.1 lib/slideshow/plugin_helpers.rb
slideshow-models-4.0.0 lib/slideshow/plugin_helpers.rb
slideshow-models-3.3.1 lib/slideshow/plugin_helpers.rb
slideshow-models-3.3.0 lib/slideshow/plugin_helpers.rb
slideshow-models-3.2.0 lib/slideshow/plugin_helpers.rb
slideshow-models-3.1.1 lib/slideshow/plugin_helpers.rb
slideshow-models-3.1.0 lib/slideshow/plugin_helpers.rb
slideshow-models-3.0.2 lib/slideshow/plugin_helpers.rb
slideshow-models-3.0.1 lib/slideshow/plugin_helpers.rb
slideshow-models-3.0.0 lib/slideshow/plugin_helpers.rb
slideshow-models-2.5.0 lib/slideshow/plugin_helpers.rb
slideshow-models-2.4.0 lib/slideshow/plugin_helpers.rb