From e09aa803cf3905c82c29dbaa9101cc4a4639cc5a Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 11 Oct 2023 12:12:25 -0400 Subject: We're on Markdown now --- app/assets/stylesheets/admin/layout.scss | 8 ++++++++ app/controllers/admin/blogs_controller.rb | 2 +- app/helpers/application_helper.rb | 5 +++++ app/models/blog.rb | 8 ++++++++ app/views/blogs/_blog.html.haml | 7 ++++++- app/views/blogs/index.html.haml | 2 +- app/views/blogs/show.html.haml | 2 +- 7 files changed, 30 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index 3adf7da..bf15b0d 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss @@ -83,6 +83,7 @@ body { #entry-form { display: flex; + height: 100%; fieldset { border: 0; @@ -143,9 +144,16 @@ body { } .body-field { + height: 100%; + label { display: none; } + + textarea { + width: 100%; + height: 100%; + } } } diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index e79dd81..f17bce2 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb @@ -44,7 +44,7 @@ class Admin::BlogsController < Admin::AdminController def update @blog = Blog.find(params[:id]) - if @blog.update_attributes(blog_params) + if @blog.update(blog_params) flash.notice = "Blog updated successfully!" else flash.alert = "Error updating blog." diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8008b04..f12cdd4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -11,4 +11,9 @@ module ApplicationHelper link_to title, {:sort => col, :dir => direction}, {:class => css_class} end + def markdown(text) + options = %i[] + Markdown.new(text, *options).to_html.html_safe + end + end diff --git a/app/models/blog.rb b/app/models/blog.rb index 18f63f1..c12d0dc 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -18,6 +18,14 @@ class Blog < ApplicationRecord self end + def has_read_more + body.include?("") + end + + def short_body + body[0..(body.index("")-1)] + end + private def set_draft_title if self.title.blank? and not self.published diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index 317ef1f..389f961 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml @@ -6,4 +6,9 @@ .blog-title %h2= blog.title .post-author Hatkirby - %blockquote#blog-content.entry-content.bubble.rounded.bottom= blog.body.html_safe + %blockquote#blog-content.entry-content.bubble.rounded.bottom + - if short and blog.has_read_more + = markdown(blog.short_body) + = link_to "Read more...", blog + - else + = markdown(blog.body) diff --git a/app/views/blogs/index.html.haml b/app/views/blogs/index.html.haml index a1ad64c..e9639ca 100644 --- a/app/views/blogs/index.html.haml +++ b/app/views/blogs/index.html.haml @@ -1,3 +1,3 @@ - @blogs.each do |blog| - = render blog + = render blog, short: true = will_paginate @blogs diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml index f915e64..9bff12b 100644 --- a/app/views/blogs/show.html.haml +++ b/app/views/blogs/show.html.haml @@ -1,6 +1,6 @@ - title @blog.title .breadcrumb= link_to "← Back to home page", root_path -= render @blog += render @blog, short: false %footer#blog-footer This entry was posted on = succeed "." do -- cgit 1.4.1