Sha256: d4493ac46345aa0e4b7606a66320dc0163a5e728fe387dd41b8a0385883e20ab

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

# - keep track of plugins in Rails.plugins
# - allow engines to ship their own vendor/plugins
# - add observers to plugin.app_paths
# - add an alias to register_[asset]_expansion to plugins
Rails::Configuration.class_eval do
  def default_plugin_loader
    Rails::Plugin::RegisteringLoader
  end
  
  def default_plugin_locators
    locators = []
    locators << Rails::Plugin::GemLocator if defined? Gem
    locators << Rails::Plugin::NestedFileSystemLocator
  end
end

module Rails
  class << self
    def plugins
      @@plugins ||= ActiveSupport::OrderedHash.new
    end
  
    def plugin?(name)
      plugins.keys.include?(name.to_sym)
    end
  end

  class Plugin
    class RegisteringLoader < Rails::Plugin::Loader # ummm, what's a better name?
      def register_plugin_as_loaded(plugin)
        Rails.plugins[plugin.name.to_sym] = plugin
        super
      end
    end
  
    def app_paths
      ['models', 'helpers', 'observers'].map { |path| File.join(directory, 'app', path) } << controller_path << metal_path
    end
  
    def register_javascript_expansion(*args)
      ActionView::Helpers::AssetTagHelper.register_javascript_expansion *args
    end
  
    def register_stylesheet_expansion(*args)
      ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion *args
    end
    
    class NestedFileSystemLocator < FileSystemLocator
      def locate_plugins_under(base_path)
        plugins = super
        Dir["{#{plugins.map(&:directory).join(',')}}/vendor/plugins"].each do |path|
          plugins.concat super(path)
        end unless plugins.empty?
        plugins
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
adva-0.1.4 lib/rails_ext/railties/plugin.rb
adva-0.1.3 lib/rails_ext/railties/plugin.rb
adva-0.1.2 lib/rails_ext/railties/plugin.rb
adva-0.1.1 lib/rails_ext/railties/plugin.rb
adva-0.1.0 lib/rails_ext/railties/plugin.rb
adva_cms-0.0.1 lib/rails_ext/railties/plugin.rb
adva-0.0.1 adva_cms/lib/rails_ext/railties/plugin.rb