Skip to content

Commit

Permalink
move url methods and tags to path
Browse files Browse the repository at this point in the history
this paves the way to deprecate current implementations and change behaviors:
for example the <r:url /> will be able to print the URL including domain.
  • Loading branch information
saturnflyer committed Oct 24, 2010
1 parent f211d2b commit cf3d033
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 163 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,7 @@

=== Edge

* Move url methods to path [Jim Gay]
* Allow use of custom TextFilter names[Petrik de Heus]
* Set autocomplete="off" for password fields [Gert Goet]
* Allow loading of database templates from extensions [Jim Gay]
Expand Down
37 changes: 21 additions & 16 deletions app/models/page.rb
Expand Up @@ -63,9 +63,10 @@ def cache?
true
end

def child_url(child)
clean_url(url + '/' + child.slug)
def child_path(child)
clean_path(path + '/' + child.slug)
end
alias_method :child_url, :child_path

def headers
# Return a blank hash that child classes can override or merge
Expand Down Expand Up @@ -116,13 +117,14 @@ def status=(value)
self.status_id = value.id
end

def url
def path
if parent?
parent.child_url(self)
parent.child_path(self)
else
clean_url(slug)
clean_path(slug)
end
end
alias_method :url, :path

def process(request, response)
@request, @response = request, response
Expand Down Expand Up @@ -160,20 +162,20 @@ def render_snippet(snippet)
parse_object(snippet)
end

def find_by_url(url, live = true, clean = true)
def find_by_path(path, live = true, clean = true)
return nil if virtual?
url = clean_url(url) if clean
my_url = self.url
if (my_url == url) && (not live or published?)
path = clean_path(path) if clean
my_path = self.path
if (my_path == path) && (not live or published?)
self
elsif (url =~ /^#{Regexp.quote(my_url)}([^\/]*)/)
elsif (path =~ /^#{Regexp.quote(my_path)}([^\/]*)/)
slug_child = children.find_by_slug($1)
if slug_child
found = slug_child.find_by_url(url, live, clean)
found = slug_child.find_by_path(path, live, clean)
return found if found
end
children.each do |child|
found = child.find_by_url(url, live, clean)
found = child.find_by_path(path, live, clean)
return found if found
end
file_not_found_types = ([FileNotFoundPage] + FileNotFoundPage.descendants)
Expand All @@ -183,6 +185,7 @@ def find_by_url(url, live = true, clean = true)
children.find(:first, :conditions => [condition] + file_not_found_names)
end
end
alias_method :find_by_url, :find_by_path

def update_status
self.published_at = Time.zone.now if published? && self.published_at == nil
Expand All @@ -204,11 +207,12 @@ class << self
alias_method :in_menu?, :in_menu
alias_method :in_menu, :in_menu=

def find_by_url(url, live = true)
def find_by_path(path, live = true)
root = find_by_parent_id(nil)
raise MissingRootPageError unless root
root.find_by_url(url, live)
root.find_by_path(path, live)
end
alias_method :find_by_url, :find_by_path

def display_name(string = nil)
if string
Expand Down Expand Up @@ -310,9 +314,10 @@ def update_virtual
true
end

def clean_url(url)
"/#{ url.strip }/".gsub(%r{//+}, '/')
def clean_path(path)
"/#{ path.strip }/".gsub(%r{//+}, '/')
end
alias_method :clean_url, :clean_path

def parent?
!parent.nil?
Expand Down

1 comment on commit cf3d033

@protoror
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not work correct <r:url /> in block <r:navigation>
change <r:url /> to <r:path /> solved problem

Please sign in to comment.