Commit 71a7f3cd397590026408ab25dc2d51da4f171adc
1 parent
6da3d1f1
Exists in
master
and in
22 other branches
Add class on body when viewing a profile homepage
(ActionItem1988)
Showing
4 changed files
with
45 additions
and
1 deletions
Show diff stats
app/models/profile.rb
@@ -809,6 +809,14 @@ private :generate_url, :url_options | @@ -809,6 +809,14 @@ private :generate_url, :url_options | ||
809 | "#{jid(options)}/#{short_name}" | 809 | "#{jid(options)}/#{short_name}" |
810 | end | 810 | end |
811 | 811 | ||
812 | + def is_on_homepage?(url, page=nil) | ||
813 | + if page | ||
814 | + page == self.home_page | ||
815 | + else | ||
816 | + url == '/' + self.identifier | ||
817 | + end | ||
818 | + end | ||
819 | + | ||
812 | protected | 820 | protected |
813 | 821 | ||
814 | def followed_by?(person) | 822 | def followed_by?(person) |
app/views/layouts/application-ng.rhtml
@@ -22,7 +22,8 @@ | @@ -22,7 +22,8 @@ | ||
22 | # Identify the current controller and action for the CSS: | 22 | # Identify the current controller and action for the CSS: |
23 | " controller-"+ @controller.controller_name() + | 23 | " controller-"+ @controller.controller_name() + |
24 | " action-"+ @controller.controller_name() +"-"+ @controller.action_name() + | 24 | " action-"+ @controller.controller_name() +"-"+ @controller.action_name() + |
25 | - " template-"+ ( profile.nil? ? "default" : profile.layout_template ) | 25 | + " template-"+ ( profile.nil? ? "default" : profile.layout_template ) + |
26 | + (!profile.nil? && profile.is_on_homepage?(request.path,@page) ? " profile-homepage" : "") | ||
26 | %>" > | 27 | %>" > |
27 | 28 | ||
28 | <a href="#content" id="link-go-content"><span><%= _("Go to the content") %></span></a> | 29 | <a href="#content" id="link-go-content"><span><%= _("Go to the content") %></span></a> |
test/functional/content_viewer_controller_test.rb
@@ -1405,4 +1405,20 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -1405,4 +1405,20 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
1405 | assert_tag :tag => 'div', :attributes => { :id => 'article-header' } | 1405 | assert_tag :tag => 'div', :attributes => { :id => 'article-header' } |
1406 | end | 1406 | end |
1407 | 1407 | ||
1408 | + should 'add class to body tag if is on profile homepage' do | ||
1409 | + profile = fast_create(Profile) | ||
1410 | + blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog') | ||
1411 | + profile.home_page = blog | ||
1412 | + profile.save | ||
1413 | + get :view_page, :profile => profile.identifier, :page => ['blog'] | ||
1414 | + assert_tag :tag => 'body', :attributes => { :class => /profile-homepage/ } | ||
1415 | + end | ||
1416 | + | ||
1417 | + should 'not add class to body tag if is not on profile homepage' do | ||
1418 | + profile = fast_create(Profile) | ||
1419 | + blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog') | ||
1420 | + get :view_page, :profile => profile.identifier, :page => ['blog'] | ||
1421 | + assert_no_tag :tag => 'body', :attributes => { :class => /profile-homepage/ } | ||
1422 | + end | ||
1423 | + | ||
1408 | end | 1424 | end |
test/unit/profile_test.rb
@@ -1691,6 +1691,25 @@ class ProfileTest < Test::Unit::TestCase | @@ -1691,6 +1691,25 @@ class ProfileTest < Test::Unit::TestCase | ||
1691 | assert_includes Profile.find_by_contents('thing'), p2 | 1691 | assert_includes Profile.find_by_contents('thing'), p2 |
1692 | end | 1692 | end |
1693 | 1693 | ||
1694 | + should 'know if url is the profile homepage' do | ||
1695 | + profile = fast_create(Profile) | ||
1696 | + | ||
1697 | + assert !profile.is_on_homepage?("/#{profile.identifier}/any_page") | ||
1698 | + assert profile.is_on_homepage?("/#{profile.identifier}") | ||
1699 | + end | ||
1700 | + | ||
1701 | + should 'know if page is the profile homepage' do | ||
1702 | + profile = fast_create(Profile) | ||
1703 | + not_homepage = fast_create(Article, :profile_id => profile.id) | ||
1704 | + | ||
1705 | + homepage = fast_create(Article, :profile_id => profile.id) | ||
1706 | + profile.home_page = homepage | ||
1707 | + profile.save | ||
1708 | + | ||
1709 | + assert !profile.is_on_homepage?("/#{profile.identifier}/#{not_homepage.slug}",not_homepage) | ||
1710 | + assert profile.is_on_homepage?("/#{profile.identifier}/#{homepage.slug}", homepage) | ||
1711 | + end | ||
1712 | + | ||
1694 | private | 1713 | private |
1695 | 1714 | ||
1696 | def assert_invalid_identifier(id) | 1715 | def assert_invalid_identifier(id) |