Commit 179d8266ed552edcd919aa850c254722720b6217
1 parent
50277d03
Exists in
master
and in
29 other branches
ActionItem457: implementing a site map
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2046 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
14 changed files
with
118 additions
and
23 deletions
Show diff stats
app/controllers/public/profile_controller.rb
app/helpers/application_helper.rb
... | ... | @@ -15,6 +15,8 @@ module ApplicationHelper |
15 | 15 | include BlockHelper |
16 | 16 | |
17 | 17 | include DatesHelper |
18 | + | |
19 | + include FolderHelper | |
18 | 20 | |
19 | 21 | # Displays context help. You can pass the content of the help message as the |
20 | 22 | # first parameter or using template code inside a block passed to this | ... | ... |
app/helpers/cms_helper.rb
... | ... | @@ -9,19 +9,6 @@ module CmsHelper |
9 | 9 | mime_type.gsub('/', '_').gsub('-', '') |
10 | 10 | end |
11 | 11 | |
12 | - def icon_for_article(article) | |
13 | - icon = article.icon_name | |
14 | - if (icon =~ /\//) | |
15 | - icon | |
16 | - else | |
17 | - if File.exists?(File.join(RAILS_ROOT, 'public', 'images', 'icons-mime', "#{icon}.png")) | |
18 | - "icons-mime/#{icon}.png" | |
19 | - else | |
20 | - "icons-mime/unknown.png" | |
21 | - end | |
22 | - end | |
23 | - end | |
24 | - | |
25 | 12 | attr_reader :environment |
26 | 13 | |
27 | 14 | end | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +module FolderHelper | |
2 | + | |
3 | + def list_articles(articles, recursive = false) | |
4 | + articles.map {|item| display_article_in_listing(item, recursive, 0)}.join('') | |
5 | + end | |
6 | + | |
7 | + def display_article_in_listing(article, recursive = false, level = 0) | |
8 | + result = content_tag( | |
9 | + 'div', | |
10 | + link_to((' ' * (level * 4) ) + image_tag(icon_for_article(article)) + article.name, article.url), | |
11 | + :class => 'sitemap-item' | |
12 | + ) | |
13 | + if recursive | |
14 | + result + article.children.map {|item| display_article_in_listing(item, recursive, level + 1) }.join('') | |
15 | + else | |
16 | + result | |
17 | + end | |
18 | + end | |
19 | + | |
20 | + def icon_for_article(article) | |
21 | + icon = article.icon_name | |
22 | + if (icon =~ /\//) | |
23 | + icon | |
24 | + else | |
25 | + if File.exists?(File.join(RAILS_ROOT, 'public', 'images', 'icons-mime', "#{icon}.png")) | |
26 | + "icons-mime/#{icon}.png" | |
27 | + else | |
28 | + "icons-mime/unknown.png" | |
29 | + end | |
30 | + end | |
31 | + end | |
32 | + | |
33 | +end | ... | ... |
app/models/folder.rb
... | ... | @@ -12,13 +12,14 @@ class Folder < Article |
12 | 12 | 'folder' |
13 | 13 | end |
14 | 14 | |
15 | - # FIXME we should not need all this just to write a link | |
15 | + # FIXME isn't this too much including just to be able to generate some HTML? | |
16 | 16 | include ActionView::Helpers::TagHelper |
17 | 17 | include ActionView::Helpers::UrlHelper |
18 | 18 | include ActionController::UrlWriter |
19 | + include ActionView::Helpers::AssetTagHelper | |
20 | + include FolderHelper | |
19 | 21 | def to_html |
20 | - content_tag('div', body) + | |
21 | - content_tag('ul', children.map { |child| content_tag('li', link_to(child.name, child.url)) }, :class => 'folder-listing') | |
22 | + content_tag('div', body) + tag('hr') + list_articles(children) | |
22 | 23 | end |
23 | 24 | |
24 | 25 | def folder? | ... | ... |
app/models/recent_documents_block.rb
app/views/cms/view.rhtml
1 | +<h1> | |
2 | + <%= icon('cms') %> | |
3 | + <%= _('Content management') %> | |
4 | +</h1> | |
5 | + | |
1 | 6 | <% if @article %> |
2 | 7 | <h1 id='article-full-path'> |
3 | 8 | <%= icon('cms') %> |
4 | 9 | <%= link_to profile.identifier, :action => 'index' %> |
5 | 10 | <%= @article.hierarchy.map {|item| " / " + ((item == @article) ? item.name : link_to(item.name, :id => item.id)) } %> |
6 | 11 | </h1> |
7 | -<% else %> | |
8 | - <h1> | |
9 | - <%= icon('cms') %> | |
10 | - <%= _('Content management') %> | |
11 | - </h1> | |
12 | 12 | <% end %> |
13 | 13 | |
14 | 14 | <% button_bar(:style => 'margin-bottom: 1em;') do %> | ... | ... |
app/views/profile/index.rhtml
public/stylesheets/common.css
... | ... | @@ -239,6 +239,10 @@ table.cms-articles th, table.cms-articles td { |
239 | 239 | border: 1px solid #e0e0e0; |
240 | 240 | } |
241 | 241 | |
242 | +table.noborder th, table.noborder td{ | |
243 | + border: none; | |
244 | +} | |
245 | + | |
242 | 246 | /* for fields with auto-completion */ |
243 | 247 | div.auto-complete { |
244 | 248 | display: block; |
... | ... | @@ -284,3 +288,18 @@ div.pending-tasks { |
284 | 288 | margin: 1em; |
285 | 289 | } |
286 | 290 | |
291 | +/* sitemap */ | |
292 | +div.sitemap-item a:link, | |
293 | +div.sitemap-item a:visited { | |
294 | + display: block; | |
295 | + border: none; | |
296 | + text-decoration: none; | |
297 | +} | |
298 | +div.sitemap-item img { | |
299 | + border: none; | |
300 | +} | |
301 | +div.sitemap-item a:hover { | |
302 | + background-color: #f0f0f0; | |
303 | + color: red; | |
304 | +} | |
305 | + | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -232,4 +232,14 @@ class ProfileControllerTest < Test::Unit::TestCase |
232 | 232 | assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ |
233 | 233 | end |
234 | 234 | |
235 | + should 'display "Site map" link for profiles' do | |
236 | + get :index, :profile => 'ze' | |
237 | + assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/ze/sitemap' } | |
238 | + end | |
239 | + | |
240 | + should 'list top level articles in sitemap' do | |
241 | + get :sitemap, :profile => 'testuser' | |
242 | + assert_equal @profile.top_level_articles, assigns(:articles) | |
243 | + end | |
244 | + | |
235 | 245 | end | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class FolderHelperTest < Test::Unit::TestCase | |
4 | + | |
5 | + include FolderHelper | |
6 | + | |
7 | + should 'display icon for articles' do | |
8 | + art1 = mock; art1.expects(:icon_name).returns('icon1') | |
9 | + art2 = mock; art2.expects(:icon_name).returns('icon2') | |
10 | + | |
11 | + File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'images', 'icons-mime', 'icon1.png')).returns(true) | |
12 | + File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'images', 'icons-mime', 'icon2.png')).returns(false) | |
13 | + | |
14 | + assert_equal 'icons-mime/icon1.png', icon_for_article(art1) | |
15 | + assert_equal 'icons-mime/unknown.png', icon_for_article(art2) | |
16 | + end | |
17 | + | |
18 | +end | ... | ... |
test/unit/folder_test.rb
... | ... | @@ -24,8 +24,8 @@ class FolderTest < ActiveSupport::TestCase |
24 | 24 | f.children.create!(:profile => p, :name => 'onearticle') |
25 | 25 | f.children.create!(:profile => p, :name => 'otherarticle') |
26 | 26 | |
27 | - assert_match(/<li><a href=".*\/testuser\/f\/onearticle">onearticle<\/a><\/li>/, f.to_html) | |
28 | - assert_match(/<li><a href=".*\/testuser\/f\/otherarticle">otherarticle<\/a><\/li>/, f.to_html) | |
27 | + assert_tag_in_string f.to_html, :tag => 'div', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/onearticle$/ } }, :content => /onearticle/ | |
28 | + assert_tag_in_string f.to_html, :tag => 'div', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/otherarticle$/ } }, :content => /otherarticle/ | |
29 | 29 | end |
30 | 30 | |
31 | 31 | should 'show text body in HTML content' do | ... | ... |
test/unit/recent_documents_block_test.rb
... | ... | @@ -55,4 +55,11 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase |
55 | 55 | assert_match /href=.*\/testinguser\/feed/, output |
56 | 56 | end |
57 | 57 | |
58 | + should 'display a link to sitemap with title "All content"' do | |
59 | + expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) | |
60 | + expects(:_).with('All content').returns('All content') | |
61 | + | |
62 | + instance_eval(&(block.footer)) | |
63 | + end | |
64 | + | |
58 | 65 | end | ... | ... |