diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4b0e707..1fae468 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,6 +3,10 @@ module ApplicationHelper bootstrap_classes[flash_type] || flash_type.to_s end + def page_header + content_for(:title) || '' + end + private def bootstrap_classes diff --git a/app/views/application/_navbar.html.slim b/app/views/application/_navbar.html.slim index 754f55f..437764b 100644 --- a/app/views/application/_navbar.html.slim +++ b/app/views/application/_navbar.html.slim @@ -10,8 +10,7 @@ = link_to 'Creddit', root_path, class: 'navbar-brand' .collapse.navbar-collapse ul.nav.navbar-nav - - if @subcreddit && @subcreddit.name - li= link_to @subcreddit.name, @subcreddit + li= page_header ul.nav.navbar-nav.navbar-right - if logged_in? li= link_to 'Sign Out', signout_path diff --git a/app/views/comments/show.html.slim b/app/views/comments/show.html.slim index b55d49f..420f1ba 100644 --- a/app/views/comments/show.html.slim +++ b/app/views/comments/show.html.slim @@ -1,3 +1,4 @@ +- content_for(:title, link_to(@subcreddit.name, @subcreddit)) == render 'posts/post', post: @post .alert.alert-info.in-page p you are viewing a single comment's thread. diff --git a/app/views/posts/show.html.slim b/app/views/posts/show.html.slim index 2a6c2e7..5a86e55 100644 --- a/app/views/posts/show.html.slim +++ b/app/views/posts/show.html.slim @@ -1,3 +1,4 @@ +- content_for(:title, link_to(@subcreddit.name, @subcreddit)) == render 'post', post: @post - if @post.comments? .title= "all #{@post.comments_count} comments" diff --git a/app/views/subcreddits/show.html.slim b/app/views/subcreddits/show.html.slim index cb109f2..6901c4d 100644 --- a/app/views/subcreddits/show.html.slim +++ b/app/views/subcreddits/show.html.slim @@ -1,3 +1,4 @@ +- content_for(:title) { link_to @subcreddit.name, @subcreddit } - if @subcreddit.closed? = "Board has been closed" - else diff --git a/app/views/users/show.html.slim b/app/views/users/show.html.slim index edd0b6a..bef5346 100644 --- a/app/views/users/show.html.slim +++ b/app/views/users/show.html.slim @@ -1,4 +1,4 @@ -h1 #{@user.username} +- content_for(:title, link_to(@user.username, @user)) .comments.contents - @comments.each do |comment| diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 59b4ce6..44dae05 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -26,4 +26,20 @@ describe ApplicationHelper do end end end + + describe '#page_header' do + context 'when title is provided' do + it 'should return the set title' do + allow(helper).to receive(:content_for).with(:title).and_return('Test') + + expect(helper.page_header).to eq 'Test' + end + end + + context 'when title is not provided' do + it 'should return blank' do + expect(helper.page_header).to be_blank + end + end + end end