diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index f936d07..e8a55d7 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -1,4 +1,5 @@ class SiteSetting < ActiveRecord::Base + has_settings include CssSanitize def get_theme_setting diff --git a/lib/ansuz/plugin_manager.rb b/lib/ansuz/plugin_manager.rb index bce1d09..33030c9 100644 --- a/lib/ansuz/plugin_manager.rb +++ b/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"] @@ -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 @@ -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 diff --git a/lib/ansuz/plugin_settings.rb b/lib/ansuz/plugin_settings.rb new file mode 100644 index 0000000..00f5d9f --- /dev/null +++ b/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 diff --git a/vendor/plugins/ansuz_content_section/app/models/ansuz/j_adams/content_section.rb b/vendor/plugins/ansuz_content_section/app/models/ansuz/j_adams/content_section.rb index 7e5455b..d3bdd52 100644 --- a/vendor/plugins/ansuz_content_section/app/models/ansuz/j_adams/content_section.rb +++ b/vendor/plugins/ansuz_content_section/app/models/ansuz/j_adams/content_section.rb @@ -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 @@ -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