-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Rendering to the EntryComponent so we have access to routes
- Loading branch information
Showing
7 changed files
with
69 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1 @@ | ||
<article class="w-full p-2 my-2 bg-white rounded flex flex-col justify-between"> | ||
<header class="border-b border-primary-500"> | ||
<h2 class=" text-primary-900"><%= entry.headline %></h2> | ||
<%- if entry.published?%> | ||
<em>Published on <%= link_to entry.published_at.to_fs(:long_ordinal), entry.location %></em> | ||
<%- else %> | ||
<em>Unpublished.</em> | ||
<%- end %> | ||
</header> | ||
|
||
<div class="prose"> | ||
<%= entry.to_html.html_safe %> | ||
</div> | ||
|
||
<footer class="flex justify-between my-2"> | ||
<%- if policy(entry).update? %> | ||
<%= link_to "Edit", entry.location(:edit) %> | ||
<%- if !entry.published? %> | ||
<%= link_to "Publish Now", (entry.location() + [{ entry: { published_at: Time.now } }]), data: { turbo_method: :put } %> | ||
<%- end %> | ||
<%- end %> | ||
|
||
<%- if policy(entry).destroy? %> | ||
<%= link_to "Delete", entry.location, data: { turbo_method: :delete } %> | ||
<%- end %> | ||
</footer> | ||
</article> | ||
<%= render Journal::EntryComponent.new(entry: entry) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<article class="w-full p-2 my-2 bg-white rounded flex flex-col justify-between"> | ||
<header class="border-b border-primary-500"> | ||
<h2 class=" text-primary-900"><%= entry.headline %></h2> | ||
<%- if entry.published?%> | ||
<em>Published on <%= link_to published_at, entry.location %></em> | ||
<%- else %> | ||
<em>Unpublished.</em> | ||
<%- end %> | ||
</header> | ||
|
||
<div class="prose"> | ||
<%== body_html %> | ||
</div> | ||
|
||
<footer class="flex justify-between my-2"> | ||
<%- if policy(entry).update? %> | ||
<%= link_to "Edit", entry.location(:edit) %> | ||
<%- if !entry.published? %> | ||
<%= link_to "Publish Now", (entry.location() + [{ entry: { published_at: Time.now } }]), data: { turbo_method: :put } %> | ||
<%- end %> | ||
<%- end %> | ||
|
||
<%- if policy(entry).destroy? %> | ||
<%= link_to "Delete", entry.location, data: { turbo_method: :delete } %> | ||
<%- end %> | ||
</footer> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Journal | ||
class EntryComponent < ApplicationComponent | ||
include RendersMarkdown | ||
attr_accessor :entry | ||
|
||
def initialize(*args, entry:, **kwargs) | ||
self.entry = entry | ||
super(*args, **kwargs) | ||
end | ||
|
||
def body_html | ||
render_markdown(entry.body) | ||
end | ||
|
||
def published_at | ||
entry.published_at.to_fs(:long_ordinal) | ||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journal::EntryComponent, type: :component do | ||
subject(:output) { render_inline(component) } | ||
|
||
let(:component) { described_class.new(entry: entry) } | ||
let(:entry) { create(:journal_entry, body: "https://www.google.com @[email protected] #GoodTimes") } | ||
|
||
it { is_expected.to have_link("https://www.google.com", href: "https://www.google.com") } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,6 @@ | |
it { is_expected.to have_one(:room).through(:journal) } | ||
it { is_expected.to have_one(:space).through(:journal) } | ||
|
||
describe "#to_html" do | ||
subject(:to_html) { entry.to_html } | ||
|
||
context "when #body is 'https://www.google.com @[email protected] #GoodTimes'" do | ||
let(:entry) { build(:journal_entry, body: "https://www.google.com @[email protected] #GoodTimes") } | ||
|
||
it { is_expected.to include('<a href="https://www.google.com">https://www.google.com</a>') } | ||
it { is_expected.to include("{keyword_GoodTimes}") } | ||
end | ||
end | ||
|
||
describe "#save" do | ||
let(:entry) { create(:journal_entry, body: "#GoodTimes") } | ||
let(:journal) { entry.journal } | ||
|