public
Fork of technoweenie/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/b3b0p/mephisto.git
initial commit to engines branch
svenfuchs (author)
Wed Feb 20 11:11:20 -0800 2008
commit  1ad1b56b4a6c9284534b0afbb9d5d87715ae4312
tree    adc435b61f05728a991fd314188bc3e75cfb6038
parent  2772ec18227b04b3cb618748a2900a7b93b84d94
...
2
3
4
5
 
6
7
8
...
19
20
21
22
 
23
24
25
...
2
3
4
 
5
6
7
8
...
19
20
21
 
22
23
24
25
0
@@ -2,7 +2,7 @@ class Admin::PluginsController < Admin::BaseController
0
   before_filter :find_plugin, :except => :index
0
 
0
   def index
0
- @plugins = Mephisto::DirectoryPlugin.scan
0
+ @plugins = Mephisto.plugins
0
   end
0
   
0
   def update
0
@@ -19,6 +19,6 @@ class Admin::PluginsController < Admin::BaseController
0
   
0
   protected
0
     def find_plugin
0
- @plugin = Mephisto::Plugin[params[:id]]
0
+ @plugin = Mephisto.plugins[params[:id]]
0
     end
0
 end
0
\ No newline at end of file
...
1
2
3
4
 
5
6
 
7
8
9
 
10
...
1
2
3
 
4
5
 
6
7
8
 
9
10
0
@@ -1,10 +1,10 @@
0
 <tr class="published" >
0
   <td class="published">
0
   <% if plugin.configurable? -%>
0
- <%= link_to plugin.path, :action => 'show', :id => plugin.path %>
0
+ <%= link_to plugin.mephisto_name, :action => 'show', :id => plugin.name %>
0
   <% else -%>
0
- <%=h plugin.path %>
0
+ <%=h plugin.mephisto_name %>
0
   <% end -%>
0
 </td>
0
- <td class="published"><%= plugin.configurable? ? link_to(image_tag('/images/mephisto/icons/8-em-check.png', :style => 'vertical-align: middle'), :action => "show", :id => plugin.path) : '&nbsp;' %></span> </td>
0
+ <td class="published"><%= plugin.configurable? ? link_to(image_tag('/images/mephisto/icons/8-em-check.png', :style => 'vertical-align: middle'), :action => "show", :id => plugin.name) : '&nbsp;' %></span> </td>
0
  </tr>
...
23
24
25
26
 
27
28
29
...
33
34
35
36
 
37
38
39
...
23
24
25
 
26
27
28
29
...
33
34
35
 
36
37
38
39
0
@@ -23,7 +23,7 @@
0
 <div id="page-nav">
0
   <ul id="act-nav" class="clear">
0
   <li>
0
- <%= link_to 'Restore Defaults', :action => 'destroy', :id => @plugin.plugin_name %>
0
+ <%= link_to 'Restore Defaults', :action => 'destroy', :id => @plugin.name %>
0
   </li>
0
   <li>
0
       <%= link_to 'Index', :action => 'index' %>
0
@@ -33,7 +33,7 @@
0
 <% end %>
0
 
0
 <% content_for :form do -%>
0
- <%= form_tag({:action => 'update', :id => @plugin.plugin_name}, {:id => 'plugin-config-form'}) %>
0
+ <%= form_tag({:action => 'update', :id => @plugin.name}, {:id => 'plugin-config-form'}) %>
0
 <% end -%>
0
 
0
 <% if @plugin.default_options.any? -%>
...
10
11
12
 
 
13
14
15
...
10
11
12
13
14
15
16
17
0
@@ -10,6 +10,8 @@
0
 
0
 # Bootstrap the Rails environment, frameworks, and default configuration
0
 require File.join(File.dirname(__FILE__), 'boot')
0
+require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')
0
+require File.join(File.dirname(__FILE__), '../lib/mephisto/plugin')
0
 
0
 # requires vendor-loaded redcloth
0
 require 'RedCloth-3.0.4/lib/redcloth' unless Object.const_defined?(:RedCloth)
...
12
13
14
 
 
15
16
17
...
36
37
38
 
 
39
40
41
...
12
13
14
15
16
17
18
19
...
38
39
40
41
42
43
44
45
0
@@ -12,6 +12,8 @@ ActiveRecord::Base.observers = [:article_observer, :comment_observer]
0
 # it's loaded before all other plugins
0
 # Object::RAILS_PATH = Pathname.new(File.expand_path(RAILS_ROOT))
0
 
0
+require 'mephisto'
0
+
0
 class ActionController::Dispatcher
0
   def self.register_liquid_tags
0
     Mephisto.liquid_filters.each { |mod| Liquid::Template.register_filter mod }
0
@@ -36,5 +38,7 @@ Inflector.inflections do |inflect|
0
   inflect.uncountable %w( audio )
0
 end
0
 
0
+Engines::Plugin::Config.set_table_name 'mephisto_plugins'
0
+
0
 Dependencies.autoloaded_constants.delete "Mephisto"
0
 Dependencies.autoloaded_constants.delete "Mephisto::Plugin"
0
\ No newline at end of file
...
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
 
 
 
 
 
 
 
 
 
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 
 
 
 
 
 
 
 
180
181
182
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
185
 
186
187
188
 
 
 
 
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
0
@@ -1,187 +1,49 @@
0
-module Mephisto
0
- # This module assists with general Mephisto plugins.
0
- class Plugin < ActiveRecord::Base
0
- set_table_name 'mephisto_plugins'
0
- serialize :options, Hash
0
-
0
- @@custom_routes = []
0
- @@view_paths = {}
0
- @@tabs = []
0
- @@admin_tabs = []
0
- cattr_reader :custom_routes, :view_paths, :tabs, :admin_tabs
0
-
0
- class << self
0
- expiring_attr_reader :plugin_name, 'name.demodulize.underscore'
0
- expiring_attr_reader :plugin_path, "RAILS_PATH + 'vendor/plugins' + ('mephisto_' + plugin_name)"
0
-
0
- plugin_property_source = %w(author version homepage notes).collect! do |property|
0
- <<-END
0
- def #{property}(value = nil)
0
- @#{property} = value if value
0
- @#{property}
0
- end
0
- END
0
- end
0
- eval plugin_property_source * "\n"
0
-
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
- end
0
-
0
- #
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
- #
0
- def find_class(key)
0
- klass_name = key.to_s.camelize
0
- klass = Mephisto::Plugins.const_get klass_name
0
- if klass < Mephisto::Plugin
0
- klass
0
- else
0
- raise NameError, "Plugin class must subclass Mephisto::Plugin"
0
- end
0
- end
0
-
0
- def [](key)
0
- find_class(key).find_or_initialize
0
- end
0
-
0
- def load(plugin_list)
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
- end
0
- end
0
- end
0
- end
0
-
0
- def default_options
0
- @default_options ||= {}
0
- end
0
-
0
- def option(property, default, field_type = :text_field)
0
- class_eval <<-END, __FILE__, __LINE__
0
- def #{property}
0
- write_attribute(:options, {}) if read_attribute(:options).nil?
0
- options[#{property.inspect}].blank? ? #{default.inspect} : options[#{property.inspect}]
0
- end
0
-
0
- def #{property}=(value)
0
- write_attribute(:options, {}) if read_attribute(:options).nil?
0
- options[#{property.inspect}] = value
0
- end
0
- END
0
- default_options[property] = field_type
0
- end
0
-
0
- # Installs the plugin's tables using the schema file in lib/#{plugin_name}/schema.rb
0
- #
0
- # script/runner -e production 'Mephisto::Plugins::Foo.install'
0
- # => installs the mephisto_foo plugin.
0
- #
0
- def install
0
- self::Schema.install
0
- end
0
-
0
- # Uninstalls the plugin's tables using the schema file in lib/#{plugin_name}/schema.rb
0
- def uninstall
0
- self::Schema.uninstall
0
- end
0
-
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
- def add_route(*args)
0
- custom_routes << args
0
- end
0
-
0
- # Keeps track of custom adminstration tabs. Each item is an array of arguments to be passed to link_to.
0
- #
0
- # module Mephisto
0
- # module Plugins
0
- # class Foo < Mephisto::Plugin
0
- # add_tab 'Foo', :controller => 'foo'
0
- # end
0
- # end
0
- # end
0
- def add_tab(*args)
0
- tabs << args
0
- end
0
-
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
- #
0
- # module Mephisto
0
- # module Plugins
0
- # class Foo < Mephisto::Plugin
0
- # add_admin_tab 'Foo', :controller => 'foo'
0
- # end
0
- # end
0
- # end
0
- def add_admin_tab(*args)
0
- admin_tabs << args
0
- end
0
-
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
- #
0
- # # #underscore will be called on the title parameter, so the 4th parameter 'foo' is unnecessary here.
0
- # module Mephisto
0
- # module Plugins
0
- # class Foo < Mephisto::Plugin
0
- # public_controller 'Foo', 'foo'
0
- # end
0
- # end
0
- # end
0
- #
0
- # Once set, create your controller in #{YOUR_PLUGIN}/lib/foo_controller.rb.
0
- #
0
- # class FooController < ApplicationController
0
- # self.template_root = Mephisto::Plugin.view_paths[:foo]
0
- # ...
0
- # end
0
- #
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
- end
0
- end
0
+require File.join(File.dirname(__FILE__), 'plugin_about_patch')
0
+
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
+
0
+module Mephisto
0
+ def self.plugins
0
+ @@plugins ||= Engines::Plugin::List.new Engines.plugins.select{ |plugin| plugin.mephisto_plugin? }
0
+ end
0
   
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
- #
0
- # module Mephisto
0
- # module Plugins
0
- # class Foo < Mephisto::Plugin
0
- # admin_controller 'Foo', 'foo'
0
- # end
0
- # end
0
- # end
0
- #
0
- # module Admin
0
- # class FooController < Admin::BaseController
0
- # self.template_root = Mephisto::Plugin.view_paths[:foo]
0
- # ...
0
- # end
0
- # end
0
- #
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
- end
0
- end
0
- end
0
+ module Plugin
0
+ @@tabs = []
0
+ @@admin_tabs = []
0
+ mattr_reader :tabs, :admin_tabs
0
+
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
     end
0
-
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
+
0
+ # Keeps track of custom adminstration tabs. Each item is an array of arguments to be passed to link_to.
0
+ def add_tab(*args)
0
+ args.push(:controller => args.first.to_s.downcase) if (args.size == 1)
0
+ Mephisto::Plugin.tabs << args
0
+ end
0
+
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
+ end
0
+
0
+ def mephisto_plugin?
0
+ name =~ /^mephisto_(\w+)$/
0
+ end
0
+
0
+ def configurable?
0
+ not default_options.empty?
0
+ end
0
+
0
+ def mephisto_name
0
+ name.sub /^mephisto_/, ''
0
     end
0
- eval plugin_property_source * "\n"
0
+ alias :conf_name :mephisto_name
0
   end
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+Engines::Plugin.send :include, Mephisto::Plugin
0
+
...
33
34
35
36
37
38
 
 
39
40
41
...
45
46
47
 
 
 
 
48
49
50
...
33
34
35
 
 
 
36
37
38
39
40
...
44
45
46
47
48
49
50
51
52
53
0
@@ -33,9 +33,8 @@ module Mephisto
0
       map.connect ':controller/:action/:id/:version', :version => nil, :controller => /routing_navigator|account|(admin\/\w+)/, :id => /[^\/]*/
0
 
0
       yield if block_given?
0
- Mephisto::Plugin.custom_routes.each do |path, options|
0
- map.connect path, options
0
- end
0
+
0
+ map_from_plugins(map)
0
       
0
       map.dispatch '*path', :controller => 'mephisto', :action => 'dispatch'
0
       map.home '', :controller => 'mephisto', :action => 'dispatch'
0
@@ -45,6 +44,10 @@ module Mephisto
0
       expiring_attr_reader :redirections, '{}'
0
     end
0
     
0
+ def self.map_from_plugins(map)
0
+ Engines.plugins.each { |plugin| map.from_plugin(plugin.name) }
0
+ end
0
+
0
     def self.deny(*paths)
0
       paths.each do |path|
0
         redirections[convert_redirection_to_regex(path)] = :deny
...
1
 
2
3
4
...
1
2
3
4
5
0
@@ -1,4 +1,5 @@
0
 ENV["RAILS_ENV"] = "test"
0
+
0
 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
0
 require 'spec'
0
 require 'spec/rails'
...
63
64
65
66
67
 
 
 
 
...
63
64
65
 
66
67
68
69
70
0
@@ -63,4 +63,7 @@ Class.class_eval do
0
   end
0
   
0
   alias_method_chain :inherited, :mixins
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+require 'mephisto/plugin'
0
+

Comments

    No one has commented yet.