From 639be572cb852588c7c7d708f0ab9a398526dd76 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 7 Feb 2011 23:18:32 +1300 Subject: [PATCH] Refactored to improve legibility and speed, removed deprecation warnings and switched to using the newer code instead. --- core/lib/refinery/plugin.rb | 27 ++------------- pages/app/controllers/pages_controller.rb | 6 ++-- pages/app/models/page.rb | 40 +++++------------------ pages/config/routes.rb | 2 +- 4 files changed, 15 insertions(+), 60 deletions(-) diff --git a/core/lib/refinery/plugin.rb b/core/lib/refinery/plugin.rb index 86a7ab3107..5eb9066f06 100644 --- a/core/lib/refinery/plugin.rb +++ b/core/lib/refinery/plugin.rb @@ -43,22 +43,12 @@ def class_name # Returns the internationalized version of the title def title - ::I18n.translate("plugins.#{name}.title") + ::I18n.translate(['plugins', name, 'title'].join('.')) end # Returns the internationalized version of the description def description - ::I18n.translate("plugins.#{name}.description") - end - - # Depreciation warning - def title=(title) - warn('title', caller) - end - - # Depreciation warning - def description=(description) - warn('description', caller) + ::I18n.translate(['plugins', name, 'description'].join('.')) end # Retrieve information about how to access the latest activities of this plugin. @@ -117,18 +107,5 @@ def initialize self.pathname = Pathname.new(caller(depth).first.match("(.*)#{File::SEPARATOR}lib")[1]) Refinery::Plugins.registered << self # add me to the collection of registered plugins end - - private - def warn(what, caller) - warning = ["\n*** DEPRECATION WARNING ***"] - warning << "You cannot use plugin.#{what} anymore." - warning << "#{what.pluralize.titleize} will be internationalized by the I18n api." - warning << "" - warning << "See http://github.com/resolve/refinerycms/blob/master/core/engines.md#readme" - warning << "Section: 'The Structure of a Plugin'" - warning << "" - warning << "Called from: #{caller.first.inspect}\n\n" - $stdout.puts warning.join("\n") - end end end diff --git a/pages/app/controllers/pages_controller.rb b/pages/app/controllers/pages_controller.rb index b914ed03cf..2d85749d85 100644 --- a/pages/app/controllers/pages_controller.rb +++ b/pages/app/controllers/pages_controller.rb @@ -16,11 +16,11 @@ def home # GET /about/mission # def show - @page = Page.find(params[:path].to_s.split('/').last) + @page = Page.find("#{params[:path]}/#{params[:id]}".split('/').last) - if @page.try(:live?) or (refinery_user? and current_user.authorized_plugins.include?("refinery_pages")) + if @page.try(:live?) || (refinery_user? && current_user.authorized_plugins.include?("refinery_pages")) # if the admin wants this to be a "placeholder" page which goes to its first child, go to that instead. - if @page.skip_to_first_child and (first_live_child = @page.children.order('lft ASC').where(:draft=>false).first).present? + if @page.skip_to_first_child && (first_live_child = @page.children.order('lft ASC').where(:draft=>false).first).present? redirect_to first_live_child.url end else diff --git a/pages/app/models/page.rb b/pages/app/models/page.rb index d9120daa22..301835ca5a 100644 --- a/pages/app/models/page.rb +++ b/pages/app/models/page.rb @@ -96,14 +96,6 @@ def destroy! # Used for the browser title to get the full path to this page # It automatically prints out this page title and all of it's parent page titles joined by a PATH_SEPARATOR def path(options = {}) - # Handle deprecated boolean - if [true, false].include?(options) - warning = "Page::path does not want a boolean (you gave #{options.inspect}) anymore. " - warning << "Please change this to {:reversed => #{options.inspect}}. " - warn(warning << "\nCalled from #{caller.first.inspect}") - options = {:reversed => options} - end - # Override default options with any supplied. options = {:reversed => true}.merge(options) @@ -144,12 +136,11 @@ def link_url_localised? def url_marketable # :id => nil is important to prevent any other params[:id] from interfering with this route. - {:controller => "/pages", :action => "show", :path => nested_url, :id => nil} + {:controller => '/pages', :action => 'show', :path => nested_url, :id => nil} end def url_normal - # :id => nil is important to prevent any other params[:id] from interfering with this route. - {:controller => "/pages", :action => "show", :path => to_param, :id => nil} + {:controller => '/pages', :action => 'show', :path => nil, :id => to_param} end # Returns an array with all ancestors to_param, allow with its own @@ -169,15 +160,15 @@ def uncached_nested_url # Returns the string version of nested_url, i.e., the path that should be generated # by the router def nested_path - @nested_path ||= "/#{nested_url.join('/')}" + @nested_path ||= ['', nested_url].join('/') end def url_cache_key - "#{cache_key}#nested_url" + [cache_key, 'nested_url'].join('#') end def cache_key - "#{Refinery.base_cache_key}/#{super}" + [Refinery.base_cache_key, super].join('/') end def use_marketable_urls? @@ -215,12 +206,6 @@ def default_parts def per_page(dialog = false) dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX end - - # Returns all the top level pages, usually to render the top level navigation. - def top_level - warn("Please use .live.in_menu instead of .top_level") - roots.where(:show_in_menu => true, :draft => false) - end end # Accessor method to get a page part from a page. @@ -248,11 +233,11 @@ def [](part_title) # In the admin area we use a slightly different title to inform the which pages are draft or hidden pages def title_with_meta - title = self.title.to_s - title << " (#{::I18n.t('hidden', :scope => 'admin.pages.page')})" unless show_in_menu? - title << " (#{::I18n.t('draft', :scope => 'admin.pages.page')})" if draft? + title = [self.title.to_s] + title << "(#{::I18n.t('hidden', :scope => 'admin.pages.page')})" unless show_in_menu? + title << "(#{::I18n.t('draft', :scope => 'admin.pages.page')})" if draft? - title.strip + title.join(' ') end # Used to index all the content on this page so it can be easily searched. @@ -281,11 +266,4 @@ def invalidate_child_cached_url Rails.cache.delete(child.url_cache_key) end end - - def warn(msg) - warning = ["\n*** DEPRECATION WARNING ***"] - warning << "#{msg}" - warning << "" - $stdout.puts warning.join("\n") - end end diff --git a/pages/config/routes.rb b/pages/config/routes.rb index dbc95d1e9a..3456a7d771 100644 --- a/pages/config/routes.rb +++ b/pages/config/routes.rb @@ -1,5 +1,5 @@ ::Refinery::Application.routes.draw do - get '/pages/:path', :to => 'pages#show', :as => :page + get '/pages/:id', :to => 'pages#show', :as => :page scope(:path => 'refinery', :as => 'admin', :module => 'admin') do resources :pages, :except => :show do