Browse Source

Add full_title helper

Frans Bergman 7 years ago
parent
commit
3fa9af3839

+ 9 - 0
app/helpers/application_helper.rb

@@ -1,2 +1,11 @@
 module ApplicationHelper
+  # Returns the full title on a per-page basis.
+  def full_title(page_title = '')
+    base_title = "School Platform"
+    if page_title.empty?
+      base_title
+    else
+      page_title + " | " + base_title
+    end
+  end
 end

+ 1 - 1
app/views/layouts/application.html.erb

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
   <head>
-    <title>SchoolPlatform</title>
+    <title><%= full_title(yield(:title)) %></title>
     <%= csrf_meta_tags %>
 
     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>

+ 1 - 0
app/views/static_pages/about.html.erb

@@ -1,3 +1,4 @@
+<%= provide(:title, "About") %>
 <h1>About</h1>
 <p>
   School Platform, abbreviated as <i>SchPlat</i>, <i>SPlat</i> or simply

+ 1 - 0
app/views/static_pages/home.html.erb

@@ -1,2 +1,3 @@
+<%= provide(:title, "Home") %>
 <h1>StaticPages#home</h1>
 <p>Find me in app/views/static_pages/home.html.erb</p>

+ 2 - 0
test/controllers/static_pages_controller_test.rb

@@ -4,11 +4,13 @@ class StaticPagesControllerTest < ActionDispatch::IntegrationTest
   test "should get home" do
     get home_url
     assert_response :success
+    assert_select "title", "Home | School Platform"
   end
 
   test "should get about" do
     get about_url
     assert_response :success
+    assert_select "title", "About | School Platform"
   end
 
 end