Skip to content

Commit

Permalink
Fixed urls for custom base and home node in alias sites.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Nov 5, 2013
1 parent 341fca8 commit b65031d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
1 change: 1 addition & 0 deletions lib/zena/use/ancestry.rb
Expand Up @@ -4,6 +4,7 @@ module Use
module Ancestry

def self.basepath_from_fullpath(fullpath)
return '' if !fullpath # This happens with pseudo root/home when node is not accessible
fullpath.split('/')[1..-1].join('/')
end

Expand Down
50 changes: 32 additions & 18 deletions lib/zena/use/urls.rb
Expand Up @@ -123,36 +123,50 @@ def zen_path(node, options={})
stamp = make_cachestamp(node, mode)
end

path = if !asset && node[:id] == visitor.site[:root_id] && mode.nil? && format == 'html'
path = if !asset && node[:id] == visitor.site.home_id && mode.nil? && format == 'html'
"#{abs_url_prefix}/#{pre}" # index page
elsif node[:custom_base]
"#{abs_url_prefix}/#{pre}/" +
basepath_as_url(node.basepath) +
(mode ? "_#{mode}" : '') +
(asset ? "=#{asset}" : '') +
(stamp ? ".#{stamp}" : '') +
basepath_as_url(node, true) +
(mode ? "_#{mode}" : '') +
(asset ? "=#{asset}" : '') +
(stamp ? ".#{stamp}" : '') +
(format == 'html' ? '' : ".#{format}")
else
"#{abs_url_prefix}/#{pre}/" +
(node.basepath.blank? ? '' : "#{basepath_as_url(node.basepath)}/") +
(node.klass.downcase ) +
(node[:zip].to_s ) +
(mode ? "_#{mode}" : '') +
(asset ? "=#{asset}" : '') +
(stamp ? ".#{stamp}" : '') +
basepath_as_url(node, false)+
(node.klass.downcase ) +
(node[:zip].to_s ) +
(mode ? "_#{mode}" : '') +
(asset ? "=#{asset}" : '') +
(stamp ? ".#{stamp}" : '') +
".#{format}"
end
append_query_params(path, opts)
end

def basepath_as_url(path)
path.split('/').map do |zip|
if n = secure(Node) { Node.find_by_zip(zip) }
n.title.url_name
else
nil
def basepath_as_url(node, is_end)
path = node.basepath
if !path.blank?
@home_base ||= begin
p = Zena::Use::Ancestry.basepath_from_fullpath(current_site.home_node.fullpath)
%r{^#{p}/?}
end
end.compact.join('/')
path = path.sub(@home_base, '')
return '' if path.blank?
path = path.split('/').map do |zip|
if n = secure(Node) { Node.find_by_zip(zip) }
n.title.url_name
else
nil
end
end.compact.join('/')
end
if is_end
path
else
path.blank? ? '' : "#{path}/"
end
end

def append_query_params(path, opts)
Expand Down
20 changes: 15 additions & 5 deletions test/integration/zafu_compiler/alias_site.yml
Expand Up @@ -8,10 +8,6 @@ default:
tem: "/visitor.site.home_node"
res: "alias.host: a wiki with Zena"

link_href_home:
src: "<r:link href='home'/>"
res: "<a href='/oo/blog29.html'>status title</a>"

test_home:
context:
node: wiki
Expand Down Expand Up @@ -39,4 +35,18 @@ from_home:
# For this test, we add some sub-nodes in wiki
in_home:
src: <r:void do='nodes in home' do='each' join=', ' do='title'/>
res: bird, flower, one, three, two
res: bird, flower, one, three, two

link_to_home:
src: <r:void do='home' do='link'/>
res: <a href='/oo'>a wiki with Zena</a>

link_with_custom_base:
# custom base is set on 'home' before this test
src: <r:void do='image in home' find='first' do='link'/> <r:void do='page where title = "three" in home' find='first' do='link'/>
res: <a href='/oo/image30.html'>bird</a> <a href='/oo/one/page68.html'>three</a>

This comment has been minimized.

Copy link
@testbird

testbird Apr 4, 2014

Could it be that the custom_base URL of the "three" page should be more like <a href='/oo/one/three.html'>three</a> or rather <a href='/oo/three.html'>three</a> with for the domain with the home node set?

This comment has been minimized.

Copy link
@testbird

testbird Apr 4, 2014

Ok, no, only "one" has the custom_base. The links are rendered fine, and it is only that the rendering itself #72 wasn't tested yet.


link_with_custom_base_out_of_home:
# custom base is set on 'home' before this test
src: <r:void do='page where id = 22 in site' find='first' do='link'/>
res: <a href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a>
12 changes: 12 additions & 0 deletions test/integration/zafu_compiler_test.rb
Expand Up @@ -398,5 +398,17 @@ def test_alias_site_in_home
secure(Page) { Page.create(:title => 'three', :parent_id => sub.id)}
yt_do_test('alias_site', 'in_home')
end

def test_alias_site_link_with_custom_base
login(:lion)
secure(Node) { nodes(:wiki) }.tap do |w|
w.update_attributes(:custom_base => true)
err w
end
node = secure(Page) { Page.create(:title => 'one', :parent_id => nodes_id(:wiki), :custom_base => true)}
sub = secure(Page) { Page.create(:title => 'two', :parent_id => node.id)}
secure(Page) { Page.create(:title => 'three', :parent_id => sub.id)}
yt_do_test('alias_site', 'link_with_custom_base')
end
yt_make
end

1 comment on commit b65031d

@testbird
Copy link

Choose a reason for hiding this comment

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

Could you add a test that checks that the link_with_custom_base can be renderd without a 404 not found?

Please sign in to comment.