public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / lib / mephisto / plugin.rb
100644 58 lines (47 sloc) 1.725 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require File.join(File.dirname(__FILE__), 'plugin_about_patch')
 
# needs to be loaded before or at beginning of plugin init stage because it
# allows to use add_tab and add_admin_tab from plugin init.rb
 
module Mephisto
  def self.plugins
    @@plugins ||= Engines::Plugin::List.new Engines.plugins.select{ |plugin| plugin.mephisto_plugin? }
  end
  
  module Plugin
    @@tabs = []
    @@admin_tabs = []
    mattr_reader :tabs, :admin_tabs
    
    # delegate read access to about info
    %w(author homepage version notes).each do |property|
      module_eval "def #{property}; about['#{property}'] end", __FILE__, __LINE__
    end
 
    # Keeps track of custom adminstration tabs. Each item is an array of arguments to be passed to link_to.
    def add_tab(*args)
      args.push(:controller => args.first.to_s.downcase) if (args.size == 1)
      Mephisto::Plugin.tabs << args
    end
 
    # Keeps track of custom adminstration tabs for ADMIN users only. Each item is an array of arguments to be passed to link_to.
    def add_admin_tab(*args)
      args.push(:controller => args.first.to_s.downcase) if (args.size == 1)
      Mephisto::Plugin.admin_tabs << args
    end
    
    def mephisto_plugin?
      name =~ /^mephisto_(\w+)$/
    end
    
    def configurable?
      not default_options.empty?
    end
    
    def mephisto_name
      name.sub /^mephisto_/, ''
    end
    alias :conf_name :mephisto_name
  end
end
 
Engines::Plugin.send :include, Mephisto::Plugin
 
module Engines
  class Plugin < Rails::Plugin
    protected
      # override engine default list for Mephisto plugins
      def default_code_paths
        %w(app/controllers app/helpers app/models app/drops components lib)
      end
  end
end