Skip to content

Commit

Permalink
tidying up things a little with the themes.
Browse files Browse the repository at this point in the history
  • Loading branch information
djones committed Mar 18, 2010
1 parent 4043cd5 commit 0b63e1c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
7 changes: 7 additions & 0 deletions vendor/plugins/themes/app/models/theme.rb
@@ -0,0 +1,7 @@
class Theme

def self.current_theme(request = nil)
RefinerySetting[:theme]
end

end
4 changes: 2 additions & 2 deletions vendor/plugins/themes/lib/theme_server.rb
Expand Up @@ -11,7 +11,7 @@ def initialize(app)
def call(env)
if env["PATH_INFO"] =~ /^\/theme/
env["PATH_INFO"].gsub!(/^\/theme\//, '')
if (file_path = (dir = Rails.root.join("themes", RefinerySetting[:theme])).join(env["PATH_INFO"])).exist?
if (file_path = (dir = Rails.root.join("themes", Theme.current_theme(env))).join(env["PATH_INFO"])).exist?
etag = Digest::MD5.hexdigest("#{file_path.to_s}#{file_path.mtime}")
unless (etag == env["HTTP_IF_NONE_MATCH"])
status, headers, body = Rack::File.new(dir).call(env)
Expand All @@ -27,4 +27,4 @@ def call(env)
end
end

end
end
34 changes: 13 additions & 21 deletions vendor/plugins/themes/rails/init.rb
Expand Up @@ -3,41 +3,33 @@
# Set up middleware to serve theme files
config.middleware.use "ThemeServer"

# Add or remove theme paths to/from Refinery application
::Refinery::ApplicationController.module_eval do

# Add or remove theme paths to/from Refinery application
before_filter do |controller|
# remove any paths relating to any theme.
controller.view_paths.reject! { |v| v.to_s =~ %r{^themes/} }

# add back theme paths if there is a theme present.
if (theme = RefinerySetting[:theme]).present?
if (theme = Theme.current_theme(controller.request)).present?
# Set up view path again for the current theme.
controller.view_paths.unshift Rails.root.join("themes", theme, "views").to_s

# Ensure that routes within the application are top priority.
# Here we grab all the routes that are under the application's view folder
# and promote them ahead of any other path.
controller.view_paths.select{|p| p.to_s =~ /^app\/views/}.each do |app_path|
controller.view_paths.unshift app_path
end
end

# Set up menu caching for this theme or lack thereof
RefinerySetting[:refinery_menu_cache_action_suffix] = "#{"#{theme}_" if theme.present?}site_menu"

# Ensure that routes within the application are top priority.
# Here we grab all the routes that are under the application's view folder
# and promote them ahead of any other path.
controller.view_paths.select{|p| p.to_s =~ /^app\/views/}.each do |app_path|
controller.view_paths.unshift app_path
end

# Ensure no duplicate paths.
controller.view_paths.uniq!
#RefinerySetting[:refinery_menu_cache_action_suffix] = "#{"#{theme}_" if theme.present?}site_menu"
end
end

if (theme = RefinerySetting[:theme]).present?
# Set up controller paths, which can only be brought in with a server restart, sorry. (But for good reason)
controller_path = Rails.root.join("themes", theme, "controllers").to_s

::ActiveSupport::Dependencies.load_paths.unshift controller_path
config.controller_paths.unshift controller_path
end

# Include theme functions into application helper.
Refinery::ApplicationHelper.send :include, ThemesHelper
end

end

0 comments on commit 0b63e1c

Please sign in to comment.