feat: add header and footer layout components

- Implement header and footer partials for better layout
- Create a full_title helper method for dynamic page titles
- Update application layout to use new header and footer
- Add typography styles for improved text presentation

These changes enhance the overall structure of the application by
introducing reusable header and footer components, which improves
maintainability. The full_title helper method allows for dynamic
titles across different pages, providing a consistent user
experience. Additionally, typography styles have been added to
improve readability and aesthetics.
This commit is contained in:
songtianlun 2024-12-30 17:54:42 +08:00
parent 12e39e2eb4
commit a91fc8f729
9 changed files with 142 additions and 39 deletions

View File

@ -28,3 +28,80 @@ textarea {
.center h1 { .center h1 {
margin-bottom: 10px; margin-bottom: 10px;
} }
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: #777;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: #fff;
text-transform: uppercase;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
}
#logo:hover {
color: #777;
text-decoration: none;
}
img {
display: none;
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid #eaeaea;
color: #777;
}
footer a {
color: #555;
}
footer a:hover {
color: #222;
}
footer small {
float: left;
}
footer ul {
float: right;
list-style: none;
}
footer ul li {
float: left;
margin-left: 15px;
}

View File

@ -1,2 +1,10 @@
module ApplicationHelper module ApplicationHelper
def full_title(page_title = '')
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
page_title + " | " + base_title
end
end
end end

View File

@ -0,0 +1,13 @@
<footer class="footer">
<small>
The <a href="https://www.railstutorial.org">Ruby on Rails Tutorial</a>
by <a href="https://www.michaelhartl.com">Michael Hartl</a>
</small>
<nav>
<ul>
<li><%= link_to "About", '#' %></li>
<li><%= link_to "Contact", '#' %></li>
<li><a href="https://news.railstutorial.org">News</a></li>
</ul>
</nav>
</footer>

View File

@ -0,0 +1,13 @@
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to "sample app", '#', id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", '#' %></li>
<li><%= link_to "Help", '#' %></li>
<li><%= link_to "Login in", '#' %></li>
</ul>
</nav>
</div>
</header>

View File

@ -0,0 +1,21 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= yield :head %>
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<%# Includes all stylesheet files in app/assets/stylesheets %>
<%#= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbo-track': 'reload' %>
<%#= javascript_pack_tag 'application', 'data-turbo-track': 'reload' %>
<%= javascript_importmap_tags %>

View File

@ -0,0 +1,4 @@
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/r29/html5.min.js">
</script>
<![endif]-->

View File

@ -2,48 +2,16 @@
<html> <html>
<head> <head>
<!-- <title><%#= content_for(:title) || "Sample App" %></title>--> <!-- <title><%#= content_for(:title) || "Sample App" %></title>-->
<title><%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title> <title><%= full_title(yield(:title)) %></title>
<meta name="viewport" content="width=device-width,initial-scale=1"> <%= render 'layouts/rails_default' %>
<meta name="apple-mobile-web-app-capable" content="yes"> <%= render 'layouts/shim' %>
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= yield :head %>
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<%# Includes all stylesheet files in app/assets/stylesheets %>
<%#= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "application", media: 'all', 'data-turbo-track': 'reload' %>
<%= javascript_importmap_tags %>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/r29/html5.min.js">
</script>
<![endif]-->
</head> </head>
<body> <body>
<header class="navbar navbar-fixed-top navbar-inverse"> <%= render 'layouts/header' %>
<div class="container">
<%= link_to "sample app", '#', id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", '#' %></li>
<li><%= link_to "Help", '#' %></li>
<li><%= link_to "Login in", '#' %></li>
</ul>
</nav>
</div>
</header>
<div class="container"> <div class="container">
<%= yield %> <%= yield %>
<%= render 'layouts/footer' %>
</div> </div>
</body> </body>
</html> </html>

View File

@ -11,6 +11,6 @@
</div> </div>
<%= link_to image_tag("rails.svg", alt:"Rails logo", width: "200"), <%= link_to image_tag("rails.svg", alt:"Rails logo", width: "200"),
"https://rubyonrails.org/" %> "https://rubyonrails.org/" %>
<%= link_to image_tag("kitten.jpg", alt:"Kitten", width:"200") %> <%#= link_to image_tag("kitten.jpg", alt:"Kitten", width:"200") %>

View File

@ -16,7 +16,6 @@ class StaticPagesControllerTest < ActionDispatch::IntegrationTest
get static_pages_home_url get static_pages_home_url
assert_response :success assert_response :success
assert_select "title", "Home | #{@base_title}" assert_select "title", "Home | #{@base_title}"
assert_select "h1", "Sample App"
end end
test "should get help" do test "should get help" do