[30926] Display info instead of error when toc is empty

https://community.openproject.com/wp/30926
pull/7637/head
Oliver Günther 5 years ago
parent 58e3e7c80c
commit d1dcb37cb4
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 1
      config/locales/en.yml
  2. 8
      lib/open_project/text_formatting/filters/table_of_contents_filter.rb

@ -1628,6 +1628,7 @@ en:
label_wiki_content_added: "Wiki page added"
label_wiki_content_updated: "Wiki page updated"
label_wiki_toc: "Table of Contents"
label_wiki_toc_empty: "Table of Contents is empty as no headings are present."
label_wiki_dont_show_menu_item: "Do not show this wikipage in project navigation"
label_wiki_edit: "Wiki edit"
label_wiki_edit_plural: "Wiki edits"

@ -117,9 +117,13 @@ module OpenProject::TextFormatting
end
def process!
return if headings.empty?
result[:toc] =
if headings.empty?
I18n.t(:label_wiki_toc_empty)
else
content_tag(:ul, render_nested(nil), class: 'toc')
end
result[:toc] = content_tag(:ul, render_nested(nil), class: 'toc')
rescue StandardError => e
Rails.logger.error { "Failed to render table of contents: #{e} #{e.message}" }
end

Loading…
Cancel
Save