Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add page_title helper
- Loading branch information
1 parent
ae7d28b
commit 80a724d
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module PageTitleHelper | ||
def page_title(options = {}) | ||
app_name = options[:app_name] || Rails.application.class.to_s.split('::').first | ||
page_title_symbol = options[:page_title_symbol] || :page_title | ||
separator = options[:separator] || ' : ' | ||
|
||
if content_for?(page_title_symbol) | ||
[app_name, content_for(page_title_symbol)].join(separator) | ||
else | ||
app_name | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
describe PageTitleHelper do | ||
describe "#page_title with no options" do | ||
subject { helper.page_title } | ||
it { should == "Dummy" } | ||
end | ||
describe "#page_title with site name" do | ||
subject { helper.page_title(app_name: 'Test') } | ||
it { should == "Test" } | ||
end | ||
describe "#page_title with content for page title" do | ||
before { helper.content_for(:page_title, 'page title') } | ||
subject { helper.page_title } | ||
it { should == "Dummy : page title" } | ||
end | ||
describe "#page_title with content for page title and alternate separator" do | ||
before { helper.content_for(:page_title, 'page title') } | ||
subject { helper.page_title(separator: ' | ') } | ||
it { should == "Dummy | page title" } | ||
end | ||
describe "#page_title with content for alternate symbol" do | ||
before { helper.content_for(:alt_page_title, 'page title') } | ||
subject { helper.page_title(page_title_symbol: :alt_page_title) } | ||
it { should == "Dummy : page title" } | ||
end | ||
end |