aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/helpers/title_helper.rb14
-rw-r--r--app/views/comments/_comment.html.erb2
-rw-r--r--app/views/things/_thing.html.erb2
3 files changed, 16 insertions, 2 deletions
diff --git a/app/helpers/title_helper.rb b/app/helpers/title_helper.rb
new file mode 100644
index 0000000..4de2779
--- /dev/null
+++ b/app/helpers/title_helper.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+# Helper functions for dealing with titles of Things.
+module TitleHelper
+ # Returns the given string with underscores to <em></em>.
+ def title_to_html(title:)
+ replace_underscores_with(string: title, open_char: '<em>', close_char: '</em>').html_safe # rubocop:disable Rails/OutputSafety
+ end
+
+ # Replace underscores from a string with the given open/close characters.
+ def replace_underscores_with(string:, open_char:, close_char:)
+ string.gsub(/_([^_]+)_/, "#{open_char}\\1#{close_char}")
+ end
+end
diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb
index 8c0975e..5ee9ec3 100644
--- a/app/views/comments/_comment.html.erb
+++ b/app/views/comments/_comment.html.erb
@@ -4,7 +4,7 @@
<% if defined?(idx) %>
<span title="Commented on <%= comment.created_at %>"><b><%= I18n.t('comments.title') %></b> #<%= idx + 1 %></span>
<% else %>
- <span title="Commented on <%= comment.created_at %>"><b><%= I18n.t('comments.title') %></b> <%= I18n.t('general.in') %> <%= link_to comment.thing.title, thing_path(comment.thing) %></span>
+ <span title="Commented on <%= comment.created_at %>"><b><%= I18n.t('comments.title') %></b> <%= I18n.t('general.in') %> <%= link_to title_to_html(title: comment.thing.title), thing_path(comment.thing) %></span>
<% end %>
</div>
diff --git a/app/views/things/_thing.html.erb b/app/views/things/_thing.html.erb
index 5a31ccc..7c5ea93 100644
--- a/app/views/things/_thing.html.erb
+++ b/app/views/things/_thing.html.erb
@@ -2,6 +2,6 @@
<div class="thing_head">
<div class="dot dot_<%= thing.kind %>" title="<%= I18n.t("things.kind.#{thing.kind}") %>"></div>
</div>
- <div class="thing_body"><%= link_to thing.title, edit_thing_path(thing) %></div>
+ <div class="thing_body"><%= link_to title_to_html(title: thing.title), edit_thing_path(thing) %></div>
<div class="thing_tail"><%= thing.rate %></div>
</div>