Skip to content

Commit

Permalink
Let's not conflict with polymorphic_path
Browse files Browse the repository at this point in the history
  • Loading branch information
jystewart committed Dec 1, 2008
1 parent 6d90014 commit 3a5304d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 64 deletions.
79 changes: 40 additions & 39 deletions lib/patches/actionview_ex.rb
Expand Up @@ -4,51 +4,52 @@ module ActionView

# Extending <tt>ActionView::Base</tt> to support rendering themes
class Base
private

alias_method :theme_support_old_pick_template, :_pick_template
def _pick_template(template_path)
search_path = [
"#{RAILS_ROOT}/themes/#{controller.current_theme}/views", # for components
"#{RAILS_ROOT}/themes/#{controller.current_theme}", # for layouts
]
return template_path if template_path.respond_to?(:render)

private
def _pick_template(template_path)
search_path = [
"#{RAILS_ROOT}/themes/#{controller.current_theme}/views", # for components
"#{RAILS_ROOT}/themes/#{controller.current_theme}", # for layouts
]
return template_path if template_path.respond_to?(:render)

path = template_path.sub(/^\//, '')
if m = path.match(/(.*)\.(\w+)$/)
template_file_name, template_file_extension = m[1], m[2]
else
template_file_name = path
end
path = template_path.sub(/^\//, '')
if m = path.match(/(.*)\.(\w+)$/)
template_file_name, template_file_extension = m[1], m[2]
else
template_file_name = path
end

themed_file = File.join(search_path[0], "#{template_file_name}.#{template_format}.erb")
if File.exists?(themed_file)
return Template.new(themed_file, search_path)
else
return theme_support_old_pick_template(template_path)
end
end

def force_liquid?
unless controller.nil?
if controller.respond_to?('force_liquid_template')
controller.force_liquid_template
themed_file = File.join(search_path[0], "#{template_file_name}.#{template_format}.erb")
if File.exists?(themed_file)
return Template.new(themed_file, search_path)
else
return theme_support_old_pick_template(template_path)
end
else
false
end
end

# def force_liquid?
# unless controller.nil?
# if controller.respond_to?('force_liquid_template')
# controller.force_liquid_template
# end
# else
# false
# end
# end

def get_current_theme(local_assigns)
unless controller.nil?
if controller.respond_to?('current_theme')
return controller.current_theme || false
end
end
# Used with ActionMailers
if local_assigns.include? :current_theme
return local_assigns.delete :current_theme
end
end
# def get_current_theme(local_assigns)
# unless controller.nil?
# if controller.respond_to?('current_theme')
# return controller.current_theme || false
# end
# end
# # Used with ActionMailers
# if local_assigns.include? :current_theme
# return local_assigns.delete :current_theme
# end
# end
end
end
50 changes: 25 additions & 25 deletions lib/patches/routeset_ex.rb
@@ -1,26 +1,26 @@
# Extends <tt>ActionController::Routing::RouteSet</tt> to automatically add the theme routes
class ActionController::Routing::RouteSet

alias_method :__draw, :draw

# Overrides the default <tt>RouteSet#draw</tt> to automatically
# include the routes needed by the <tt>ThemeController</tt>
def draw
clear!
map = Mapper.new(self)

create_theme_routes(map)
yield map

named_routes.install
end

# Creates the required routes for the <tt>ThemeController</tt>...
def create_theme_routes(map)
map.theme_images "/themes/:theme/images/*filename", :controller=>'theme', :action=>'images'
map.theme_stylesheets "/themes/:theme/stylesheets/*filename", :controller=>'theme', :action=>'stylesheets'
map.theme_javascript "/themes/:theme/javascript/*filename", :controller=>'theme', :action=>'javascript'
map.connect "/themes/*whatever", :controller=>'theme', :action=>'error'
end

end
# class ActionController::Routing::RouteSet
#
# alias_method :__draw, :draw
#
# # Overrides the default <tt>RouteSet#draw</tt> to automatically
# # include the routes needed by the <tt>ThemeController</tt>
# def draw
# clear!
# map = Mapper.new(self)
#
# create_theme_routes(map)
# yield map
#
# named_routes.install
# end
#
# # Creates the required routes for the <tt>ThemeController</tt>...
# def create_theme_routes(map)
# map.theme_images "/themes/:theme/images/*filename", :controller=>'theme', :action=>'images'
# map.theme_stylesheets "/themes/:theme/stylesheets/*filename", :controller=>'theme', :action=>'stylesheets'
# map.theme_javascript "/themes/:theme/javascript/*filename", :controller=>'theme', :action=>'javascript'
# map.connect "/themes/*whatever", :controller=>'theme', :action=>'error'
# end
#
# end

0 comments on commit 3a5304d

Please sign in to comment.