Commit 7d163bce8d0795a6b5d3beb5e6791e8277e3f5ce
1 parent
c8c723cd
Exists in
master
and in
28 other branches
ActionItem614: expanding profile in list of links
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/branches/0.11.x@2496 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
16 additions
and
1 deletions
Show diff stats
app/models/link_list_block.rb
... | ... | @@ -17,10 +17,18 @@ class LinkListBlock < Block |
17 | 17 | def content |
18 | 18 | block_title(title) + |
19 | 19 | content_tag('ul', |
20 | - links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_to(i[:name], i[:address]))} | |
20 | + links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_to(i[:name], expand_address(i[:address])))} | |
21 | 21 | ) |
22 | 22 | end |
23 | 23 | |
24 | + def expand_address(address) | |
25 | + if owner.respond_to?(:identifier) | |
26 | + address.gsub('{profile}', owner.identifier) | |
27 | + else | |
28 | + address | |
29 | + end | |
30 | + end | |
31 | + | |
24 | 32 | def editable? |
25 | 33 | true |
26 | 34 | end | ... | ... |
test/unit/link_list_block_test.rb
... | ... | @@ -33,4 +33,11 @@ class LinkListBlockTest < ActiveSupport::TestCase |
33 | 33 | assert_equal [{:name => 'categ', :address => '/address'}], l.links |
34 | 34 | end |
35 | 35 | |
36 | + should 'replace {profile} with profile identifier' do | |
37 | + profile = Profile.new(:identifier => 'test_profile') | |
38 | + l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{profile}/address'}]) | |
39 | + l.stubs(:owner).returns(profile) | |
40 | + assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/test_profile/address'} | |
41 | + end | |
42 | + | |
36 | 43 | end | ... | ... |