FIX: Replace details content with instruction.

This commit is contained in:
Bianca Nenciu 2019-05-24 18:57:03 +03:00 committed by Guo Xiang Tan
parent 6cceb72173
commit 3a1d99577e
3 changed files with 27 additions and 3 deletions

View File

@ -1,3 +1,5 @@
en:
site_settings:
details_enabled: "Enable the details feature. If you change this, you must rebake all posts with: \"rake posts:rebake\"."
details:
excerpt_details: "(click for more details)"

View File

@ -31,8 +31,14 @@ after_initialize do
end
end
on(:reduce_cooked) do |fragment|
fragment.css("details.elided").each(&:remove)
on(:reduce_cooked) do |fragment, post|
fragment.css("details").each do |el|
text = fragment.css("summary").text
link = fragment.document.create_element("a")
link["href"] = post.url if post
link.content = I18n.t("details.excerpt_details")
el.replace text + " " + link.to_html
end
end
end

View File

@ -5,6 +5,8 @@ require 'pretty_text'
describe PrettyText do
let(:post) { Fabricate(:post) }
it "supports details tag" do
cooked_html = <<~HTML
<details>
@ -20,9 +22,23 @@ describe PrettyText do
it "deletes elided content" do
cooked_html = PrettyText.cook("Hello World\n\n<details class='elided'>42</details>")
mail_html = PrettyText.cook("Hello World")
mail_html = "<p>Hello World</p>\n<a href=\"http://test.localhost\">(click for more details)</a>"
expect(PrettyText.format_for_email(cooked_html)).to match_html(mail_html)
end
it 'can replace spoilers in emails' do
md = PrettyText.cook(<<~EOF)
hello
[details="Summary"]
world
[/details]
EOF
md = PrettyText.format_for_email(md, post)
html = "<p>hello</p>\n\nSummary <a href=\"#{post.full_url}\">(click for more details)</a>"
expect(md).to eq(html)
end
end