Refactor page header code
This commit is contained in:
parent
c880ba31b8
commit
b68960efe5
7 changed files with 25 additions and 3 deletions
|
@ -3,6 +3,10 @@ module ApplicationHelper
|
||||||
bootstrap_classes[flash_type] || flash_type.to_s
|
bootstrap_classes[flash_type] || flash_type.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def page_header
|
||||||
|
content_for(:title) || ''
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def bootstrap_classes
|
def bootstrap_classes
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
= link_to 'Creddit', root_path, class: 'navbar-brand'
|
= link_to 'Creddit', root_path, class: 'navbar-brand'
|
||||||
.collapse.navbar-collapse
|
.collapse.navbar-collapse
|
||||||
ul.nav.navbar-nav
|
ul.nav.navbar-nav
|
||||||
- if @subcreddit && @subcreddit.name
|
li= page_header
|
||||||
li= link_to @subcreddit.name, @subcreddit
|
|
||||||
ul.nav.navbar-nav.navbar-right
|
ul.nav.navbar-nav.navbar-right
|
||||||
- if logged_in?
|
- if logged_in?
|
||||||
li= link_to 'Sign Out', signout_path
|
li= link_to 'Sign Out', signout_path
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
- content_for(:title, link_to(@subcreddit.name, @subcreddit))
|
||||||
== render 'posts/post', post: @post
|
== render 'posts/post', post: @post
|
||||||
.alert.alert-info.in-page
|
.alert.alert-info.in-page
|
||||||
p you are viewing a single comment's thread.
|
p you are viewing a single comment's thread.
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
- content_for(:title, link_to(@subcreddit.name, @subcreddit))
|
||||||
== render 'post', post: @post
|
== render 'post', post: @post
|
||||||
- if @post.comments?
|
- if @post.comments?
|
||||||
.title= "all #{@post.comments_count} comments"
|
.title= "all #{@post.comments_count} comments"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
- content_for(:title) { link_to @subcreddit.name, @subcreddit }
|
||||||
- if @subcreddit.closed?
|
- if @subcreddit.closed?
|
||||||
= "Board has been closed"
|
= "Board has been closed"
|
||||||
- else
|
- else
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
h1 #{@user.username}
|
- content_for(:title, link_to(@user.username, @user))
|
||||||
|
|
||||||
.comments.contents
|
.comments.contents
|
||||||
- @comments.each do |comment|
|
- @comments.each do |comment|
|
||||||
|
|
|
@ -26,4 +26,20 @@ describe ApplicationHelper do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue