about summary refs log tree commit diff
path: root/app/helpers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-02-28 01:52:31 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-02-28 01:52:31 +0100
commitd180aaa2a7e4026612dbc46243689f4f2e52c258 (patch)
tree41d7bc83eca82e6da4ab8e54b3ea6c2883de3173 /app/helpers
parent809455aaaed1e576ca2613828ad009a93224afa0 (diff)
Fix #186 - Add RTL support to the compose form textarea and statuses output
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/stream_entries_helper.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb
index 15601a079..a26e912a3 100644
--- a/app/helpers/stream_entries_helper.rb
+++ b/app/helpers/stream_entries_helper.rb
@@ -37,4 +37,17 @@ module StreamEntriesHelper
   def proper_status(status)
     status.reblog? ? status.reblog : status
   end
+
+  def rtl?(text)
+    return false if text.empty?
+
+    matches = /[\p{Hebrew}|\p{Arabic}|\p{Syriac}|\p{Thaana}|\p{Nko}]+/m.match(text)
+
+    return false unless matches
+
+    rtl_size = matches.to_a.reduce(0) { |acc, elem| acc + elem.size }.to_f
+    ltr_size = text.strip.size.to_f
+
+    rtl_size / ltr_size > 0.3
+  end
 end