From 3d6ab2fa578bc4c7cc9d96697ee81b6d38a421e3 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Fri, 4 Aug 2023 15:24:51 -0500 Subject: [PATCH] Add break opportunities in long names for mobile When wrapping text, Safari and Chrome do not consider `/` nor `:` as word break characters. Firefox considers `/` as a word break character but not `:`. This can lead to horizontal overflow issues with long file paths and module names on mobile. This commit adds a `full_name` helper to insert word-break opportunities into file paths and module names. It also revises the `link_to` helper to do the same when given an `RDoc::CodeObject`. The helpers insert `` tags which tell the browser that the text can be wrapped at that point. --- .../generator/template/rails/_context.rhtml | 10 +-- lib/rdoc/generator/template/rails/class.rhtml | 14 ++-- lib/rdoc/generator/template/rails/file.rhtml | 2 +- lib/sdoc/helpers.rb | 26 ++++-- spec/helpers_spec.rb | 81 ++++++++++++++++--- 5 files changed, 103 insertions(+), 30 deletions(-) diff --git a/lib/rdoc/generator/template/rails/_context.rhtml b/lib/rdoc/generator/template/rails/_context.rhtml index 13f868ec..a3883bf4 100644 --- a/lib/rdoc/generator/template/rails/_context.rhtml +++ b/lib/rdoc/generator/template/rails/_context.rhtml @@ -14,7 +14,7 @@
Required Files
<% end %> @@ -58,9 +58,9 @@ <% context.includes.each do |inc| %>
  • <% if inc.module.is_a?(String) %> - <%= h inc.name %> + <%= full_name inc.name %> <% else %> - <%= link_to inc.module.full_name, inc.module %> + <%= link_to inc.module %> <% end %>
  • <% end %> @@ -144,7 +144,7 @@

    Also aliased as: <%# Sometimes a parent cannot be determined. See ruby/rdoc@85ebfe13dc. %> - <%= method.aliases.map { |aka| link_to aka.name, (aka if aka.parent) }.join(", ") %>. + <%= method.aliases.map { |aka| link_to_if aka.parent, aka.name, aka }.join(", ") %>.

    <% end %> @@ -191,7 +191,7 @@ <% (context.modules.sort + context.classes.sort).each do |mod| %>
  • <%= mod.type.upcase %> - <%= link_to mod.full_name, mod %> + <%= link_to mod %>
  • <% end %> diff --git a/lib/rdoc/generator/template/rails/class.rhtml b/lib/rdoc/generator/template/rails/class.rhtml index ac2fa21d..55c1bcbc 100644 --- a/lib/rdoc/generator/template/rails/class.rhtml +++ b/lib/rdoc/generator/template/rails/class.rhtml @@ -28,14 +28,10 @@

    <%= klass.module? ? 'Module' : 'Class' %> - <%= h klass.full_name %> - <% if klass.type == "class" && klass.superclass %> - < - <% if klass.superclass.is_a?(String) %> - <%= klass.superclass %> - <% else %> - <%= link_to klass.superclass.full_name, klass.superclass %> - <% end %> + <%= full_name klass %> + <% if klass.type == "class" && superclass = klass.superclass %> + + < <%= superclass.is_a?(String) ? full_name(superclass) : link_to(superclass) %> <% end %>

    @@ -51,7 +47,7 @@ Appears in diff --git a/lib/rdoc/generator/template/rails/file.rhtml b/lib/rdoc/generator/template/rails/file.rhtml index a681c0c2..cac4f0ca 100644 --- a/lib/rdoc/generator/template/rails/file.rhtml +++ b/lib/rdoc/generator/template/rails/file.rhtml @@ -28,7 +28,7 @@