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.
- #link_to_wiki_page(page, **options) ⇒ Object
- #show_enable_confluence_integration?(container) ⇒ Boolean
- #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) ⇒ Object
- #wiki_sort_title(key) ⇒ 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 |
#link_to_wiki_page(page, **options) ⇒ Object
20 21 22 |
# File 'app/helpers/wiki_helper.rb', line 20 def link_to_wiki_page(page, **) link_to page.human_title, wiki_page_path(page.wiki, page), ** end |
#show_enable_confluence_integration?(container) ⇒ Boolean
134 135 136 137 138 |
# File 'app/helpers/wiki_helper.rb', line 134 def show_enable_confluence_integration?(container) container.is_a?(Project) && current_user&.can?(:admin_project, container) && !container.has_confluence? end |
#wiki_attachment_upload_url ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'app/helpers/wiki_helper.rb', line 53 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 |
# 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}/" link_to(WikiPage.unhyphenize(dir_or_page).capitalize, wiki_page_path(@wiki, current_slug)), location: :after end end |
#wiki_empty_state_messages(wiki) ⇒ Object
84 85 86 87 88 89 90 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 |
# File 'app/helpers/wiki_helper.rb', line 84 def (wiki) case wiki.container when Project writable_body = s_("WikiEmpty|A wiki is where you can store all the details about your project. This can include why you've created it, its principles, how to use it, and so on.") writable_body += s_("WikiEmpty| Have a Confluence wiki already? Use that instead.") if show_enable_confluence_integration?(wiki.container) { writable: { title: s_('WikiEmpty|The wiki lets you write documentation for your project'), body: writable_body }, issuable: { title: s_('WikiEmpty|This project has no wiki pages'), body: s_('WikiEmptyIssueMessage|You must be a project member in order to add wiki pages. If you have suggestions for how to improve the wiki for this project, consider opening an issue in the %{issues_link}.') }, readonly: { title: s_('WikiEmpty|This project has no wiki pages'), body: s_('WikiEmpty|You must be a project member in order to add wiki pages.') } } when Group { writable: { title: s_('WikiEmpty|The wiki lets you write documentation for your group'), body: s_("WikiEmpty|A wiki is where you can store all the details about your group. This can include why you've created it, its principles, how to use it, and so on.") }, issuable: { title: s_('WikiEmpty|This group has no wiki pages'), body: s_('WikiEmptyIssueMessage|You must be a group member in order to add wiki pages. If you have suggestions for how to improve the wiki for this group, consider opening an issue in the %{issues_link}.') }, readonly: { title: s_('WikiEmpty|This group has no wiki pages'), body: s_('WikiEmpty|You must be a group member in order to add wiki pages.') } } else raise NotImplementedError, "Unknown wiki container type #{wiki.container.class.name}" end end |
#wiki_markup_hash_by_name_id ⇒ Object
144 145 146 |
# File 'app/helpers/wiki_helper.rb', line 144 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
140 141 142 |
# File 'app/helpers/wiki_helper.rb', line 140 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
124 125 126 127 128 129 130 131 132 |
# File 'app/helpers/wiki_helper.rb', line 124 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
24 25 26 27 28 |
# File 'app/helpers/wiki_helper.rb', line 24 def content_tag :button, class: 'gl-button btn btn-default btn-icon sidebar-toggle js-sidebar-wiki-toggle', role: 'button', type: 'button' do sprite_icon('chevron-double-lg-left') end end |
#wiki_sort_controls(wiki, direction) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/wiki_helper.rb', line 62 def wiki_sort_controls(wiki, direction) link_class = 'gl-button btn btn-default btn-icon 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: :pages, direction: reversed_direction } link_to(wiki_path(wiki, **), type: 'button', class: link_class, title: title) do sprite_icon("sort-#{icon_class}") end end |
#wiki_sort_title(key) ⇒ Object
76 77 78 79 80 81 82 |
# File 'app/helpers/wiki_helper.rb', line 76 def wiki_sort_title(key) if key == Wiki::CREATED_AT_ORDER s_("Wiki|Created date") else s_("Wiki|Title") end end |