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

Commit

Permalink
global plugin settings
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cook committed Jan 13, 2009
1 parent b012cac commit e30f2a2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/models/site_setting.rb
@@ -1,4 +1,5 @@
class SiteSetting < ActiveRecord::Base
has_settings
include CssSanitize

def get_theme_setting
Expand Down
15 changes: 13 additions & 2 deletions lib/ansuz/plugin_manager.rb
@@ -1,7 +1,7 @@
require "rubygems/gem_runner"

require File.join( RAILS_ROOT, "lib", "ansuz", "plugin_settings.rb" )
module Ansuz
class PluginManager
include Ansuz::PluginSettings
attr_accessor :plugins, :plugin_nav, :admin_plugin_nav, :admin_menu, :admin_menu_top_level_entries, :page_types
ADMIN_MENU_TOP_LEVEL_ENTRIES = ["Create", "Manage", "Ansuz"]

Expand All @@ -18,6 +18,8 @@ def initialize
# A plugin can call register_plugin(ClassName) to add itself to the plugins array
def register_plugin klass
self.plugins << klass
settings_name = klass.to_s.tableize.gsub(/\//,'_').to_sym
create_settings( settings_name )
end

# A plugin can call register_plugin_nav(title, link) to add itself to the
Expand Down Expand Up @@ -61,5 +63,14 @@ def setup_admin_menu
def register_page_type name, modules=[]
@page_types << [name, modules]
end

protected
def create_settings(name)
site_setting = SiteSetting.first
unless( site_setting.settings[name])
site_setting.settings[name] = {}
site_setting.save
end
end
end
end
26 changes: 26 additions & 0 deletions lib/ansuz/plugin_settings.rb
@@ -0,0 +1,26 @@
module Ansuz
# Don't really know the best way to do this, just rolling with whatever works -james
module PluginSettings
class << self
def included base
base.extend ClassMethods
end
end

module ClassMethods
def plugin_settings
SiteSetting.first.settings[self.settings_name]
end

def settings_name
self.to_s.tableize.gsub(/\//,'_').to_sym
end

def modify_setting(name,val)
site_setting = SiteSetting.first
site_setting.settings[self.settings_name][name.to_sym] = val
site_setting.save
end
end
end
end
@@ -1,7 +1,10 @@
require File.join(RAILS_ROOT, "lib", "ansuz", "plugin_settings.rb")
module Ansuz
module JAdams
class ContentSection < ActiveRecord::Base
include Ansuz::PluginSettings
before_save :set_default_content_section_type

CONTENT_SECTION_TYPES = ["FCKeditor", "Markdown", "Textile"]
has_settings
# Prevent bad things ™ from happening on initial rake db:migrate -james
Expand Down Expand Up @@ -62,11 +65,16 @@ def to_html
return self.contents
end
end

# Read the global setting or default to FCKeditor
def default_content_type
ContentSection.plugin_settings[:content_type] || "FCKeditor"
end

protected
def set_default_content_section_type
if( self.content_type.nil? )
self.content_type = "FCKeditor"
self.content_type = default_content_type
end
end
end
Expand Down

0 comments on commit e30f2a2

Please sign in to comment.