Skip to content

Commit

Permalink
Added support for "target" in [zazen] when rendering links.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Jun 27, 2012
1 parent e47d4f1 commit 9284888
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Exporting relations by class name instead of kpath (may differ from site to site).
* Using any character to build kpath if no character from the class name can be used.
* Going through reverse order in console's foreach in case we destroy nodes.
* Added support for "target" in [zazen] when rendering links.

== 1.2.0, 1.2.1 2012-05-01

Expand Down
8 changes: 4 additions & 4 deletions lib/zena/parser/zazen_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def scan_exclam
end
else
if node.kind_of?(Document)
store @helper.make_image(:style=>style, :id=>node[:zip].to_s, :node=>node, :mode=>mode, :title=>title, :link=>link, :images=>@context[:images], :host => @context[:host])
store @helper.make_image(:style=>style, :id=>node[:zip].to_s, :node=>node, :mode=>mode, :title=>title, :link=>link, :images=>@context[:images], :host => @context[:host],:target=>@context[:target])
else
store "[#{node.fullpath_as_title.join('/')} is not a document]"
end
Expand Down Expand Up @@ -162,7 +162,7 @@ def scan_exclam
end
store "!#{style}#{id}#{other_opts}#{title_opts}!#{link ? ':' + link : ''}"
else
store @helper.make_image(:style=>style, :id=>id, :mode=>mode, :title=>title, :link=>link, :images=>@context[:images], :host => @context[:host])
store @helper.make_image(:style=>style, :id=>id, :mode=>mode, :title=>title, :link=>link, :images=>@context[:images], :host => @context[:host],:target=>@context[:target])
end
else
#puts "EAT:[#{$&}]"
Expand Down Expand Up @@ -190,7 +190,7 @@ def scan_quote
id, anchor = $1, $2
anchor = 'true' if anchor == ''
end
store @helper.make_link(:title=>title,:id=>id,:anchor=>anchor,:host=>@context[:host])
store @helper.make_link(:title=>title,:id=>id,:anchor=>anchor,:host=>@context[:host],:target=>@context[:target])
end
elsif @text =~ /\A"([^"]*)":(#{PSEUDO_ID_REGEXP})((_[a-z]+|)(\.[a-z]+|)(#[a-z_\/\[\]]*|))/m
#puts "SHORTCUT_LINK:[#{$&}]"
Expand All @@ -212,7 +212,7 @@ def scan_quote
id, anchor = $1, $2
anchor = 'true' if anchor == ''
end
store @helper.make_link(:title=>title,:id=>id,:anchor=>anchor,:node=>node,:host=>@context[:host])
store @helper.make_link(:title=>title,:id=>id,:anchor=>anchor,:node=>node,:host=>@context[:host],:target=>@context[:target])
end
elsif @translate_ids
store $&
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def r_zazen(signature = nil)
node = node(Node) || '@node'
return nil unless attribute = get_attribute_or_eval

hash_arguments = extract_from_params(:code, :host, :line_numbers, :theme) || []
hash_arguments = extract_from_params(:code, :host, :line_numbers, :theme, :target) || []

hash_arguments.insert(0, ":node => #{node}")

Expand Down
4 changes: 2 additions & 2 deletions lib/zena/use/zazen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ def make_link(opts)
link_to title, "##{anchor_value}"
end
elsif opts[:id] && opts[:id][0..0] == '0'
link_to title, zen_path(node, link_opts), :popup=>true
link_to title, zen_path(node, link_opts), :popup => true
else
link_to title, zen_path(node, link_opts)
link_to title, zen_path(node, link_opts), :target => opts[:target]
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/zena/parser/zazen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ wiki_link_partial_url:

make_asset:
src: "my email: [email]bob@example.com[/email]."
res: "<p>my email: [make_asset asset_tag:|email| content:|bob@example.com| output:|html|].</p>"
res: "<p>my email: [make_asset asset_tag:|email| content:|bob@example.com| output:|html|].</p>"
1 change: 1 addition & 0 deletions test/unit/zena/use/zazen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_image_title
def test_make_link
# * ["":34] creates a link to node 34 with node's title.
assert_equal '<p><a href="/en/projects-list/Clean-Water-project">Clean Water project</a></p>', zazen('"":21')
assert_equal '<p><a href="/en/projects-list/Clean-Water-project" target="_blank">Clean Water project</a></p>', zazen('"":21', :target => "_blank")
# * ["title":34] creates a link to node 34 with the given title.
assert_equal '<p><a href="/en/projects-list/Clean-Water-project">hello</a></p>', zazen('"hello":21')
# * ["":034] if the node id starts with '0', creates a popup link.
Expand Down

0 comments on commit 9284888

Please sign in to comment.