From 27482983496cd0b8b6fa7dc943a1b05959735835 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 13 Oct 2023 12:16:18 -0400 Subject: Nice pagination! --- app/assets/stylesheets/main/entries.scss | 50 ++++++++++++++++++++++++++++++++ app/assets/stylesheets/main/layout.scss | 4 +++ app/controllers/blogs_controller.rb | 3 ++ app/controllers/tags_controller.rb | 2 +- app/views/blogs/_list.html.haml | 5 ++++ app/views/blogs/summary.html.haml | 4 +-- app/views/tags/show.html.haml | 6 ++++ 7 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 app/views/blogs/_list.html.haml create mode 100644 app/views/tags/show.html.haml (limited to 'app') diff --git a/app/assets/stylesheets/main/entries.scss b/app/assets/stylesheets/main/entries.scss index 1a42d85..a4e9463 100644 --- a/app/assets/stylesheets/main/entries.scss +++ b/app/assets/stylesheets/main/entries.scss @@ -305,3 +305,53 @@ } } } + +.pagination { + text-align: center; + padding: 0.3em; + cursor: default; + margin-bottom: 1em; + + a, span, em { + padding: 0.2em 0.5em; + } + + .disabled { + color: #aaaaaa; + } + + .current { + font-style: normal; + font-weight: bold; + color: #ff0084; + } + + a { + border: 1px solid #dddddd; + color: #0063dc; + text-decoration: none; + + &:hover, &:focus { + border-color: #003366; + background: #0063dc; + color: white; + } + } + + .page_info { + color: #aaaaaa; + padding-top: 0.8em; + } + + .previous_page, .next_page { + border-width: 2px; + } + + .previous_page { + margin-right: 1em; + } + + .next_page { + margin-left: 1em; + } +} diff --git a/app/assets/stylesheets/main/layout.scss b/app/assets/stylesheets/main/layout.scss index 9283f36..281d820 100644 --- a/app/assets/stylesheets/main/layout.scss +++ b/app/assets/stylesheets/main/layout.scss @@ -203,3 +203,7 @@ blockquote.bubble.bottom::after { .clear { clear: both; } + +h2.centered { + text-align: center; +} diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index c35a05d..39a578a 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -2,6 +2,9 @@ class BlogsController < ApplicationController def summary @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) + if not params[:page] + @main_page = true + end end def index diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index cf5d50b..bceb3cf 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,8 +1,8 @@ class TagsController < ApplicationController def show + @tag_name = params[:name] @blogs = Blog.tagged_with(params[:name]).where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) - render "blogs/summary" end def suggest diff --git a/app/views/blogs/_list.html.haml b/app/views/blogs/_list.html.haml new file mode 100644 index 0000000..3618bdb --- /dev/null +++ b/app/views/blogs/_list.html.haml @@ -0,0 +1,5 @@ +- if not @main_page + = will_paginate @blogs +- @blogs.each do |blog| + = render blog, short: true += will_paginate @blogs diff --git a/app/views/blogs/summary.html.haml b/app/views/blogs/summary.html.haml index e9639ca..79811b1 100644 --- a/app/views/blogs/summary.html.haml +++ b/app/views/blogs/summary.html.haml @@ -1,3 +1 @@ -- @blogs.each do |blog| - = render blog, short: true -= will_paginate @blogs += render "list" diff --git a/app/views/tags/show.html.haml b/app/views/tags/show.html.haml new file mode 100644 index 0000000..1d34b37 --- /dev/null +++ b/app/views/tags/show.html.haml @@ -0,0 +1,6 @@ +- title "Tag #{@tag_name}" +%h2.centered + Blog posts tagged + = surround "\"" do + = @tag_name += render "blogs/list" -- cgit 1.4.1