0
- # This module assists with general Mephisto plugins.
0
- class Plugin < ActiveRecord::Base
0
- set_table_name 'mephisto_plugins'
0
- serialize :options, Hash
0
+require File.join(File.dirname(__FILE__), 'plugin_about_patch')
0
+# needs to be loaded before or at beginning of plugin init stage because it
0
+# allows to use add_tab and add_admin_tab from plugin init.rb
0
+ @@plugins ||= Engines::Plugin::List.new Engines.plugins.select{ |plugin| plugin.mephisto_plugin? }
0
- cattr_reader :custom_routes, :view_paths, :tabs, :admin_tabs
0
- expiring_attr_reader :plugin_name, 'name.demodulize.underscore'
0
- expiring_attr_reader :plugin_path, "RAILS_PATH + 'vendor/plugins' + ('mephisto_' + plugin_name)"
0
- plugin_property_source = %w(author version homepage notes).collect! do |property|
0
- def #{property}(value = nil)
0
- @#{property} = value if value
0
- eval plugin_property_source * "\n"
0
- # Finds or initializes a new plugin record from the database by the plugin name
0
- def find_or_initialize
0
- find_or_initialize_by_name(plugin_name)
0
- # Matches key to sub classes of Mephisto::Plugin in the namespace Mephisto::Plugins.
0
- # In other words, your plugin needs to subclass the former and be within the latter.
0
- klass_name = key.to_s.camelize
0
- klass = Mephisto::Plugins.const_get klass_name
0
- if klass < Mephisto::Plugin
0
- raise NameError, "Plugin class must subclass Mephisto::Plugin"
0
- find_class(key).find_or_initialize
0
- returning find_all_by_name(plugin_list).index_by(&:name) do |plugins|
0
- plugin_list.each do |name|
0
- if plugin_class = plugins[name].nil? && self[name]
0
- plugins[name] ||= plugin_class.new(:name => name)
0
- @default_options ||= {}
0
- def option(property, default, field_type = :text_field)
0
- class_eval <<-END, __FILE__, __LINE__
0
- write_attribute(:options, {}) if read_attribute(:options).nil?
0
- options[#{property.inspect}].blank? ? #{default.inspect} : options[#{property.inspect}]
0
- def #{property}=(value)
0
- write_attribute(:options, {}) if read_attribute(:options).nil?
0
- options[#{property.inspect}] = value
0
- default_options[property] = field_type
0
- # Installs the plugin's tables using the schema file in lib/#{plugin_name}/schema.rb
0
- # script/runner -e production 'Mephisto::Plugins::Foo.install'
0
- # => installs the mephisto_foo plugin.
0
- # Uninstalls the plugin's tables using the schema file in lib/#{plugin_name}/schema.rb
0
- self::Schema.uninstall
0
- # Adds a custom route to Mephisto from a plugin. These routes are created in the order they are added.
0
- # They will be the last routes before the Mephisto Dispatcher catch-all route.
0
- # Keeps track of custom adminstration tabs. Each item is an array of arguments to be passed to link_to.
0
- # class Foo < Mephisto::Plugin
0
- # add_tab 'Foo', :controller => 'foo'
0
- # Keeps track of custom adminstration tabs for ADMIN users only. Each item is an array of arguments to be passed to link_to.
0
- # class Foo < Mephisto::Plugin
0
- # add_admin_tab 'Foo', :controller => 'foo'
0
- def add_admin_tab(*args)
0
- # Sets up a custom public controller for this plugin. It adds the plugin's lib directory to the controller paths directory and
0
- # saves the view path. Call this from your plugin's init.rb file.
0
- # # #underscore will be called on the title parameter, so the 4th parameter 'foo' is unnecessary here.
0
- # class Foo < Mephisto::Plugin
0
- # public_controller 'Foo', 'foo'
0
- # Once set, create your controller in #{YOUR_PLUGIN}/lib/foo_controller.rb.
0
- # class FooController < ApplicationController
0
- # self.template_root = Mephisto::Plugin.view_paths[:foo]
0
- # Your views will then be stored in #{YOUR_PLUGIN}/views/foo/*.rhtml.
0
- def public_controller(title, name = nil)
0
- returning((name || title.underscore).to_sym) do |controller_name|
0
- view_paths[controller_name] = (plugin_path + 'views').to_s
0
- # Sets up a custom admin controller. Mephisto::Plugin.public_controller is used for the basic setup. This also automatically
0
- # adds a tab for you, and symlinks Mephisto's core app/views/layouts path. Like Mephisto::Plugin.public_controller, this should be
0
- # called from your plugin's init.rb file.
0
- # class Foo < Mephisto::Plugin
0
- # admin_controller 'Foo', 'foo'
0
- # class FooController < Admin::BaseController
0
- # self.template_root = Mephisto::Plugin.view_paths[:foo]
0
- # Your views will then be stored in #{YOUR_PLUGIN}/views/admin/foo/*.rhtml.
0
- def admin_controller(title, name = nil, options = {})
0
- returning public_controller(title, name) do |controller_name|
0
- add_tab title, {:controller => "admin/#{controller_name}"}.update(options)
0
- unless File.exists?(File.join(view_paths[controller_name], 'layouts'))
0
- FileUtils.mkdir_p view_paths[controller_name]
0
- FileUtils.symlink(RAILS_PATH + 'app/views/layouts', File.join(view_paths[controller_name], 'layouts'))
0
+ mattr_reader :tabs, :admin_tabs
0
+ # delegate read access to about info
0
+ %w(author homepage version notes).each do |property|
0
+ module_eval "def #{property}; about['#{property}'] end", __FILE__, __LINE__
0
- plugin_property_source = %w(author version homepage notes plugin_name plugin_path default_options).collect! do |property|
0
- "def #{property}() self.class.#{property} end"
0
+ # Keeps track of custom adminstration tabs. Each item is an array of arguments to be passed to link_to.
0
+ args.push(:controller => args.first.to_s.downcase) if (args.size == 1)
0
+ Mephisto::Plugin.tabs << args
0
- eval plugin_property_source * "\n"
0
+ # Keeps track of custom adminstration tabs for ADMIN users only. Each item is an array of arguments to be passed to link_to.
0
+ def add_admin_tab(*args)
0
+ args.push(:controller => args.first.to_s.downcase) if (args.size == 1)
0
+ Mephisto::Plugin.admin_tabs << args
0
+ name =~ /^mephisto_(\w+)$/
0
+ not default_options.empty?
0
+ name.sub /^mephisto_/, ''
0
+ alias :conf_name :mephisto_name
0
+Engines::Plugin.send :include, Mephisto::Plugin