about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorblackle <isabelle@blackle-mori.com>2017-01-12 23:54:26 -0500
committerblackle <isabelle@blackle-mori.com>2017-01-23 21:07:40 -0500
commitbf0f6eb62d0f5bd1f0d8e4e2a6e9e8fd3b297b6c (patch)
treec06ebcba34c5971d564beb98aa81d5d9784ec2c7 /app/lib
parent1761d3f9c33f3e2e98a09906fae1a03783b54b10 (diff)
Implement a click-to-view spoiler system
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/formatter.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 3565611bc..ccdef0382 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -14,7 +14,15 @@ class Formatter
 
     html = status.text
     html = encode(html)
-    html = simple_format(html, sanitize: false)
+
+    if (status.spoiler?)
+      spoilerhtml = status.spoiler_text
+      spoilerhtml = encode(spoilerhtml)
+      html = wrap_spoilers(html, spoilerhtml)
+    else
+      html = simple_format(html, sanitize: false)
+    end
+
     html = html.gsub(/\n/, '')
     html = link_urls(html)
     html = link_mentions(html, status.mentions)
@@ -43,6 +51,13 @@ class Formatter
     HTMLEntities.new.encode(html)
   end
 
+  def wrap_spoilers(html, spoilerhtml)
+    spoilerhtml = simple_format(spoilerhtml, {class: "spoiler-helper"}, {sanitize: false})
+    html = simple_format(html, {class: ["spoiler", "spoiler-on"]}, {sanitize: false})
+
+    spoilerhtml + html
+  end
+
   def link_urls(html)
     html.gsub(URI.regexp(%w(http https))) do |match|
       link_html(match)