From 94dcadd62ac66cc5c52579ae9c288314bbca0c20 Mon Sep 17 00:00:00 2001 From: Alex Braha Stoll <alexbrahastoll@gmail.com> Date: Tue, 27 Dec 2016 01:44:03 -0200 Subject: [PATCH] Add a breadcrumb at projects/wikis/show.html.haml --- app/assets/stylesheets/pages/wiki.scss | 5 +++++ app/helpers/wiki_helper.rb | 13 +++++++++++++ app/views/projects/wikis/show.html.haml | 3 +++ spec/helpers/wiki_helper_spec.rb | 21 +++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 app/helpers/wiki_helper.rb create mode 100644 spec/helpers/wiki_helper_spec.rb diff --git a/app/assets/stylesheets/pages/wiki.scss b/app/assets/stylesheets/pages/wiki.scss index 369fb44d818..480cb2b9f0d 100644 --- a/app/assets/stylesheets/pages/wiki.scss +++ b/app/assets/stylesheets/pages/wiki.scss @@ -17,6 +17,11 @@ @extend .top-area; position: relative; + .wiki-breadcrumb { + border-bottom: 1px solid $white-normal; + padding: 11px 0; + } + .wiki-page-title { margin: 0; font-size: 22px; diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb new file mode 100644 index 00000000000..76ee632ab6d --- /dev/null +++ b/app/helpers/wiki_helper.rb @@ -0,0 +1,13 @@ +module WikiHelper + # 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. + def breadcrumb(page_slug) + page_slug.split('/'). + map { |dir_or_page| dir_or_page.gsub(/-+/, ' ').capitalize }. + join(' / ') + end +end diff --git a/app/views/projects/wikis/show.html.haml b/app/views/projects/wikis/show.html.haml index 87b9ff6e415..3609461b721 100644 --- a/app/views/projects/wikis/show.html.haml +++ b/app/views/projects/wikis/show.html.haml @@ -6,6 +6,9 @@ %button.btn.btn-default.sidebar-toggle.js-sidebar-wiki-toggle{ role: "button", type: "button" } = icon('angle-double-left') + .wiki-breadcrumb + %span= breadcrumb(@page.slug) + .nav-text %h2.wiki-page-title= @page.title.capitalize %span.wiki-last-edit-by diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb new file mode 100644 index 00000000000..92c6f27a867 --- /dev/null +++ b/spec/helpers/wiki_helper_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe WikiHelper do + describe '#breadcrumb' do + context 'when the page is at the root level' do + it 'returns the capitalized page name' do + slug = 'page-name' + + expect(helper.breadcrumb(slug)).to eq('Page name') + end + end + + context 'when the page is inside a directory' do + it 'returns the capitalized name of each directory and of the page itself' do + slug = 'dir_1/page-name' + + expect(helper.breadcrumb(slug)).to eq('Dir_1 / Page name') + end + end + end +end -- GitLab