Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8bf52a4a
Commit
8bf52a4a
authored
Dec 16, 2016
by
Alex Braha Stoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show directory hierarchy when listing wiki pages
parent
8dc2163c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
10 deletions
+65
-10
app/controllers/projects/wikis_controller.rb
app/controllers/projects/wikis_controller.rb
+2
-1
app/models/wiki_page.rb
app/models/wiki_page.rb
+25
-0
app/views/projects/wikis/_sidebar.html.haml
app/views/projects/wikis/_sidebar.html.haml
+8
-4
app/views/projects/wikis/pages.html.haml
app/views/projects/wikis/pages.html.haml
+9
-5
changelogs/unreleased/23535-folders-in-wiki-repository.yml
changelogs/unreleased/23535-folders-in-wiki-repository.yml
+4
-0
spec/models/wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+17
-0
No files found.
app/controllers/projects/wikis_controller.rb
View file @
8bf52a4a
...
...
@@ -8,6 +8,7 @@ class Projects::WikisController < Projects::ApplicationController
def
pages
@wiki_pages
=
Kaminari
.
paginate_array
(
@project_wiki
.
pages
).
page
(
params
[
:page
])
@wiki_directories
=
WikiPage
.
group_by_directory
(
@wiki_pages
)
end
def
show
...
...
@@ -116,7 +117,7 @@ class Projects::WikisController < Projects::ApplicationController
# Call #wiki to make sure the Wiki Repo is initialized
@project_wiki
.
wiki
@sidebar_wiki_
pages
=
@project_wiki
.
pages
.
first
(
15
)
@sidebar_wiki_
directories
=
WikiPage
.
group_by_directory
(
@project_wiki
.
pages
.
first
(
15
)
)
rescue
ProjectWiki
::
CouldNotCreateWikiError
flash
[
:notice
]
=
"Could not create Wiki Repository at this time. Please try again later."
redirect_to
project_path
(
@project
)
...
...
app/models/wiki_page.rb
View file @
8bf52a4a
...
...
@@ -12,6 +12,23 @@ class WikiPage
ActiveModel
::
Name
.
new
(
self
,
nil
,
'wiki'
)
end
def
self
.
group_by_directory
(
pages
)
directories
=
{}
pages
.
each
do
|
page
|
if
page
.
slug
.
include?
(
'/'
)
# Directory hierarchy is given by matching from the beginning up to
# the last forward slash.
directory
=
page
.
slug
.
match
(
/\A(.+)\//
)[
1
]
directories
[
directory
]
=
add_to_directory
(
directories
[
directory
],
page
)
else
directories
[
'root'
]
=
add_to_directory
(
directories
[
'root'
],
page
)
end
end
directories
end
def
to_key
[
:slug
]
end
...
...
@@ -176,6 +193,14 @@ class WikiPage
private
def
self
.
add_to_directory
(
directory
,
page
)
if
directory
.
present?
directory
<<
page
else
[
page
]
end
end
def
set_attributes
attributes
[
:slug
]
=
@page
.
url_path
attributes
[
:title
]
=
@page
.
title
...
...
app/views/projects/wikis/_sidebar.html.haml
View file @
8bf52a4a
...
...
@@ -12,10 +12,14 @@
.blocks-container
.block.block-first
%ul
.wiki-pages
-
@sidebar_wiki_pages
.
each
do
|
wiki_page
|
%li
{
class:
params
[
:id
]
==
wiki_page
.
slug
?
'active'
:
''
}
=
link_to
namespace_project_wiki_path
(
@project
.
namespace
,
@project
,
wiki_page
)
do
=
wiki_page
.
title
.
capitalize
-
@sidebar_wiki_directories
.
each
do
|
wiki_directory
,
wiki_pages
|
%li
=
wiki_directory
%ul
-
wiki_pages
.
each
do
|
wiki_page
|
%li
{
class:
params
[
:id
]
==
wiki_page
.
slug
?
'active'
:
''
}
=
link_to
namespace_project_wiki_path
(
@project
.
namespace
,
@project
,
wiki_page
)
do
=
wiki_page
.
title
.
capitalize
.block
=
link_to
namespace_project_wikis_pages_path
(
@project
.
namespace
,
@project
),
class:
'btn btn-block'
do
More Pages
...
...
app/views/projects/wikis/pages.html.haml
View file @
8bf52a4a
...
...
@@ -14,10 +14,14 @@
Clone repository
%ul
.content-list
-
@wiki_
pages
.
each
do
|
wiki_page
|
-
@wiki_
directories
.
each
do
|
wiki_directory
,
wiki_pages
|
%li
=
link_to
wiki_page
.
title
,
namespace_project_wiki_path
(
@project
.
namespace
,
@project
,
wiki_page
)
%small
(
#{
wiki_page
.
format
}
)
.pull-right
%small
Last edited
#{
time_ago_with_tooltip
(
wiki_page
.
commit
.
authored_date
)
}
=
wiki_directory
%ul
-
wiki_pages
.
each
do
|
wiki_page
|
%li
=
link_to
wiki_page
.
title
,
namespace_project_wiki_path
(
@project
.
namespace
,
@project
,
wiki_page
)
%small
(
#{
wiki_page
.
format
}
)
.pull-right
%small
Last edited
#{
time_ago_with_tooltip
(
wiki_page
.
commit
.
authored_date
)
}
=
paginate
@wiki_pages
,
theme:
'gitlab'
changelogs/unreleased/23535-folders-in-wiki-repository.yml
0 → 100644
View file @
8bf52a4a
---
title
:
Show directory hierarchy when listing wiki pages
merge_request
:
author
:
Alex Braha Stoll
spec/models/wiki_page_spec.rb
View file @
8bf52a4a
...
...
@@ -7,6 +7,23 @@ describe WikiPage, models: true do
subject
{
WikiPage
.
new
(
wiki
)
}
describe
'::group_by_directory'
do
context
'when there are no pages'
do
it
'returns an empty hash'
do
end
end
context
'when there are pages'
do
let!
(
:page_1
)
{
create_page
(
'page_1'
,
'content'
)
}
let!
(
:page_2
)
{
create_page
(
'directory/page_2'
,
'content'
)
}
let
(
:pages
)
{
[
page_1
,
page_2
]
}
xit
'returns a hash in which keys are directories and values are their pages'
do
expected_grouped_pages
=
{
'root'
=>
[
page_1
],
'directory'
=>
[
page_2
]
}
end
end
end
describe
"#initialize"
do
context
"when initialized with an existing gollum page"
do
before
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment