Skip to content

Commit

Permalink
Refactored to improve legibility and speed, removed deprecation warni…
Browse files Browse the repository at this point in the history
…ngs and switched to using the newer code instead.
  • Loading branch information
parndt committed Feb 7, 2011
1 parent 3269b70 commit 639be57
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 60 deletions.
27 changes: 2 additions & 25 deletions core/lib/refinery/plugin.rb
Expand Up @@ -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.
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions pages/app/controllers/pages_controller.rb
Expand Up @@ -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
Expand Down
40 changes: 9 additions & 31 deletions pages/app/models/page.rb
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 << " <em>(#{::I18n.t('hidden', :scope => 'admin.pages.page')})</em>" unless show_in_menu?
title << " <em>(#{::I18n.t('draft', :scope => 'admin.pages.page')})</em>" if draft?
title = [self.title.to_s]
title << "<em>(#{::I18n.t('hidden', :scope => 'admin.pages.page')})</em>" unless show_in_menu?
title << "<em>(#{::I18n.t('draft', :scope => 'admin.pages.page')})</em>" if draft?

title.strip
title.join(' ')
end

# Used to index all the content on this page so it can be easily searched.
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion 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
Expand Down

0 comments on commit 639be57

Please sign in to comment.