From a9c27377138ddef54435e8757dd695941d2aad0d Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Thu, 16 Mar 2023 14:27:30 -0400 Subject: [PATCH] Started working on a blog for the website; adjusted some styles --- Gemfile | 3 +++ Gemfile.lock | 3 +++ app/assets/stylesheets/lumbridge.sass.erb | 9 +++++++++ app/controllers/blog_controller.rb | 9 +++++++++ app/models/post.rb | 7 +++++++ app/views/blog/index.html.erb | 14 ++++++++++++++ app/views/blog/show.html.erb | 8 ++++++++ app/views/layouts/application.html.erb | 1 + config/routes.rb | 3 +++ db/migrate/20230316173633_create_posts.rb | 11 +++++++++++ db/schema.rb | 22 ++++++++++++++++++++++ test/fixtures/posts.yml | 11 +++++++++++ test/models/post_test.rb | 7 +++++++ 13 files changed, 108 insertions(+) create mode 100644 app/controllers/blog_controller.rb create mode 100644 app/models/post.rb create mode 100644 app/views/blog/index.html.erb create mode 100644 app/views/blog/show.html.erb create mode 100644 db/migrate/20230316173633_create_posts.rb create mode 100644 db/schema.rb create mode 100644 test/fixtures/posts.yml create mode 100644 test/models/post_test.rb diff --git a/Gemfile b/Gemfile index 5e121b6..37ba7a5 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,9 @@ gem "sassc-rails" # Use CoffeeScript to process JS gem "coffee-rails" +# Kramdown gem to convert Markdown to HTML +gem "kramdown", "~> 2.4" + # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" diff --git a/Gemfile.lock b/Gemfile.lock index ec5fbe2..7cc99b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,6 +111,8 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) + kramdown (2.4.0) + rexml loofah (2.18.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -238,6 +240,7 @@ DEPENDENCIES debug importmap-rails jbuilder + kramdown (~> 2.4) puma (~> 6.1) rails (~> 7.0) sassc-rails diff --git a/app/assets/stylesheets/lumbridge.sass.erb b/app/assets/stylesheets/lumbridge.sass.erb index 18cd763..b3c4490 100644 --- a/app/assets/stylesheets/lumbridge.sass.erb +++ b/app/assets/stylesheets/lumbridge.sass.erb @@ -34,6 +34,7 @@ hr margin: 0 padding: 0 background: white + box-shadow: 0px 80px 50px -30px rgba(0, 0, 0, 0.15) // header @@ -135,13 +136,21 @@ hr li padding: 15px 20px 0 border: 2px solid #bbb + border-radius: 8px + box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2) .post-title margin-bottom: 3px + text-decoration: underline .post-body margin-bottom: 0 +#post-header + #post-author + color: #999 + font-style: italic + // footer section #footer diff --git a/app/controllers/blog_controller.rb b/app/controllers/blog_controller.rb new file mode 100644 index 0000000..9f35402 --- /dev/null +++ b/app/controllers/blog_controller.rb @@ -0,0 +1,9 @@ +class BlogController < ApplicationController + def index + @posts = Post.all() + end + + def show + @post = Post.find(params[:id]) + end +end diff --git a/app/models/post.rb b/app/models/post.rb new file mode 100644 index 0000000..cffb445 --- /dev/null +++ b/app/models/post.rb @@ -0,0 +1,7 @@ +class Post < ApplicationRecord + + def renderBody() + Kramdown::Document.new(self.body).to_html() + end + +end diff --git a/app/views/blog/index.html.erb b/app/views/blog/index.html.erb new file mode 100644 index 0000000..feebf3c --- /dev/null +++ b/app/views/blog/index.html.erb @@ -0,0 +1,14 @@ +

Bit Goblin Blog

+ +<% if @posts.length > 0 %> + +<% else %> +

I'm sorry, there don't appear to be any blog posts published at this time. Check back later!

+<% end %> diff --git a/app/views/blog/show.html.erb b/app/views/blog/show.html.erb new file mode 100644 index 0000000..c4bd415 --- /dev/null +++ b/app/views/blog/show.html.erb @@ -0,0 +1,8 @@ +
+

<%= @post.title %>

+

written by <%= @post.author %>

+
+ +
+ <%= raw(@post.renderBody()) %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3e56fbd..53cc0be 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -23,6 +23,7 @@