Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from bthuilot/fixing_styling
Browse files Browse the repository at this point in the history
Fixing styling
  • Loading branch information
bthuilot authored Jul 23, 2019
2 parents 3b8d2f8 + 98804e1 commit 7d43b78
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 86 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ gem 'bootsnap', '>= 1.1.0', require: false

# Styles
gem 'jquery-rails'
gem 'material_icons'
gem 'bootstrap', '4.1.1'
gem 'material-sass', '4.1.1'
gem 'octicons_helper'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
13 changes: 6 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ GEM
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
material-sass (4.1.1)
autoprefixer-rails (>= 6.0.3)
sass (>= 3.5.2)
material_icons (2.2.1)
railties (>= 3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
Expand All @@ -144,6 +139,11 @@ GEM
nio4r (2.3.1)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
octicons (9.1.1)
nokogiri (>= 1.6.3.1)
octicons_helper (9.1.1)
octicons (= 9.1.1)
rails
popper_js (1.14.5)
public_suffix (3.0.3)
puma (3.12.1)
Expand Down Expand Up @@ -266,10 +266,9 @@ DEPENDENCIES
jbuilder (~> 2.5)
jquery-rails
listen (>= 3.0.5, < 3.2)
material-sass (= 4.1.1)
material_icons
minitest
minitest-reporters
octicons_helper
puma (~> 3.11)
rails (~> 5.2.2)
rails-controller-testing
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
//= require jquery
//= require popper
//= require bootstrap
//= require material
//= require_tree .
22 changes: 11 additions & 11 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@
*
*= require_tree .
*= require_self
*= require material_icons
*/
@import "material";
@import "bootstrap";

$NORMAL_TEXT_COLOR: rgba(0, 0, 0, 0.87);
$WHITE_TEXT: white;
$INVISIBLE_TEXT: rgba(0, 0, 0, 0);


#header {
margin-bottom: 50px;
}

.no-underline-link {
text-decoration: none !important;
}


.accordion {
width: 100% !important;
}

.black-link {
color: $NORMAL_TEXT_COLOR
}
Expand All @@ -41,10 +40,11 @@ $INVISIBLE_TEXT: rgba(0, 0, 0, 0);
border-color: $INVISIBLE_TEXT;
}

.navbar-dark select {
background-image: url('data:image/svg+xml;charset=utf8,%3Csvg fill="%23FFFFFF" fill-opacity="1" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"%3E%3Cpath d="M7 10l5 5 5-5z"/%3E%3Cpath d="M0 0h24v24H0z" fill="none"/%3E%3C/svg%3E');
}

.navbar-search-select option {
color: $NORMAL_TEXT_COLOR;
}

.align-icon {
display: inline-flex;
vertical-align: middle;
}
4 changes: 0 additions & 4 deletions app/assets/stylesheets/posts.scss
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
.breadcrumb-post i {
display: inline-flex;
vertical-align: middle;
}
6 changes: 3 additions & 3 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def get_all_categories

def get_search_results
if params[:search]
search_term = params[:search][:term]
search_category_id = /\A\d+\z/.match(params[:search][:category]) ? params[:search][:category].to_i : nil
@search_term = params[:search][:term]
@search_category_id = /\A\d+\z/.match(params[:search][:category]) ? params[:search][:category].to_i : nil
end
Post.search(search_term, search_category_id)
Post.search(@search_term, @search_category_id)
end

def get_search_page
Expand Down
1 change: 1 addition & 0 deletions app/models/system_page.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class SystemPage < ApplicationRecord
validates :name, uniqueness: true, presence: true, length: {maximum: 50}
end
14 changes: 8 additions & 6 deletions app/views/categories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
<div class="col-9">
<h1 class="category-title"><%= @category.name %></h1>
</div>
<div class="col-3 text-center pull-right">
<a href="<%= edit_categories_url(@category) %>" role="button" class="btn btn-success align-middle">Edit
Category</a>
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteCategoryModal">
Delete Category
</button>
<div class="col-3 text-right pull-right">
<a href="<%= new_post_url %>" role="button" class="mx-2">
<%= octicon "plus", height: 32 %></a>
<a href="<%= edit_categories_url(@category) %>" role="button" class="mx-2">
<%= octicon "pencil", height: 32 %></a>
<a href='#' data-toggle="modal" data-target="#deleteCategoryModal" class="mx-2">
<%= octicon "trashcan", height: 32 %>
</a>
<!-- Confirm Delete Modal -->
<div class="modal fade" id="deleteCategoryModal" tabindex="-1" role="dialog" aria-labelledby="deleteCategoryModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
Expand Down
9 changes: 1 addition & 8 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nav id="header" class="navbar navbar-expand-lg navbar-dark bg-dark">
<nav id="header" class="navbar navbar-expand-lg navbar-dark bg-dark mb-5">
<a class="navbar-brand" href="/">Pearl Wiki</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand Down Expand Up @@ -46,14 +46,7 @@
</li>
</ul>

<!-- TODO Fix styling for dropdown -->
<%= form_for :search, method: :get, html: {class: 'form-inline my-2 my-lg-0 navbar-search-select'}, url: '/search' do |form| %>
<%= form.select :category, Category.all.collect {|c| [c.name, c.id]}, {include_blank: 'All Categories'}, {class: 'custom-select navbar-dark select-no-border'} %>

<%= form.text_field :term, class: 'form-control mr-sm-2', placeholder: "Search" %>
<br>
<%= form.submit :search, class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %>
</div>
</nav>

75 changes: 58 additions & 17 deletions app/views/layouts/_sidebar.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
<nav class="flex-column">
<h3>Categories</h3>
<hr/>
<% @categories.each do |category| %>
<a class='no-underline-link' data-toggle="collapse" href="#collapse-<%= category.name.parameterize %>-dropdown" role="button" aria-expanded="false" aria-controls="collapse-<%= category.name.parameterize %>-dropdown">
<h4 class="text-muted"><%= category.name %> <i data-toggle="collapse" class="material-icons">arrow_drop_down</i>
</h4>
</a>
<div class="collapse" id="collapse-<%= category.name.parameterize %>-dropdown">
<% category.posts.each do |post| %>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="<%= post_url(post) %>"><%= post.title %></a>
</li>
</ul>
<nav data-spy="scroll" class="navbar navbar-expand-md flex-column pt-0 px-0">
<div class="row">
<div class="col-md-12 col-11">
<%= form_for :search, method: :get, url: '/search' do |form| %>
<div class="form-row">
<div class="form-group col-md-12 col-6">
<%= form.text_field :term, class: 'form-control', placeholder: "Search Posts..." %>
</div>
<div class="form-group col-md-8 col-4">
<%= form.select :category, Category.all.collect {|c| [c.name, c.id]}, {include_blank: 'All Categories'}, {class: 'custom-select'} %>
</div>
<div class="form-group col-md-4 col-2">
<%= form.submit :search, value: "Search", class: 'btn btn-primary' %>
</div>

</div>
<% end %>
</div>
<% end %>
</nav>
<div class="col-md-12 col-1">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#sidebarCollapse" aria-controls="sidebarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<%= octicon "three-bars", height: 32 %>
</button>
</div>
</div>
<div class="collapse navbar-collapse" id="sidebarCollapse">
<div class="row">
<% @categories.each do |category| %>
<div class="col-12">
<div class="accordion mt-2" id="category-accordion">
<div class="card">
<div class="card-header" id="category-<%= category.id %>-heading">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#category-<%= category.id %>-collapse" aria-expanded="true" aria-controls="category-<%= category.id %>-collapse">
<%= category.name %>
</button>
</h2>
</div>

<div id="category-<%= category.id %>-collapse" class="collapse
<% if (@category && @category.id == category.id) || (@post && @post.category && @post.category.id == category.id) %>show
<% end %>" aria-labelledby="category" data-parent="#category-accordion">
<div class="card-body">
<ul class="nav flex-column">
<% category.posts.each do |post| %>
<li class="nav-item">
<a class="nav-link
<% if @post && @post.id == post.id %>
<% end %>" href="<%= post_path(post) %>"><%= post.title %></a>
</li>
<% end %>
</ul>
</div>
</div>
</div>
</div>
</div>
<% end %>
</div>
</div>
</nav>
6 changes: 4 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<html>
<head>
<title><%= yield(:title) %> | PearlWiki</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
Expand Down Expand Up @@ -34,10 +36,10 @@
<% end %>

<div class="row">
<div class="col-2">
<div class="col-12 col-md-4 col-xl-2">
<%= render 'layouts/sidebar' %>
</div>
<div class="col-9">
<div class="col-12 col-md-7 col-xl-9">
<%= yield %>
</div>
</div>
Expand Down
15 changes: 7 additions & 8 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
<a class="black-link no-underline-link" href="<%= categories_url(@post.category) %>">
<%= @post.category.name %>
</a>
<span class="breadcrumb-post">
<i class="material-icons">keyboard_arrow_right</i>
<span class="align-icon">
<%= octicon "chevron-right", height: 32 %>
</span>
<%= @post.title %>
</h1>
</ol>
</div>
<div class="col-3 text-center">
<a href="<%= edit_post_url(@post) %>" role="button" class="btn btn-success align-middle">
Edit Post
</a>
<div class="col-3 text-right pull-right">
<a href="<%= edit_post_url(@post) %>" role="button" class="mx-2">
<%= octicon "pencil", height: 32 %></a>
<a data-confirm="Are you sure you want to delete this page?"
data-method="delete" href="/page/<%= @post.id %>" role="button" class="btn btn-danger align-middle">
Delete Post
data-method="delete" href="/page/<%= @post.id %>" role="button" class="mx-2">
<%= octicon "trashcan", height: 32 %>
</a>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/search/search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<div class="col-12">
<div class="form-row">
<div class="form-group col-md-10 col-sm-12">
<%= form.text_field :term, class: "form-control", placeholder: 'Search' %>
<%= form.text_field :term, class: "form-control", value: @search_term, placeholder: 'Search' %>
</div>
<div class="form-group col-md-2 col-sm-6">
<%= form.select :category, Category.all.collect {|c| [c.name, c.id]}, {include_blank: 'All Categories'}, {class: 'form-control custom-select'} %>
<%= form.select :category, Category.all.collect {|c| [c.name, c.id]}, {include_blank: 'All Categories', selected: @search_category_id}, {class: 'form-control custom-select'} %>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/views/static_pages/about.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<div class="col-9">
<h1 class="category-title">About</h1>
</div>
<div class="col-3 text-center">
<a href="<%= edit_about_url %>" role="button" class="btn btn-success align-middle">Edit
Page</a>
<div class="col-3 text-right pull-right">
<a href="<%= edit_about_url %>" role="button" class="mx-2">
<%= octicon "pencil", height: 32 %></a>
</div>
</div>
<div class="row justify-content-center">
Expand Down
6 changes: 3 additions & 3 deletions app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<div class="col-9">
<h1 class="category-title">Home</h1>
</div>
<div class="col-3 text-center">
<a href="<%= edit_home_url %>" role="button" class="btn btn-success align-middle">Edit
Page</a>
<div class="col-3 text-right pull-right">
<a href="<%= edit_home_url %>" role="button" class="mx-2">
<%= octicon "pencil", height: 32 %></a>
</div>
</div>
<div class="row justify-content-center">
Expand Down
29 changes: 26 additions & 3 deletions test/models/category_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
require 'test_helper'

class CategoryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end

setup do
@category = Category.new({name: "Test Category", homepage: "# Hello World!!"})
end

test "Valid category" do
assert @category.valid?, "Category with unique name and a homepage"
end

test "Category missing name" do
@category.name = nil
refute @category.valid?, "Category with missing name"
assert_not_nil @category.errors[:name]
end

test "Category non unique name" do
@category.name = "Finance Category"
refute @category.valid?, "Category with duplicate name"
assert_not_nil @category.errors[:name]
end

test "Category name longer than 50 characters" do
@category.name = "-" * 51
refute @category.valid?, "Category with name longer than 50"
assert_not_nil @category.errors[:name]
end
end
27 changes: 24 additions & 3 deletions test/models/post_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
require 'test_helper'

class PostTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
setup do
@post = Post.new({title: "Test Post", contents: "# Hello World!!", category: categories(:dev_ops)})
end

test "Valid post" do
assert @post.valid?, "Post with title, category, and a contents"
end

test "Post is missing category" do
@post.category = nil
refute @post.valid?
end

test "Post missing title" do
@post.title = nil
refute @post.valid?, "Post with missing title"
assert_not_nil @post.errors[:title]
end

test "Post title longer than 50 characters" do
@post.title = "-" * 51
refute @post.valid?, "Post with title longer than 50"
assert_not_nil @post.errors[:title]
end
end
Loading

0 comments on commit 7d43b78

Please sign in to comment.