sidebar_helper.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:

Ajax

开发平台:

Others

  1. module SidebarHelper
  2.   def render_sidebars(*sidebars)
  3.     begin
  4.       (sidebars.blank? ? Sidebar.find(:all, :order => 'active_position ASC') : sidebars).inject('') do |acc, sb|
  5.         @sidebar = sb
  6.         sb.parse_request(contents, params)
  7.         acc + render_sidebar(sb)
  8.       end
  9.     rescue
  10.       _("It seems something went wrong. Maybe some of your sidebars are actually missing and you should either reinstall them or remove them manually
  11.         ")
  12.     end
  13.   end
  14.   def render_sidebar(sidebar)
  15.     if sidebar.view_root
  16.       # Allow themes to override sidebar views
  17.       view_root = File.expand_path(sidebar.view_root)
  18.       rails_root = File.expand_path(RAILS_ROOT)
  19.       if view_root =~ /^#{Regexp.escape(rails_root)}/
  20.         new_root = view_root[rails_root.size..-1]
  21.         new_root.sub! %r{^/?vendor/}, ""
  22.         new_root.sub! %r{/views}, ""
  23.         new_root = File.join(this_blog.current_theme.path, "views", new_root)
  24.         view_root = new_root if File.exists?(File.join(new_root, "content.rhtml"))
  25.       end
  26.       render_to_string(:file => "#{view_root}/content.rhtml",
  27.                        :locals => sidebar.to_locals_hash)
  28.     else
  29.       render_to_string(:partial => sidebar.content_partial,
  30.                        :locals => sidebar.to_locals_hash)
  31.     end
  32.   end
  33.   def articles?
  34.     not Article.first.nil?
  35.   end
  36.   def trackbacks?
  37.     not Trackback.first.nil?
  38.   end
  39.   def comments?
  40.     not Comment.first.nil?
  41.   end
  42. end