From cde1583e75e0c51e853b5856ca48e7d7d0b815d5 Mon Sep 17 00:00:00 2001
From: Zee Spencer <50284+zspencer@users.noreply.github.com>
Date: Sun, 9 Jul 2023 21:16:51 -0700
Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20`Journal`:=20Migrate=20Rendering?=
=?UTF-8?q?=20to=20EntryComponent?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- https://github.com/zinc-collective/convene/issues/1566
This refactor allows us to do post-processing of the markdown at the
Component level, which has access to the rails URL builders; which
should allow us to link to the `Keyword` within the `Entry#body`...
---
app/furniture/journal/entries/show.html.erb | 2 +-
app/furniture/journal/entry.rb | 16 ----------
...ntry.html.erb => entry_component.html.erb} | 4 +--
app/furniture/journal/entry_component.rb | 30 +++++++++++++++++++
.../journal/journals/_journal.html.erb | 4 +--
.../furniture/journal/entry_component_spec.rb | 10 +++++++
spec/furniture/journal/entry_spec.rb | 10 -------
7 files changed, 45 insertions(+), 31 deletions(-)
rename app/furniture/journal/{entries/_entry.html.erb => entry_component.html.erb} (85%)
create mode 100644 app/furniture/journal/entry_component.rb
create mode 100644 spec/furniture/journal/entry_component_spec.rb
diff --git a/app/furniture/journal/entries/show.html.erb b/app/furniture/journal/entries/show.html.erb
index 5001b3336..5eab77be6 100644
--- a/app/furniture/journal/entries/show.html.erb
+++ b/app/furniture/journal/entries/show.html.erb
@@ -1,2 +1,2 @@
<%- breadcrumb :journal_entry, entry %>
-<%= render entry %>
+<%= render Journal::EntryComponent.new(entry: entry) %>
diff --git a/app/furniture/journal/entry.rb b/app/furniture/journal/entry.rb
index 7e51b67ae..f75c5f84a 100644
--- a/app/furniture/journal/entry.rb
+++ b/app/furniture/journal/entry.rb
@@ -3,7 +3,6 @@ class Entry < ApplicationRecord
location(parent: :journal)
self.table_name = "journal_entries"
- include RendersMarkdown
extend StripsNamespaceFromModelName
scope :recent, -> { order("published_at DESC NULLS FIRST") }
@@ -38,21 +37,6 @@ def published?
published_at.present?
end
- def to_html
- render_markdown(body)
- end
-
- def self.renderer
- @_renderer ||= Redcarpet::Markdown.new(
- Renderer.new(filter_html: true, with_toc_data: true),
- autolink: true, strikethrough: true,
- no_intra_emphasis: true,
- lax_spacing: true,
- fenced_code_blocks: true, disable_indented_code_blocks: true,
- tables: true, footnotes: true, superscript: true, quote: true
- )
- end
-
def extract_keywords
self.keywords = journal.keywords.extract_and_create_from!(body).pluck(:canonical_keyword)
end
diff --git a/app/furniture/journal/entries/_entry.html.erb b/app/furniture/journal/entry_component.html.erb
similarity index 85%
rename from app/furniture/journal/entries/_entry.html.erb
rename to app/furniture/journal/entry_component.html.erb
index 4e30bd537..02dc3f235 100644
--- a/app/furniture/journal/entries/_entry.html.erb
+++ b/app/furniture/journal/entry_component.html.erb
@@ -2,14 +2,14 @@
<%= entry.headline %>
<%- if entry.published?%>
- Published on <%= link_to entry.published_at.to_fs(:long_ordinal), entry.location %>
+ Published on <%= link_to published_at, entry.location %>
<%- else %>
Unpublished.
<%- end %>