diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 280071a..d50858c 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -34,6 +34,10 @@ class ProfileController < ApplicationController @favorite_enterprises = profile.favorite_enterprises end + def sitemap + @articles = profile.top_level_articles + end + protected def check_access_to_profile diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 73cc18f..4268d24 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -15,6 +15,8 @@ module ApplicationHelper include BlockHelper include DatesHelper + + include FolderHelper # Displays context help. You can pass the content of the help message as the # first parameter or using template code inside a block passed to this diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index d053fdd..ff94bdc 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -9,19 +9,6 @@ module CmsHelper mime_type.gsub('/', '_').gsub('-', '') end - def icon_for_article(article) - icon = article.icon_name - if (icon =~ /\//) - icon - else - if File.exists?(File.join(RAILS_ROOT, 'public', 'images', 'icons-mime', "#{icon}.png")) - "icons-mime/#{icon}.png" - else - "icons-mime/unknown.png" - end - end - end - attr_reader :environment end diff --git a/app/helpers/folder_helper.rb b/app/helpers/folder_helper.rb new file mode 100644 index 0000000..1a07926 --- /dev/null +++ b/app/helpers/folder_helper.rb @@ -0,0 +1,33 @@ +module FolderHelper + + def list_articles(articles, recursive = false) + articles.map {|item| display_article_in_listing(item, recursive, 0)}.join('') + end + + def display_article_in_listing(article, recursive = false, level = 0) + result = content_tag( + 'div', + link_to((' ' * (level * 4) ) + image_tag(icon_for_article(article)) + article.name, article.url), + :class => 'sitemap-item' + ) + if recursive + result + article.children.map {|item| display_article_in_listing(item, recursive, level + 1) }.join('') + else + result + end + end + + def icon_for_article(article) + icon = article.icon_name + if (icon =~ /\//) + icon + else + if File.exists?(File.join(RAILS_ROOT, 'public', 'images', 'icons-mime', "#{icon}.png")) + "icons-mime/#{icon}.png" + else + "icons-mime/unknown.png" + end + end + end + +end diff --git a/app/models/folder.rb b/app/models/folder.rb index b4c15c5..7b54449 100644 --- a/app/models/folder.rb +++ b/app/models/folder.rb @@ -12,13 +12,14 @@ class Folder < Article 'folder' end - # FIXME we should not need all this just to write a link + # FIXME isn't this too much including just to be able to generate some HTML? include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper include ActionController::UrlWriter + include ActionView::Helpers::AssetTagHelper + include FolderHelper def to_html - content_tag('div', body) + - content_tag('ul', children.map { |child| content_tag('li', link_to(child.name, child.url)) }, :class => 'folder-listing') + content_tag('div', body) + tag('hr') + list_articles(children) end def folder? diff --git a/app/models/recent_documents_block.rb b/app/models/recent_documents_block.rb index aed4727..6b58456 100644 --- a/app/models/recent_documents_block.rb +++ b/app/models/recent_documents_block.rb @@ -15,4 +15,11 @@ class RecentDocumentsBlock < Block end + def footer + profile = self.owner + lambda do + link_to _('All content'), :profile => profile.identifier, :controller => 'profile', :action => 'sitemap' + end + end + end diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml index d92be01..63c2af0 100644 --- a/app/views/cms/view.rhtml +++ b/app/views/cms/view.rhtml @@ -1,14 +1,14 @@ +

+ <%= icon('cms') %> + <%= _('Content management') %> +

+ <% if @article %>

<%= icon('cms') %> <%= link_to profile.identifier, :action => 'index' %> <%= @article.hierarchy.map {|item| " / " + ((item == @article) ? item.name : link_to(item.name, :id => item.id)) } %>

-<% else %> -

- <%= icon('cms') %> - <%= _('Content management') %> -

<% end %> <% button_bar(:style => 'margin-bottom: 1em;') do %> diff --git a/app/views/profile/index.rhtml b/app/views/profile/index.rhtml index 82f8587..b1804af 100644 --- a/app/views/profile/index.rhtml +++ b/app/views/profile/index.rhtml @@ -30,6 +30,10 @@ <% end %>
  • + <%= link_to _('Site map'), :action => 'sitemap' %> +
  • + +
  • <%= _('Tags:') %> <%= tag_cloud @tags, :id, { :action => 'tag' }, :max_size => 18, :min_size => 10%>
  • diff --git a/app/views/profile/sitemap.rhtml b/app/views/profile/sitemap.rhtml new file mode 100644 index 0000000..09b970e --- /dev/null +++ b/app/views/profile/sitemap.rhtml @@ -0,0 +1,3 @@ +

    <%= _("%s: site map") % profile.name %>

    + +<%= list_articles(@articles, true) %> diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index 9fb2abc..7989334 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -239,6 +239,10 @@ table.cms-articles th, table.cms-articles td { border: 1px solid #e0e0e0; } +table.noborder th, table.noborder td{ + border: none; +} + /* for fields with auto-completion */ div.auto-complete { display: block; @@ -284,3 +288,18 @@ div.pending-tasks { margin: 1em; } +/* sitemap */ +div.sitemap-item a:link, +div.sitemap-item a:visited { + display: block; + border: none; + text-decoration: none; +} +div.sitemap-item img { + border: none; +} +div.sitemap-item a:hover { + background-color: #f0f0f0; + color: red; +} + diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 0912505..2225a53 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -232,4 +232,14 @@ class ProfileControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ end + should 'display "Site map" link for profiles' do + get :index, :profile => 'ze' + assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/ze/sitemap' } + end + + should 'list top level articles in sitemap' do + get :sitemap, :profile => 'testuser' + assert_equal @profile.top_level_articles, assigns(:articles) + end + end diff --git a/test/unit/folder_helper_test.rb b/test/unit/folder_helper_test.rb new file mode 100644 index 0000000..c0cb378 --- /dev/null +++ b/test/unit/folder_helper_test.rb @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FolderHelperTest < Test::Unit::TestCase + + include FolderHelper + + should 'display icon for articles' do + art1 = mock; art1.expects(:icon_name).returns('icon1') + art2 = mock; art2.expects(:icon_name).returns('icon2') + + File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'images', 'icons-mime', 'icon1.png')).returns(true) + File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'images', 'icons-mime', 'icon2.png')).returns(false) + + assert_equal 'icons-mime/icon1.png', icon_for_article(art1) + assert_equal 'icons-mime/unknown.png', icon_for_article(art2) + end + +end diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb index 7b73daf..92d377a 100644 --- a/test/unit/folder_test.rb +++ b/test/unit/folder_test.rb @@ -24,8 +24,8 @@ class FolderTest < ActiveSupport::TestCase f.children.create!(:profile => p, :name => 'onearticle') f.children.create!(:profile => p, :name => 'otherarticle') - assert_match(/
  • onearticle<\/a><\/li>/, f.to_html) - assert_match(/
  • otherarticle<\/a><\/li>/, f.to_html) + assert_tag_in_string f.to_html, :tag => 'div', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/onearticle$/ } }, :content => /onearticle/ + assert_tag_in_string f.to_html, :tag => 'div', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/otherarticle$/ } }, :content => /otherarticle/ end should 'show text body in HTML content' do diff --git a/test/unit/recent_documents_block_test.rb b/test/unit/recent_documents_block_test.rb index 463acc5..91f9e56 100644 --- a/test/unit/recent_documents_block_test.rb +++ b/test/unit/recent_documents_block_test.rb @@ -55,4 +55,11 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase assert_match /href=.*\/testinguser\/feed/, output end + should 'display a link to sitemap with title "All content"' do + expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) + expects(:_).with('All content').returns('All content') + + instance_eval(&(block.footer)) + end + end -- libgit2 0.21.2