Skip to content

Commit

Permalink
Allow overriding output title by setting page_title (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmer authored and jcypret committed Apr 2, 2017
1 parent 7a4b28e commit 118f4e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/middleman-title/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module Title
module Helpers

def page_title
current_page_title = current_page.data.page_title
return current_page_title unless current_page_title.nil?

title = []
title = add_page_name_to_title(title)
title = add_website_name_to_title(title)
Expand Down
9 changes: 9 additions & 0 deletions spec/extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
h.stub_chain(:current_page, :data, :title).and_return(nil)
h.stub_chain(:current_page, :data, :title_site).and_return(nil)
h.stub_chain(:current_page, :data, :title_reverse).and_return(nil)
h.stub_chain(:current_page, :data, :page_title).and_return(nil)
end

context 'website name is set' do
Expand Down Expand Up @@ -93,5 +94,13 @@

end

context 'page_title is set' do
before(:each) { h.stub_chain(:current_page, :data, :page_title).and_return('This takes precedence') }

it 'returns page_title specified for the current page' do
expect(h.page_title).to eq 'This takes precedence'
end
end

end
end

0 comments on commit 118f4e4

Please sign in to comment.