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
@@ -34,6 +34,10 @@ class ProfileController < ApplicationController | @@ -34,6 +34,10 @@ class ProfileController < ApplicationController | ||
34 | @favorite_enterprises = profile.favorite_enterprises | 34 | @favorite_enterprises = profile.favorite_enterprises |
35 | end | 35 | end |
36 | 36 | ||
37 | + def sitemap | ||
38 | + @articles = profile.top_level_articles | ||
39 | + end | ||
40 | + | ||
37 | protected | 41 | protected |
38 | 42 | ||
39 | def check_access_to_profile | 43 | def check_access_to_profile |
app/helpers/application_helper.rb
@@ -15,6 +15,8 @@ module ApplicationHelper | @@ -15,6 +15,8 @@ module ApplicationHelper | ||
15 | include BlockHelper | 15 | include BlockHelper |
16 | 16 | ||
17 | include DatesHelper | 17 | include DatesHelper |
18 | + | ||
19 | + include FolderHelper | ||
18 | 20 | ||
19 | # Displays context help. You can pass the content of the help message as the | 21 | # Displays context help. You can pass the content of the help message as the |
20 | # first parameter or using template code inside a block passed to this | 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,19 +9,6 @@ module CmsHelper | ||
9 | mime_type.gsub('/', '_').gsub('-', '') | 9 | mime_type.gsub('/', '_').gsub('-', '') |
10 | end | 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 | attr_reader :environment | 12 | attr_reader :environment |
26 | 13 | ||
27 | end | 14 | end |
@@ -0,0 +1,33 @@ | @@ -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,13 +12,14 @@ class Folder < Article | ||
12 | 'folder' | 12 | 'folder' |
13 | end | 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 | include ActionView::Helpers::TagHelper | 16 | include ActionView::Helpers::TagHelper |
17 | include ActionView::Helpers::UrlHelper | 17 | include ActionView::Helpers::UrlHelper |
18 | include ActionController::UrlWriter | 18 | include ActionController::UrlWriter |
19 | + include ActionView::Helpers::AssetTagHelper | ||
20 | + include FolderHelper | ||
19 | def to_html | 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 | end | 23 | end |
23 | 24 | ||
24 | def folder? | 25 | def folder? |
app/models/recent_documents_block.rb
@@ -15,4 +15,11 @@ class RecentDocumentsBlock < Block | @@ -15,4 +15,11 @@ class RecentDocumentsBlock < Block | ||
15 | 15 | ||
16 | end | 16 | end |
17 | 17 | ||
18 | + def footer | ||
19 | + profile = self.owner | ||
20 | + lambda do | ||
21 | + link_to _('All content'), :profile => profile.identifier, :controller => 'profile', :action => 'sitemap' | ||
22 | + end | ||
23 | + end | ||
24 | + | ||
18 | end | 25 | end |
app/views/cms/view.rhtml
1 | +<h1> | ||
2 | + <%= icon('cms') %> | ||
3 | + <%= _('Content management') %> | ||
4 | +</h1> | ||
5 | + | ||
1 | <% if @article %> | 6 | <% if @article %> |
2 | <h1 id='article-full-path'> | 7 | <h1 id='article-full-path'> |
3 | <%= icon('cms') %> | 8 | <%= icon('cms') %> |
4 | <%= link_to profile.identifier, :action => 'index' %> | 9 | <%= link_to profile.identifier, :action => 'index' %> |
5 | <%= @article.hierarchy.map {|item| " / " + ((item == @article) ? item.name : link_to(item.name, :id => item.id)) } %> | 10 | <%= @article.hierarchy.map {|item| " / " + ((item == @article) ? item.name : link_to(item.name, :id => item.id)) } %> |
6 | </h1> | 11 | </h1> |
7 | -<% else %> | ||
8 | - <h1> | ||
9 | - <%= icon('cms') %> | ||
10 | - <%= _('Content management') %> | ||
11 | - </h1> | ||
12 | <% end %> | 12 | <% end %> |
13 | 13 | ||
14 | <% button_bar(:style => 'margin-bottom: 1em;') do %> | 14 | <% button_bar(:style => 'margin-bottom: 1em;') do %> |
app/views/profile/index.rhtml
@@ -30,6 +30,10 @@ | @@ -30,6 +30,10 @@ | ||
30 | <% end %> | 30 | <% end %> |
31 | 31 | ||
32 | <li> | 32 | <li> |
33 | + <%= link_to _('Site map'), :action => 'sitemap' %> | ||
34 | + </li> | ||
35 | + | ||
36 | + <li> | ||
33 | <%= _('Tags:') %> | 37 | <%= _('Tags:') %> |
34 | <%= tag_cloud @tags, :id, { :action => 'tag' }, :max_size => 18, :min_size => 10%> | 38 | <%= tag_cloud @tags, :id, { :action => 'tag' }, :max_size => 18, :min_size => 10%> |
35 | </li> | 39 | </li> |
public/stylesheets/common.css
@@ -239,6 +239,10 @@ table.cms-articles th, table.cms-articles td { | @@ -239,6 +239,10 @@ table.cms-articles th, table.cms-articles td { | ||
239 | border: 1px solid #e0e0e0; | 239 | border: 1px solid #e0e0e0; |
240 | } | 240 | } |
241 | 241 | ||
242 | +table.noborder th, table.noborder td{ | ||
243 | + border: none; | ||
244 | +} | ||
245 | + | ||
242 | /* for fields with auto-completion */ | 246 | /* for fields with auto-completion */ |
243 | div.auto-complete { | 247 | div.auto-complete { |
244 | display: block; | 248 | display: block; |
@@ -284,3 +288,18 @@ div.pending-tasks { | @@ -284,3 +288,18 @@ div.pending-tasks { | ||
284 | margin: 1em; | 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,4 +232,14 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
232 | assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ | 232 | assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ |
233 | end | 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 | end | 245 | end |
@@ -0,0 +1,18 @@ | @@ -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,8 +24,8 @@ class FolderTest < ActiveSupport::TestCase | ||
24 | f.children.create!(:profile => p, :name => 'onearticle') | 24 | f.children.create!(:profile => p, :name => 'onearticle') |
25 | f.children.create!(:profile => p, :name => 'otherarticle') | 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 | end | 29 | end |
30 | 30 | ||
31 | should 'show text body in HTML content' do | 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,4 +55,11 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase | ||
55 | assert_match /href=.*\/testinguser\/feed/, output | 55 | assert_match /href=.*\/testinguser\/feed/, output |
56 | end | 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 | end | 65 | end |