Skip to content
Browse files

Updated mail initializer & setting views

  • Loading branch information...
1 parent 35378fe commit a750529e9d578141cac357f7a1d46bce67f3e952 @hulihanapplications committed
View
1 app/assets/stylesheets/application.css.scss
@@ -31,6 +31,7 @@
@import "menu";
@import "pages";
@import "pagination";
+@import "settings";
View
10 app/assets/stylesheets/settings.css.scss
@@ -0,0 +1,10 @@
+/* Settings */
+div.settings {
+ margin-bottom:20px;
+ div.setting {
+ span.name {font-size:0.8em;color:#aaa;padding-left:3px}
+ div.description {
+ margin-top:10px;
+ }
+ }
+}
View
104 app/models/setting.rb
@@ -6,44 +6,63 @@ class Setting < ActiveRecord::Base
cattr_accessor :global_settings # Setting.global_settings
- def self.get_setting(name) # get a setting from the database, usually text-based string
- setting = Setting.find_by_name(name)
- return setting.to_s
- rescue # ActiveRecord not found
- return ""
- end
-
- def self.get_setting_bool(name) # get a setting from the database return true or false depending on "1" or "0"
- setting = Setting.find_by_name(name)
- setting.to_bool
- rescue # ActiveRecord not found
- return false
- end
-
- def self.get_global_settings
- begin
- logger.info "Retrieving global settings."
- setting_array = Setting.global # get ALL settings
- setting = setting_array.hash_by(:name, :to_value) # convert array to hash, indexed by name, value by to_value
- setting[:title] = setting[:site_title]
- setting[:description] = setting[:site_description]
- setting[:theme_url] = "/themes/#{setting[:theme]}" # url for theme directory
- setting[:themes_dir] = File.join(Rails.root.to_s, "public", "themes") # system path for main themes directory
- setting[:theme_dir] = File.join(setting[:themes_dir], setting[:theme]) # system path for current theme directory
- setting[:default_preview_type] = setting[:default_preview_type].constantize if setting[:default_preview_type]
- Rails.application.config.action_mailer.default_url_options = { :host => setting[:host] ? setting[:host] : "localhost" } # set actionmailer host
- # Autoload plugin settings
- Plugin.plugins.each do |name, plugin|
- setting[plugin.plugin_class.name.underscore.to_sym] = PluginSetting.plugin(plugin).all.hash_by(:name, :to_value)
- end
- rescue Exception => e
- logger.error e
- #logger.error e.backtrace
- setting = Hash.new
- end
- return setting
- end
+ class << self
+ def get_setting(name) # get a setting from the database, usually text-based string
+ setting = Setting.find_by_name(name)
+ return setting.to_s
+ rescue # ActiveRecord not found
+ return ""
+ end
+
+ def get_setting_bool(name) # get a setting from the database return true or false depending on "1" or "0"
+ setting = Setting.find_by_name(name)
+ setting.to_bool
+ rescue # ActiveRecord not found
+ return false
+ end
+
+ def get_global_settings
+ begin
+ logger.info "Retrieving global settings."
+ setting_array = Setting.global # get ALL settings
+ setting = setting_array.hash_by(:name, :to_value) # convert array to hash, indexed by name, value by to_value
+ setting[:title] = setting[:site_title]
+ setting[:description] = setting[:site_description]
+ setting[:theme_url] = "/themes/#{setting[:theme]}" # url for theme directory
+ setting[:themes_dir] = File.join(Rails.root.to_s, "public", "themes") # system path for main themes directory
+ setting[:theme_dir] = File.join(setting[:themes_dir], setting[:theme]) # system path for current theme directory
+ setting[:default_preview_type] = setting[:default_preview_type].constantize if setting[:default_preview_type]
+ Rails.application.config.action_mailer.default_url_options = { :host => setting[:host] ? setting[:host] : "localhost" } # set actionmailer host
+ # Autoload plugin settings
+ Plugin.plugins.each do |name, plugin|
+ setting[plugin.plugin_class.name.underscore.to_sym] = PluginSetting.plugin(plugin).all.hash_by(:name, :to_value)
+ end
+ rescue Exception => e
+ logger.error e
+ #logger.error e.backtrace
+ setting = Hash.new
+ end
+ return setting
+ end
+
+ # change setting
+ def set(name, value)
+ find_by_name(name).update_attribute(:value, value)
+ reload
+ end
+
+ # reload settings from database and store/cache in cattr
+ def reload
+ self.global_settings = table_exists? ? Setting.get_global_settings : Hash.new # load global settings into metaclass variable
+ end
+ # override [] for easy setting retrieval
+ # Setting[:title] # => "My Website"
+ def [](setting)
+ global_settings[setting.to_sym]
+ end
+ end
+
def to_param # make custom parameter generator for friendly urls
"#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}"
end
@@ -68,17 +87,6 @@ def to_value # return a value based on setting type
item_type == "bool" ? to_bool : to_s
end
- # change setting
- def self.set(name, value)
- find_by_name(name).update_attribute(:value, value)
- reload
- end
-
- # reload settings from database and store/cache in cattr
- def self.reload
- self.global_settings = table_exists? ? Setting.get_global_settings : Hash.new # load global settings into metaclass variable
- end
-
# Load settings for the first time when model is loaded
reload
end
View
54 app/views/settings/_list_settings.html.erb
@@ -1,57 +1,13 @@
<div class="section">
- <div class="header">
-
+ <div class="header">
<% if defined?(title) %>
<h2 class="title"><%= title %> <%= Setting.model_name.human(:count => :other) %></h2>
<% end %>
</div>
+ <%= content_tag :em, description if defined?(description) %>
- <%= "<i>#{description}</i>" if defined?(description) %>
- <% for setting in settings %>
- <% css_class = cycle("row_a", "row_b") %>
- <div class="box_1">
- <table width="100%" cellpadding=0 cellspacing=0 class="">
- <tr class="<%#= css_class %>">
- <td align=left>
- <h2><%= t("activerecord.records.#{setting.class == PluginSetting ? "plugin_" : nil}setting.#{setting.name}.title", :default => setting.name.humanize) %></h2>
- </td>
- <td align=right valign=middle>
- <div align=right>
- <% if setting.item_type == "string" %>
- <input type=text name="setting[<%= setting.name %>]" value="<%= setting.value %>" class="setting_item_string" id="setting_<%= setting.id %>" onfocus ="focus_input('setting_<%= setting.id %>')" onblur ="blur_input('setting_<%= setting.id %>')">
- <% elsif setting.item_type == "bool" %>
- <%= t("single.positive") %>
- <input type="radio" value="1" name="setting[<%= setting.name %>]"<% if setting.value == "1" %>CHECKED<% end %>>
- <%= t("single.negative") %>
- <input type="radio" value="0" name="setting[<%= setting.name %>]"<% if setting.value == "0" %>CHECKED<% end %>>
- <% elsif setting.item_type == "option" %>
- <select name="setting[<%= setting.name %>]">
- <% for option in setting.options.split(",") %>
- <% option = option.gsub(/ /,'') %>
- <option value="<%= option %>" <%= "SELECTED" if option == setting.value %>><%= t("single.#{option.downcase}", :default => option) %></option>
- <% end %>
- </select>
- <% elsif setting.item_type == "special" %>
- <%# Handle Special Settings %>
- <% if setting.name == "locale" %>
- <%= render :partial => "select_locale", :locals => {:options => {:input_name => "setting[#{setting.name}]"}} %>
- <% end%>
- <% else %>
- <%= t("label.item_unknown", :item => Setting.model_name.human, :name => setting.item_type) %>
- <% end %>
- </div>
- </td>
- </tr>
- <tr class="<%= @class %>">
- <td colspan=2 align=left>
- <hr />
- <div class="setting_description">
- <%= raw t("activerecord.records.#{setting.class == PluginSetting ? "plugin_" : nil}setting.#{setting.name}.description", :default => "") %>
- </div>
- </td>
- </tr>
- </table>
- </div>
- <% end %>
+ <% for setting in settings %>
+ <%= render setting %>
+ <% end %>
</div>
View
38 app/views/settings/_setting.html.erb
@@ -0,0 +1,38 @@
+<div class="setting box_1">
+ <table class="cell">
+ <tr>
+ <td class="half left title">
+ <h4>
+ <%= label_tag "setting_#{setting.id}", setting.title %>
+ <%= content_tag :span, setting.name, :class => :name %>
+ </h4>
+ </td>
+ <td class="half right" align=right>
+ <% case setting.item_type %>
+ <% when "string" %>
+ <% when "bool" %>
+ <%= radio_button_tag "setting[#{setting.name}]", "1", setting.to_bool %>
+ <%= t("single.positive") %>
+ <%= radio_button_tag "setting[#{setting.name}]", "0", !setting.to_bool %>
+ <%= t("single.negative") %>
+ <% when "option" %>
+ <select name="setting[<%= setting.name %>]">
+ <% for option in setting.options.split(",") %>
+ <% option = option.gsub(/ /,'') %>
+ <option value="<%= option %>" <%= "SELECTED" if option == setting.value %>><%= t("single.#{option.downcase}", :default => option) %></option>
+ <% end %>
+ </select>
+ <% when "special" %>
+ <% if setting.name == "locale" %>
+ <%= render :partial => "select_locale", :locals => {:options => {:input_name => "setting[#{setting.name}]"}} %>
+ <% end%>
+ <% else %>
+ <%= t("label.item_unknown", :item => Setting.model_name.human, :name => setting.item_type) %>
+ <% end %>
+ </td>
+ </tr>
+ </table>
+ <div class="description">
+ <%= setting.description %>
+ </div>
+</div>
View
17 config/initializers/mail.rb
@@ -1,18 +1,17 @@
# Load Mail Settings from config/email.yml
Rails.application.class.configure do
- config.action_mailer.raise_delivery_errors = false # report email errors?...usually overriden by config/environments/[environment]
-
+ config_file = Rails.root.join("config/email.yml")
+
if Rails.env != 'test'
- if File.exists?("#{Rails.root.to_s}/config/email.yml")
+ if File.exists?(config_file)
config.action_mailer.delivery_method = :smtp
- email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/email.yml"))
+ email_settings = YAML::load(File.open(config_file))
config.action_mailer.smtp_settings = email_settings[Rails.env] unless email_settings[Rails.env].nil?
+ # Load host from config file if specified
+ config.action_mailer.default_url_options ||= {:host => email_settings[Rails.env][:host]} if email_settings[Rails.env][:host]
else # no mail config file found
config.action_mailer.delivery_method = :sendmail if File.exists?(Emailer.sendmail_settings[:location]) # attempt to use use sendmail
+ config.action_mailer.default_url_options ||= {:host => "localhost"} # set actionmailer default host
end
end
-
- config.action_mailer.default_url_options ||= {:host => "localhost"} # set actionmailer default host
-end
-
-
+end

0 comments on commit a750529

Please sign in to comment.
Something went wrong with that request. Please try again.