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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
e6404816
Commit
e6404816
authored
May 06, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'files_in_wiki' into 'master'
Add support to show files from wiki repository on wiki pages
parents
478d6bd4
00cd3ecc
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
92 additions
and
6 deletions
+92
-6
app/controllers/projects/wikis_controller.rb
app/controllers/projects/wikis_controller.rb
+13
-0
app/models/project_wiki.rb
app/models/project_wiki.rb
+8
-1
app/models/wiki_page.rb
app/models/wiki_page.rb
+13
-3
app/views/projects/wikis/_new.html.haml
app/views/projects/wikis/_new.html.haml
+1
-1
config/routes.rb
config/routes.rb
+1
-1
features/project/wiki.feature
features/project/wiki.feature
+17
-0
features/steps/project/wiki.rb
features/steps/project/wiki.rb
+39
-0
No files found.
app/controllers/projects/wikis_controller.rb
View file @
e6404816
...
@@ -12,9 +12,22 @@ class Projects::WikisController < Projects::ApplicationController
...
@@ -12,9 +12,22 @@ class Projects::WikisController < Projects::ApplicationController
def
show
def
show
@page
=
@project_wiki
.
find_page
(
params
[
:id
],
params
[
:version_id
])
@page
=
@project_wiki
.
find_page
(
params
[
:id
],
params
[
:version_id
])
gollum_wiki
=
@project_wiki
.
wiki
file
=
gollum_wiki
.
file
(
params
[
:id
],
gollum_wiki
.
ref
,
true
)
if
@page
if
@page
render
'show'
render
'show'
elsif
file
if
file
.
on_disk?
send_file
file
.
on_disk_path
,
disposition:
'inline'
else
send_data
(
file
.
raw_data
,
type:
file
.
mime_type
,
disposition:
'inline'
,
filename:
file
.
name
)
end
else
else
return
render
(
'empty'
)
unless
can?
(
current_user
,
:write_wiki
,
@project
)
return
render
(
'empty'
)
unless
can?
(
current_user
,
:write_wiki
,
@project
)
@page
=
WikiPage
.
new
(
@project_wiki
)
@page
=
WikiPage
.
new
(
@project_wiki
)
...
...
app/models/project_wiki.rb
View file @
e6404816
...
@@ -64,7 +64,8 @@ class ProjectWiki
...
@@ -64,7 +64,8 @@ class ProjectWiki
#
#
# Returns an initialized WikiPage instance or nil
# Returns an initialized WikiPage instance or nil
def
find_page
(
title
,
version
=
nil
)
def
find_page
(
title
,
version
=
nil
)
if
page
=
wiki
.
page
(
title
,
version
)
page_title
,
page_dir
=
page_title_and_dir
(
title
)
if
page
=
wiki
.
page
(
page_title
,
version
,
page_dir
)
WikiPage
.
new
(
self
,
page
,
true
)
WikiPage
.
new
(
self
,
page
,
true
)
else
else
nil
nil
...
@@ -90,6 +91,12 @@ class ProjectWiki
...
@@ -90,6 +91,12 @@ class ProjectWiki
wiki
.
delete_page
(
page
,
commit_details
(
:deleted
,
message
,
page
.
title
))
wiki
.
delete_page
(
page
,
commit_details
(
:deleted
,
message
,
page
.
title
))
end
end
def
page_title_and_dir
(
title
)
title_array
=
title
.
split
(
"/"
)
title
=
title_array
.
pop
[
title
.
gsub
(
/\.[^.]*$/
,
""
),
title_array
.
join
(
"/"
)]
end
private
private
def
create_repo!
def
create_repo!
...
...
app/models/wiki_page.rb
View file @
e6404816
...
@@ -175,14 +175,24 @@ class WikiPage
...
@@ -175,14 +175,24 @@ class WikiPage
end
end
def
save
(
method
,
*
args
)
def
save
(
method
,
*
args
)
if
valid?
&&
wiki
.
send
(
method
,
*
args
)
project_wiki
=
wiki
@page
=
wiki
.
wiki
.
paged
(
title
)
if
valid?
&&
project_wiki
.
send
(
method
,
*
args
)
page_details
=
if
method
==
:update_page
@page
.
path
else
title
end
page_title
,
page_dir
=
project_wiki
.
page_title_and_dir
(
page_details
)
gollum_wiki
=
project_wiki
.
wiki
@page
=
gollum_wiki
.
paged
(
page_title
,
page_dir
)
set_attributes
set_attributes
@persisted
=
true
@persisted
=
true
else
else
errors
.
add
(
:base
,
wiki
.
error_message
)
if
wiki
.
error_message
errors
.
add
(
:base
,
project_wiki
.
error_message
)
if
project_
wiki
.
error_message
@persisted
=
false
@persisted
=
false
end
end
@persisted
@persisted
...
...
app/views/projects/wikis/_new.html.haml
View file @
e6404816
...
@@ -9,6 +9,6 @@
...
@@ -9,6 +9,6 @@
%span
Page slug
%span
Page slug
=
text_field_tag
:new_wiki_path
,
nil
,
placeholder:
'how-to-setup'
,
class:
'form-control'
,
required:
true
,
:'data-wikis-path'
=>
project_wikis_path
(
@project
)
=
text_field_tag
:new_wiki_path
,
nil
,
placeholder:
'how-to-setup'
,
class:
'form-control'
,
required:
true
,
:'data-wikis-path'
=>
project_wikis_path
(
@project
)
%p
.hint
%p
.hint
Please don't use spaces
and slashes
Please don't use spaces
.
.modal-footer
.modal-footer
=
link_to
'Build'
,
'#'
,
class:
'build-new-wiki btn btn-create'
=
link_to
'Build'
,
'#'
,
class:
'build-new-wiki btn btn-create'
config/routes.rb
View file @
e6404816
...
@@ -206,7 +206,7 @@ Gitlab::Application.routes.draw do
...
@@ -206,7 +206,7 @@ Gitlab::Application.routes.draw do
end
end
end
end
resources
:wikis
,
only:
[
:show
,
:edit
,
:destroy
,
:create
],
constraints:
{
id:
/[a-zA-Z.0-9_\-]+/
}
do
resources
:wikis
,
only:
[
:show
,
:edit
,
:destroy
,
:create
],
constraints:
{
id:
/[a-zA-Z.0-9_\-
\/
]+/
}
do
collection
do
collection
do
get
:pages
get
:pages
put
':id'
=>
'wikis#update'
put
':id'
=>
'wikis#update'
...
...
features/project/wiki.feature
View file @
e6404816
...
@@ -45,3 +45,20 @@ Feature: Project Wiki
...
@@ -45,3 +45,20 @@ Feature: Project Wiki
And
I browse to that Wiki page
And
I browse to that Wiki page
And
I click on the
"Pages"
button
And
I click on the
"Pages"
button
Then
I should see the existing page in the pages list
Then
I should see the existing page in the pages list
Scenario
:
Image in wiki repo shown on the page
Given
I have an existing Wiki page with images linked on page
And
I browse to wiki page with images
Then
Image should be shown on the page
Scenario
:
File does not exist in wiki repo
Given
I have an existing Wiki page with images linked on page
And
I browse to wiki page with images
And
I click on image link
Then
I should see the new wiki page form
Scenario
:
File exists in wiki repo
Given
I have an existing Wiki page with images linked on page
And
I browse to wiki page with images
And
I click on existing image link
Then
I should see the image from wiki repo
features/steps/project/wiki.rb
View file @
e6404816
...
@@ -86,6 +86,45 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
...
@@ -86,6 +86,45 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
page
.
should
have_content
@page
.
title
page
.
should
have_content
@page
.
title
end
end
Given
'I have an existing Wiki page with images linked on page'
do
wiki
.
create_page
(
"pictures"
,
"Look at this [image](image.jpg)
\n\n
![image](image.jpg)"
,
:markdown
,
"first commit"
)
@wiki_page
=
wiki
.
find_page
(
"pictures"
)
end
And
'I browse to wiki page with images'
do
visit
project_wiki_path
(
project
,
@wiki_page
)
end
And
'I click on existing image link'
do
file
=
Gollum
::
File
.
new
(
wiki
.
wiki
)
Gollum
::
Wiki
.
any_instance
.
stub
(
:file
).
with
(
"image.jpg"
,
"master"
,
true
).
and_return
(
file
)
Gollum
::
File
.
any_instance
.
stub
(
:mime_type
).
and_return
(
"image/jpeg"
)
page
.
should
have_link
(
'image'
,
href:
"image.jpg"
)
click_on
"image"
end
Then
'I should see the image from wiki repo'
do
url
=
URI
.
parse
(
current_url
)
url
.
path
.
should
match
(
"wikis/image.jpg"
)
page
.
should_not
have_xpath
(
'/html'
)
# Page should render the image which means there is no html involved
end
Then
'Image should be shown on the page'
do
page
.
should
have_xpath
(
"//img[@src=
\"
image.jpg
\"
]"
)
end
And
'I click on image link'
do
page
.
should
have_link
(
'image'
,
href:
"image.jpg"
)
click_on
"image"
end
Then
'I should see the new wiki page form'
do
url
=
URI
.
parse
(
current_url
)
url
.
path
.
should
match
(
"wikis/image.jpg"
)
page
.
should
have_content
(
'New Wiki Page'
)
page
.
should
have_content
(
'Editing - image.jpg'
)
end
def
wiki
def
wiki
@project_wiki
=
ProjectWiki
.
new
(
project
,
current_user
)
@project_wiki
=
ProjectWiki
.
new
(
project
,
current_user
)
end
end
...
...
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