diff --git a/app/assets/stylesheets/pages/wiki.scss b/app/assets/stylesheets/pages/wiki.scss index b9f8153315025829a6435861394e0af078fe62ae..7afadb7364dea9439374c1d7665b59d58a3e89ed 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 aeacb6f89958b92505813502929bb719046a5286..e970cfbfff8cb18c9d09260ab94f46b78de8fdad 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 1b6dceee2413ea31807fa7a08fc97c68e5c54875..25ae5c587ecf9e488aa55e1130e1cfff5f05a2c7 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 595d4a621c12cdec47d3abd746de69129e880544..c40a89b9dfbbff779729dd91249a2f692b3d39da 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')