-
Notifications
You must be signed in to change notification settings - Fork 0
08 Layout and Style
Dave Strus edited this page Nov 13, 2014
·
4 revisions
Let's add a helper to print flash messages:
app/helpers/application_helper.rb
def flash_messages
flash.map do |key, message|
alert_type = case key
when 'notice' then 'alert-success'
when 'alert' then 'alert-error'
else nil
end
content_tag :p, message, id: 'flash', class: ['alert', alert_type].join(' ')
end.join.html_safe
end
Edit application.html.erb
as follows:
<!DOCTYPE html>
<html>
<head>
<title>Elevennote</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="container wrap">
<div class="row">
<div class="col-xs-12">
<header>
<div class="well">ElevenNote</div>
</header>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-xs-4">
<nav id="sidebar">
<div class="well">
SIDEBAR
</div>
</nav>
</div>
<div class="col-xs-8">
<main>
<div class="well">
<!-- BEGIN main content -->
<%= flash_messages %>
<%= yield %>
</div>
</main>
</div>
</div>
</div>
</div>
</body>
</html>
Create a new stylesheet named style.css.scss
:
$highlight_color: #2dbe60;
body {
font-family: Oxygen, Helvetica, Arial, sans-serif;
}
.container {
width: 100% !important;
padding-left: 0 !important;
padding-right: 0 !important;
}
.row {
margin-left: 0 !important;
margin-right: 0 !important;
}
.col-xs-12 {
padding-left: 0 !important;
padding-right: 0 !important;
}
header .well {
padding-top: 5px;
padding-bottom: 5px;
.user-links {
float: right;
color: #ccc;
}
}
h1, h2, h3, h4, h5 {
font-family: Merriweather;
font-weight: 300;
color: $highlight_color;
}
a:link, a:visited, a:hover, a:active {
color: $highlight_color;
}
.bootsy_text_area {
width: 100%;
border-color: #ccc;
border: none;
font-size: 120%;
&:focus {
outline: none;
}
}
i.fa-trash-o {
color: #ccc;
font-size: 150%;
vertical-align: middle;
margin-left: 1em;
&:hover {
color: #999;
}
}
.wysihtml5-toolbar {
.btn-default {
color: #999;
}
}
input#note_title {
border: none;
font-size: 200%;
font-family: Merriweather;
color: $highlight_color;
font-weight: 300;
width: 100%;
&:focus {
outline: none;
}
}
ul#notes {
list-style: none;
margin-top: 1em;
padding: 0;
width: 100%;
color: #999;
li {
border-top: 1px solid #ddd;
padding: 1em;
height: 100px;
font-size: 90%;
cursor: pointer;
overflow: hidden;
&:first-of-type {
border-top: none;
}
&:hover {
color: white;
background-color: $highlight_color;
.note-title {
color: white;
}
}
.note-title {
color: black;
font-family: Merriweather;
font-size: 120%;
font-weight: 300;
}
.note-body {
height: 54px;
overflow: hidden;
}
}
}
#new_user {
input[type="text"],
input[type="password"] {
width: 300px;
font-size: 120%;
border-radius: 4px;
border: 1px solid #ccc;
padding: 0.25em;
}
}
#welcome {
h1 {
color: $highlight_color
}
main {
margin: 0 auto;
width: 360px;
}
}
span.login {
margin-left: 1em;
}
Let's also add a default route so we have a page we can view in the browser to admire our new layout.
config/routes.rb
root 'welcome#index'
app/controllers/welcome_controller.rb
class WelcomeController < ApplicationController
end
app/views/welcome/index.html
Welcome to Elevennote.