Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add page_title helper

  • Loading branch information...
commit 80a724df1a1b5e76245dc2c7cb53bb864aaa8242 1 parent ae7d28b
Matt Jankowski mjankowski authored
13 app/helpers/page_title_helper.rb
View
@@ -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 spec/helpers/page_title_helper_spec.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.