Module: WikiHelper
- Includes:
- API::Helpers::RelatedResourcesHelpers
- Defined in:
- app/helpers/wiki_helper.rb
Instance Method Summary collapse
-
#breadcrumb(page_slug) ⇒ Object
Produces a pure text breadcrumb for a given page.
- #show_enable_confluence_integration?(container) ⇒ Boolean
- #wiki_404_messages ⇒ Object
- #wiki_attachment_upload_url ⇒ Object
- #wiki_breadcrumb_collapsed_links(page_slug) ⇒ Object
- #wiki_empty_state_messages(wiki) ⇒ Object
- #wiki_markup_hash_by_name_id ⇒ Object
- #wiki_page_render_api_endpoint(page) ⇒ Object
- #wiki_page_title(page, action = nil) ⇒ Object
- #wiki_page_tracking_context(page) ⇒ Object
- #wiki_sidebar_toggle_button ⇒ Object
- #wiki_sort_controls(wiki, direction, action: :pages) ⇒ Object
Methods included from API::Helpers::RelatedResourcesHelpers
#expose_path, #expose_url, #issues_available?, #mrs_available?, #project_feature_string_access_level
Instance Method Details
#breadcrumb(page_slug) ⇒ Object
Produces a pure text breadcrumb for a given page.
page_slug - The slug of a WikiPage object.
Returns a String composed of the capitalized name of each directory and the capitalized name of the page itself.
36 37 38 39 40 |
# File 'app/helpers/wiki_helper.rb', line 36 def (page_slug) page_slug.split('/') .map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize } .join(' / ') end |
#show_enable_confluence_integration?(container) ⇒ Boolean
151 152 153 154 155 |
# File 'app/helpers/wiki_helper.rb', line 151 def show_enable_confluence_integration?(container) container.is_a?(Project) && current_user&.can?(:admin_project, container) && !container.has_confluence? end |
#wiki_404_messages ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'app/helpers/wiki_helper.rb', line 80 def title = s_("Wiki404|This page doesn't exist") writable_body = s_("Wiki404|Would you like to create it?") readonly_body = s_('Wiki404|Use the sidebar to find a different page.') { writable: { title: title, body: writable_body }, readonly: { title: title, body: readonly_body } } end |
#wiki_attachment_upload_url ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/helpers/wiki_helper.rb', line 56 def case @wiki.container when Project expose_url((id: @wiki.container.id)) else raise TypeError, "Unsupported wiki container #{@wiki.container.class}" end end |
#wiki_breadcrumb_collapsed_links(page_slug) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/wiki_helper.rb', line 42 def (page_slug) page_slug_split = page_slug.split('/') page_slug_split.pop(1) current_slug = "" page_slug_split .map do |dir_or_page| current_slug = "#{current_slug}#{dir_or_page}/" ( { text: WikiPage.unhyphenize(dir_or_page).capitalize, href: wiki_page_path(@wiki, current_slug) }, location: :after ) end end |
#wiki_empty_state_messages(wiki) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/helpers/wiki_helper.rb', line 91 def (wiki) case wiki.container when Project writable_body = s_( "WikiEmpty|Use GitLab Wiki to collaborate on documentation in a project or group. " \ "You can store wiki pages written in markup formats like Markdown or AsciiDoc in a " \ "separate Git repository, and access the wiki through Git, the GitLab web interface, or the API." ) if show_enable_confluence_integration?(wiki.container) writable_body += s_("WikiEmpty| Have a Confluence wiki already? Use that instead.") end { writable: { title: s_('WikiEmpty|Get started with wikis'), body: writable_body }, readonly: { title: s_('WikiEmpty|This wiki doesn\'t have any content yet'), body: s_( 'WikiEmpty|You can use GitLab Wiki to collaborate on documentation in a project or group. ' \ 'You can store wiki pages written in markup formats like Markdown or AsciiDoc in a ' \ 'separate Git repository, and access the wiki through Git, the GitLab web interface, or the API.' ) } } when Group { writable: { title: s_('WikiEmpty|Get started with wikis'), body: s_( "WikiEmpty|Use GitLab Wiki to collaborate on documentation in a project or group. " \ "You can store wiki pages written in markup formats like Markdown or AsciiDoc in a " \ "separate Git repository, and access the wiki through Git, the GitLab web interface, or the API." ) }, readonly: { title: s_('WikiEmpty|This wiki doesn\'t have any content yet'), body: s_('WikiEmpty|You can use GitLab Wiki to collaborate on documentation in a project or group. ' \ 'You can store wiki pages written in markup formats like Markdown or AsciiDoc in a ' \ 'separate Git repository, and access the wiki through Git, the GitLab web interface, or the API.' ) } } else raise NotImplementedError, "Unknown wiki container type #{wiki.container.class.name}" end end |
#wiki_markup_hash_by_name_id ⇒ Object
161 162 163 |
# File 'app/helpers/wiki_helper.rb', line 161 def wiki_markup_hash_by_name_id Wiki::VALID_USER_MARKUPS.map { |key, value| { value[:name] => key } }.reduce({}, :merge) end |
#wiki_page_render_api_endpoint(page) ⇒ Object
157 158 159 |
# File 'app/helpers/wiki_helper.rb', line 157 def wiki_page_render_api_endpoint(page) expose_path(api_v4_projects_wikis_path(wiki_page_render_api_endpoint_params(page))) end |
#wiki_page_title(page, action = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/wiki_helper.rb', line 6 def wiki_page_title(page, action = nil) titles = [_('Wiki')] if page.persisted? titles << page.human_title (page.human_title) (page.slug) end titles << action if action page_title(*titles.reverse) (_('Wiki'), wiki_path(page.wiki)) end |
#wiki_page_tracking_context(page) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/wiki_helper.rb', line 141 def wiki_page_tracking_context(page) { 'wiki-format' => page.format, 'wiki-title-size' => page.title.bytesize, 'wiki-content-size' => page.raw_content.bytesize, 'wiki-directory-nest-level' => page.path.scan('/').count, 'wiki-container-type' => page.wiki.container.class.name } end |
#wiki_sidebar_toggle_button ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/wiki_helper.rb', line 20 def render Pajamas::ButtonComponent.new( category: :tertiary, icon: 'list-bulleted', button_options: { class: 'wiki-sidebar-header-toggle js-sidebar-wiki-toggle-open gl-mr-2', "aria-label": _('Toggle sidebar') }) end |
#wiki_sort_controls(wiki, direction, action: :pages) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/wiki_helper.rb', line 65 def wiki_sort_controls(wiki, direction, action: :pages) link_class = 'has-tooltip reverse-sort-btn rspec-reverse-sort' reversed_direction = direction == 'desc' ? 'asc' : 'desc' icon_class = direction == 'desc' ? 'highest' : 'lowest' title = direction == 'desc' ? _('Sort direction: Descending') : _('Sort direction: Ascending') = { action: action, direction: reversed_direction } render Pajamas::ButtonComponent.new( href: wiki_path(wiki, **), icon: "sort-#{icon_class}", button_options: { class: link_class, title: title } ) end |