Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
added admin tabs registration to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Sep 10, 2008
1 parent 438e2f0 commit e0be36f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Admin::BaseController < ApplicationController
before_filter :login_required
before_filter :load_admin_plugin_nav
layout 'admin'

protected
def load_admin_plugin_nav
# The plugin nav comes across as an array of arrays like [text, url]
@admin_plugin_nav = Ansuz::PluginManagerInstance.admin_plugin_nav
end
end
6 changes: 6 additions & 0 deletions app/controllers/page_admin_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class PageAdminController < ApplicationController
before_filter :load_admin_plugin_nav # This needs to happen in an Admin::BaseController
include PageAdminHelper
before_filter :login_required
before_filter :load_page, :only => [:edit, :update, :destroy, :shift_order]
Expand All @@ -9,6 +10,11 @@ def load_page
@page = Page.find params[:id]
end

def load_admin_plugin_nav
# The plugin nav comes across as an array of arrays like [text, url]
@admin_plugin_nav = Ansuz::PluginManagerInstance.admin_plugin_nav
end

public

def index
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<%= render :partial => "/page_admin/tabs" %>
<div id="bd">
<div class="yui-g">
<%# TODO: I need to use the helper I use to print all flash messages here, way more stylable / useful -ja -%>
<% if flash[:message] -%>
<div id="message"><%= flash[:message] %></div> <!-- end .message -->
<% end -%>
Expand All @@ -39,4 +40,4 @@
<div id="ft">Add a Plugin</div>
</div>
</body>
</html>
</html>
1 change: 1 addition & 0 deletions app/views/page_admin/_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<li><%= create_tab('Account Settings', 'account', 'update') %></li>
<li><%= create_tab('Logout', 'account', 'logout') %></li>
</ul>
<%= render :partial => "page_plugins/admin_plugins_nav" -%>
</div>
<% end %>
5 changes: 5 additions & 0 deletions app/views/page_plugins/_admin_plugins_nav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul id='admin-plugins-nav'>
<% @admin_plugin_nav.each do |text, url| -%>
<li><%= link_to text, url -%></li>
<% end -%>
</ul>
9 changes: 8 additions & 1 deletion lib/ansuz/plugin_manager.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class Ansuz
class PluginManager
attr_accessor :plugins, :plugin_nav
attr_accessor :plugins, :plugin_nav, :admin_plugin_nav

def initialize
@plugins = []
@plugin_nav = []
@admin_plugin_nav = []
end

# A plugin can call register_plugin(ClassName) to add itself to the plugins array
Expand All @@ -17,5 +18,11 @@ def register_plugin klass
def register_plugin_nav title, link
self.plugin_nav << [title, link]
end

# A plugin can call register_admin_plugin_nav(title, link) to add itself to the
# admin-facing navigation menu
def register_admin_plugin_nav title, link
self.admin_plugin_nav << [title, link]
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BlogPostsController < ApplicationController
class BlogPostsController < Admin::BaseController
unloadable # This is required if you subclass a controller provided by the base rails app

layout 'admin'
Expand Down
1 change: 1 addition & 0 deletions vendor/plugins/ansuz_blog/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
require 'blog_post'
require 'blog_comment'
Ansuz::PluginManagerInstance.register_plugin_nav('Blog', '/articles')
Ansuz::PluginManagerInstance.register_admin_plugin_nav('Blog Posts', '/blog_posts')

0 comments on commit e0be36f

Please sign in to comment.