Permalink
Browse files

Add a title helper

  • Loading branch information...
1 parent 973d6a0 commit f69e8b9b10a8e582916bcaae717d5fac7a31acd2 @kdironside committed May 18, 2012
View
@@ -12,11 +12,12 @@
# Ignore all logfiles and tempfiles.
/log/*.log
-/tmp/*
+/tmp
# Ignore other unneeded files.
doc/
*.swp
*~
.project
-.DS_Store
+.DS_Store
+bundler_stubs/
View
@@ -8,6 +8,7 @@ gem 'rails', '3.2.3'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.9.0'
+ gem 'guard-rspec', '0.5.5'
end
group :test do
View
@@ -52,6 +52,11 @@ GEM
execjs (1.3.2)
multi_json (~> 1.0)
ffi (1.0.11)
+ guard (1.0.3)
+ ffi (>= 0.5.0)
+ thor (>= 0.14.6)
+ guard-rspec (0.5.5)
+ guard (>= 0.8.4)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
@@ -143,6 +148,7 @@ PLATFORMS
DEPENDENCIES
capybara (= 1.1.2)
coffee-rails (~> 3.2.1)
+ guard-rspec (= 0.5.5)
jquery-rails
pg (= 0.12.2)
rails (= 3.2.3)
@@ -1,2 +1,12 @@
module ApplicationHelper
+
+ # Returns the full title on a per-page basis.
+ def full_title(page_title)
+ base_title = "Ruby on Rails Tutorial Sample App"
+ if page_title.empty?
+ base_title
+ else
+ "#{base_title} | #{page_title}"
+ end
+ end
end
@@ -3,7 +3,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
+ <title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
@@ -1,4 +1,3 @@
-<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page for the
@@ -9,10 +9,15 @@
page.should have_selector('h1', :text => 'Sample App')
end
- it "should have the title 'Home'" do
+ it "should have the base title" do
visit '/static_pages/home'
page.should have_selector('title',
- :text => "Ruby on Rails Tutorial Sample App | Home")
+ :text => "Ruby on Rails Tutorial Sample App")
+ end
+
+ it "should not have a custom page title" do
+ visit '/static_pages/home'
+ page.should_not have_selector('title', :text => '| Home')
end
end

0 comments on commit f69e8b9

Please sign in to comment.