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
Boxiang Sun
gitlab-ce
Commits
121c5f66
Commit
121c5f66
authored
Apr 13, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JSON endpoint to get simple blob viewer
parent
ee17c659
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
app/controllers/concerns/renders_blob.rb
app/controllers/concerns/renders_blob.rb
+17
-0
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+13
-2
No files found.
app/controllers/concerns/renders_blob.rb
0 → 100644
View file @
121c5f66
module
RendersBlob
extend
ActiveSupport
::
Concern
def
render_blob_json
(
blob
)
viewer
=
if
params
[
:viewer
]
==
'rich'
blob
.
rich_viewer
else
blob
.
simple_viewer
end
return
render_404
unless
viewer
render
json:
{
html:
view_to_html_string
(
"projects/blob/_viewer"
,
viewer:
viewer
)
}
end
end
app/controllers/projects/blob_controller.rb
View file @
121c5f66
...
...
@@ -2,6 +2,7 @@
class
Projects::BlobController
<
Projects
::
ApplicationController
include
ExtractsPath
include
CreatesCommit
include
RendersBlob
include
ActionView
::
Helpers
::
SanitizeHelper
# Raised when given an invalid file path
...
...
@@ -34,8 +35,18 @@ class Projects::BlobController < Projects::ApplicationController
end
def
show
environment_params
=
@repository
.
branch_exists?
(
@ref
)
?
{
ref:
@ref
}
:
{
commit:
@commit
}
@environment
=
EnvironmentsFinder
.
new
(
@project
,
current_user
,
environment_params
).
execute
.
last
respond_to
do
|
format
|
format
.
html
do
environment_params
=
@repository
.
branch_exists?
(
@ref
)
?
{
ref:
@ref
}
:
{
commit:
@commit
}
@environment
=
EnvironmentsFinder
.
new
(
@project
,
current_user
,
environment_params
).
execute
.
last
render
'show'
end
format
.
json
do
render_blob_json
(
@blob
)
end
end
end
def
edit
...
...
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