Skip to content

Commit

Permalink
Better parsing of the pseudo attribute [url].
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Dec 13, 2010
1 parent 006d582 commit ef18e1d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bricks/tags/test/zafu/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tag_names:

tag_cloud:
src: "<r:tag_cloud in='project'><span do='each' join=' '><r:name/>(<r:show attr='count'/>)</span></r:tag_cloud>"
res: "<span>sky(2)</span>"
res: "<span>blue(1)</span> <span>sky(1)</span>"

input_tag:
context:
Expand Down
5 changes: 1 addition & 4 deletions lib/zafu/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def node_attribute(str, opts={})
if klass.ancestors.include?(Node)
if ['url','path'].include?(real_attribute)
# pseudo attribute 'url'
params = {}
params[:mode] = @params[:mode] if @params[:mode]
params[:format] = @params[:format] if @params[:format]
res = "zen_#{real_attribute}(#{node}#{params_to_erb(params)})"
res = make_link(:url_only => true, :in_erb => true, :is_url => real_attribute == 'url', :skip_html => true)
elsif real_attribute == 'lang'
res = 'lang'
elsif type = safe_method_type([real_attribute])
Expand Down
21 changes: 17 additions & 4 deletions lib/zafu/support/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def make_link(options = {})
end
end

if prefix = params.delete(:prefix)
opts[:prefix] = prefix.inspect
end

if mode = params.delete(:mode)
opts[:mode] = mode.inspect
end
Expand All @@ -79,7 +83,7 @@ def make_link(options = {})
opts[:anchor_in] = finder
end

if @html_tag && @html_tag != 'a'
if options[:skip_html] || (@html_tag && @html_tag != 'a')
# FIXME: can we remove this ?
# html attributes do not belong to anchor
pre_space = ''
Expand Down Expand Up @@ -147,10 +151,19 @@ def make_link(options = {})

opts_str += ", :host => #{@context["exp_host"]}" if @context["exp_host"]

if options[:url_only]
pre_space + "<%= zen_path(#{lnode}#{opts_str}) %>"
method = options[:is_url] ? 'zen_url' : 'zen_path'
if options[:in_erb]
if options[:url_only]
pre_space + "#{method}(#{lnode}#{opts_str})"
else
pre_space + "%Q{<a#{params_to_html(html_params)} href='\#{#{method}(#{lnode}#{opts_str})}'>#{text_for_link(default_text)}</a>}"
end
else
pre_space + "<a#{params_to_html(html_params)} href='<%= zen_path(#{lnode}#{opts_str}) %>'>#{text_for_link(default_text)}</a>"
if options[:url_only]
pre_space + "<%= #{method}(#{lnode}#{opts_str}) %>"
else
pre_space + "<a#{params_to_html(html_params)} href='<%= #{method}(#{lnode}#{opts_str}) %>'>#{text_for_link(default_text)}</a>"
end
end
end
end
Expand Down
16 changes: 14 additions & 2 deletions test/unit/zena/zena_tags/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ url:
context:
node: 'bird_jpg'
src: "<r:url format='data'/>"
res: "/en/image30.jpg?1144713600"
res: "/en/image30.jpg\?1144713600"

zafu_link_with_blocks:
src: "<a id='branding' do='link'><img src='sample.png' do='img' src='30'/></a>"
Expand Down Expand Up @@ -1326,4 +1326,16 @@ expand_with_set_host:
node: 'projects'
src: "relative:<r:link/> absolute:<r:expand_with set_host='[site.host]' do='link'/>"
tem: "/relative:.*zen_path\(@node\).*absolute:.*zen_path\(@node, :host => \"#\{current_site.host\}\"/"
res: "relative:<a href='/oo/page18.html'>projects list</a> absolute:<a href='http://test.host/oo/page18.html'>projects list</a>"
res: "relative:<a href='/oo/page18.html'>projects list</a> absolute:<a href='http://test.host/oo/page18.html'>projects list</a>"

url_with_format:
context:
node: 'bird_jpg'
src: "<link rel='image_src' do='void' set_href='[url]' format='data'/>"
tem: "<link href='<%= zen_url(@node,:format=>@node.c_ext) %>' rel='image_src'></link>"
res: "<link href='http://test.host/en/image30.jpg?1144713600' rel='image_src'></link>"

url_with_prefix:
src: "<link rel='image_src' do='void' set_href='[url]' prefix='fr'/>"
tem: "<link href='<%= zen_url(@node,:prefix=>\"fr\") %>' rel='image_src'></link>"
res: "<link href='http://test.host/fr/projects/cleanWater/page22.html' rel='image_src'></link>"

0 comments on commit ef18e1d

Please sign in to comment.