summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Braha Stoll <alexbrahastoll@gmail.com>2016-12-18 21:22:20 -0200
committerAlex Braha Stoll <alexbrahastoll@gmail.com>2016-12-31 16:55:50 -0200
commit5bbe6559917e1e64cdb047b6235715e2a7f002f2 (patch)
tree8ec5db6fa9527808826904aa5d32016a645e2b8d
parent294acf1c5cd2aea353081059c60b3951a2cf7c77 (diff)
downloadgitlab-ce-5bbe6559917e1e64cdb047b6235715e2a7f002f2.tar.gz
Add component to show the full path of a wiki page when viewing its content
-rw-r--r--app/assets/stylesheets/pages/wiki.scss3
-rw-r--r--app/models/wiki_page.rb11
-rw-r--r--app/views/projects/wikis/show.html.haml2
-rw-r--r--spec/models/wiki_page_spec.rb40
4 files changed, 54 insertions, 2 deletions
diff --git a/app/assets/stylesheets/pages/wiki.scss b/app/assets/stylesheets/pages/wiki.scss
index b9f81533150..7afadb7364d 100644
--- a/app/assets/stylesheets/pages/wiki.scss
+++ b/app/assets/stylesheets/pages/wiki.scss
@@ -14,7 +14,8 @@
font-size: 22px;
}
- .wiki-last-edit-by {
+ .wiki-last-edit-by, .wiki-page-full-path {
+ display: block;
color: $gl-gray-light;
strong {
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index aeacb6f8995..e970cfbfff8 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -88,6 +88,12 @@ class WikiPage
end
end
+ # The hierarchy of the directory this page is contained in.
+ def directory
+ dir = wiki.page_title_and_dir(slug).last
+ dir.present? ? dir : '/'
+ end
+
# The processed/formatted content of this page.
def formatted_content
@attributes[:formatted_content] ||= if @page
@@ -100,6 +106,11 @@ class WikiPage
@attributes[:format] || :markdown
end
+ # The full path for this page, including its filename and extension.
+ def full_path
+ "/#{directory}/#{page.filename}".gsub(/\/+/, '/')
+ end
+
# The commit message for this page version.
def message
version.try(:message)
diff --git a/app/views/projects/wikis/show.html.haml b/app/views/projects/wikis/show.html.haml
index 1b6dceee241..25ae5c587ec 100644
--- a/app/views/projects/wikis/show.html.haml
+++ b/app/views/projects/wikis/show.html.haml
@@ -8,7 +8,7 @@
.nav-text
%h2.wiki-page-title= @page.title.capitalize
-
+ %span.wiki-page-full-path= "(#{@page.full_path})"
%span.wiki-last-edit-by
Last edited by
%strong
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb
index 595d4a621c1..c40a89b9dfb 100644
--- a/spec/models/wiki_page_spec.rb
+++ b/spec/models/wiki_page_spec.rb
@@ -224,6 +224,46 @@ describe WikiPage, models: true do
end
end
+ describe '#directory' do
+ context 'when the page is at the root directory' do
+ it 'returns /' do
+ create_page('file', 'content')
+ page = wiki.find_page('file')
+
+ expect(page.directory).to eq('/')
+ end
+ end
+
+ context 'when the page is inside an actual directory' do
+ it 'returns the full directory hierarchy' do
+ create_page('dir_1/dir_1_1/file', 'content')
+ page = wiki.find_page('dir_1/dir_1_1/file')
+
+ expect(page.directory).to eq('dir_1/dir_1_1')
+ end
+ end
+ end
+
+ describe '#full_path' do
+ context 'when the page is at the root directory' do
+ it 'returns /filename.fileextension' do
+ create_page('file', 'content')
+ page = wiki.find_page('file')
+
+ expect(page.full_path).to eq('/file.md')
+ end
+ end
+
+ context 'when the page is inside an actual directory' do
+ it 'returns /directory/filename.fileextension' do
+ create_page('dir/file', 'content')
+ page = wiki.find_page('dir/file')
+
+ expect(page.full_path).to eq('/dir/file.md')
+ end
+ end
+ end
+
describe '#historical?' do
before do
create_page('Update', 'content')