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
3052e894
Commit
3052e894
authored
Apr 15, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-fix image rendering for help pages
parent
e24cb79f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
8 deletions
+99
-8
app/controllers/help_controller.rb
app/controllers/help_controller.rb
+36
-6
app/views/help/show.html.haml
app/views/help/show.html.haml
+1
-1
spec/controllers/help_controller_spec.rb
spec/controllers/help_controller_spec.rb
+61
-0
spec/features/help_pages_spec.rb
spec/features/help_pages_spec.rb
+1
-1
No files found.
app/controllers/help_controller.rb
View file @
3052e894
...
...
@@ -3,13 +3,36 @@ class HelpController < ApplicationController
end
def
show
@category
=
clean_path_info
(
params
[
:category
])
@file
=
clean_path_info
(
params
[
:file
])
category
=
clean_path_info
(
path_
params
[
:category
])
file
=
clean_path_info
(
path_
params
[
:file
])
if
File
.
exists?
(
Rails
.
root
.
join
(
'doc'
,
@category
,
@file
+
'.md'
))
render
'show'
else
not_found!
respond_to
do
|
format
|
format
.
any
(
:markdown
,
:md
,
:html
)
do
path
=
Rails
.
root
.
join
(
'doc'
,
category
,
"
#{
file
}
.md"
)
if
File
.
exist?
(
path
)
@markdown
=
File
.
read
(
path
)
render
'show.html.haml'
else
# Force template to Haml
render
'errors/not_found.html.haml'
,
layout:
'errors'
,
status:
404
end
end
# Allow access to images in the doc folder
format
.
any
(
:png
,
:gif
,
:jpeg
)
do
path
=
Rails
.
root
.
join
(
'doc'
,
category
,
"
#{
file
}
.
#{
params
[
:format
]
}
"
)
if
File
.
exist?
(
path
)
send_file
(
path
,
disposition:
'inline'
)
else
head
:not_found
end
end
# Any other format we don't recognize, just respond 404
format
.
any
{
head
:not_found
}
end
end
...
...
@@ -21,6 +44,13 @@ class HelpController < ApplicationController
private
def
path_params
params
.
require
(
:category
)
params
.
require
(
:file
)
params
end
PATH_SEPS
=
Regexp
.
union
(
*
[
::
File
::
SEPARATOR
,
::
File
::
ALT_SEPARATOR
].
compact
)
# Taken from ActionDispatch::FileHandler
...
...
app/views/help/show.html.haml
View file @
3052e894
.documentation.wiki
=
markdown
File
.
read
(
Rails
.
root
.
join
(
'doc'
,
@category
,
@file
+
'.md'
)).
gsub
(
"$your_email"
,
current_user
.
email
)
=
markdown
@markdown
.
gsub
(
'$your_email'
,
current_user
.
email
)
spec/controllers/help_controller_spec.rb
0 → 100644
View file @
3052e894
require
'spec_helper'
describe
HelpController
do
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
end
describe
'GET #show'
do
context
'for Markdown formats'
do
context
'when requested file exists'
do
before
do
get
:show
,
category:
'ssh'
,
file:
'README'
,
format: :md
end
it
'assigns to @markdown'
do
expect
(
assigns
[
:markdown
]).
not_to
be_empty
end
it
'renders HTML'
do
expect
(
response
).
to
render_template
(
'show.html.haml'
)
expect
(
response
.
content_type
).
to
eq
'text/html'
end
end
context
'when requested file is missing'
do
it
'renders not found'
do
get
:show
,
category:
'foo'
,
file:
'bar'
,
format: :md
expect
(
response
).
to
be_not_found
end
end
end
context
'for image formats'
do
context
'when requested file exists'
do
it
'renders the raw file'
do
get
:show
,
category:
'workflow/protected_branches'
,
file:
'protected_branches1'
,
format: :png
expect
(
response
).
to
be_success
expect
(
response
.
content_type
).
to
eq
'image/png'
expect
(
response
.
headers
[
'Content-Disposition'
]).
to
match
(
/^inline;/
)
end
end
context
'when requested file is missing'
do
it
'renders not found'
do
get
:show
,
category:
'foo'
,
file:
'bar'
,
format: :png
expect
(
response
).
to
be_not_found
end
end
end
context
'for other formats'
do
it
'always renders not found'
do
get
:show
,
category:
'ssh'
,
file:
'README'
,
format: :foo
expect
(
response
).
to
be_not_found
end
end
end
end
spec/features/help_pages_spec.rb
View file @
3052e894
...
...
@@ -6,7 +6,7 @@ describe 'Help Pages', feature: true do
login_as
:user
end
it
'replace the variable $your_email with the email of the user'
do
visit
help_page_path
(
category:
'ssh'
,
file:
'README.md
'
)
visit
help_page_path
(
'ssh'
,
'README
'
)
expect
(
page
).
to
have_content
(
"ssh-keygen -t rsa -C
\"
#{
@user
.
email
}
\"
"
)
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