Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add page_title helper
  • Loading branch information
mjankowski committed Sep 2, 2011
1 parent ae7d28b commit 80a724d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/helpers/page_title_helper.rb
@@ -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
27 changes: 27 additions & 0 deletions spec/helpers/page_title_helper_spec.rb
@@ -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

0 comments on commit 80a724d

Please sign in to comment.