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
87327c58
Commit
87327c58
authored
Apr 20, 2017
by
Jarka Kadlecova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support preview_markdown action for personal_snippets
parent
a9da3743
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
80 additions
and
29 deletions
+80
-29
app/controllers/concerns/markdown_preview.rb
app/controllers/concerns/markdown_preview.rb
+19
-0
app/controllers/projects/wikis_controller.rb
app/controllers/projects/wikis_controller.rb
+7
-14
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+5
-14
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+5
-0
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+1
-1
changelogs/unreleased/12910-personal-snippet-prep-2.yml
changelogs/unreleased/12910-personal-snippet-prep-2.yml
+4
-0
config/routes/snippets.rb
config/routes/snippets.rb
+1
-0
spec/controllers/projects/wikis_controller_spec.rb
spec/controllers/projects/wikis_controller_spec.rb
+16
-0
spec/controllers/projects_controller_spec.rb
spec/controllers/projects_controller_spec.rb
+10
-0
spec/controllers/snippets_controller_spec.rb
spec/controllers/snippets_controller_spec.rb
+12
-0
No files found.
app/controllers/concerns/markdown_preview.rb
0 → 100644
View file @
87327c58
module
MarkdownPreview
private
def
render_markdown_preview
(
text
,
markdown_context
=
{})
render
json:
{
body:
view_context
.
markdown
(
text
,
markdown_context
),
references:
{
users:
preview_referenced_users
(
text
)
}
}
end
def
preview_referenced_users
(
text
)
extractor
=
Gitlab
::
ReferenceExtractor
.
new
(
@project
,
current_user
)
extractor
.
analyze
(
text
,
author:
current_user
)
extractor
.
users
.
map
(
&
:username
)
end
end
app/controllers/projects/wikis_controller.rb
View file @
87327c58
class
Projects::WikisController
<
Projects
::
ApplicationController
include
MarkdownPreview
before_action
:authorize_read_wiki!
before_action
:authorize_create_wiki!
,
only:
[
:edit
,
:create
,
:history
]
before_action
:authorize_admin_wiki!
,
only: :destroy
...
...
@@ -91,21 +93,13 @@ class Projects::WikisController < Projects::ApplicationController
)
end
def
preview_markdown
text
=
params
[
:text
]
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
@project
,
current_user
)
ext
.
analyze
(
text
,
author:
current_user
)
render
json:
{
body:
view_context
.
markdown
(
text
,
pipeline: :wiki
,
project_wiki:
@project_wiki
,
page_slug:
params
[
:id
]),
references:
{
users:
ext
.
users
.
map
(
&
:username
)
}
}
def
git_access
end
def
git_access
def
preview_markdown
context
=
{
pipeline: :wiki
,
project_wiki:
@project_wiki
,
page_slug:
params
[
:id
]
}
render_markdown_preview
(
params
[
:text
],
context
)
end
private
...
...
@@ -115,7 +109,6 @@ class Projects::WikisController < Projects::ApplicationController
# Call #wiki to make sure the Wiki Repo is initialized
@project_wiki
.
wiki
@sidebar_wiki_entries
=
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."
...
...
app/controllers/projects_controller.rb
View file @
87327c58
class
ProjectsController
<
Projects
::
ApplicationController
include
IssuableCollections
include
ExtractsPath
include
MarkdownPreview
before_action
:authenticate_user!
,
except:
[
:index
,
:show
,
:activity
,
:refs
]
before_action
:project
,
except:
[
:index
,
:new
,
:create
]
...
...
@@ -216,20 +217,6 @@ class ProjectsController < Projects::ApplicationController
}
end
def
preview_markdown
text
=
params
[
:text
]
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
@project
,
current_user
)
ext
.
analyze
(
text
,
author:
current_user
)
render
json:
{
body:
view_context
.
markdown
(
text
),
references:
{
users:
ext
.
users
.
map
(
&
:username
)
}
}
end
def
refs
branches
=
BranchesFinder
.
new
(
@repository
,
params
).
execute
.
map
(
&
:name
)
...
...
@@ -252,6 +239,10 @@ class ProjectsController < Projects::ApplicationController
render
json:
options
.
to_json
end
def
preview_markdown
render_markdown_preview
(
params
[
:text
])
end
private
# Render project landing depending of which features are available
...
...
app/controllers/snippets_controller.rb
View file @
87327c58
...
...
@@ -2,6 +2,7 @@ class SnippetsController < ApplicationController
include
ToggleAwardEmoji
include
SpammableActions
include
SnippetsActions
include
MarkdownPreview
before_action
:snippet
,
only:
[
:show
,
:edit
,
:destroy
,
:update
,
:raw
,
:download
]
...
...
@@ -77,6 +78,10 @@ class SnippetsController < ApplicationController
)
end
def
preview_markdown
render_markdown_preview
(
params
[
:text
],
skip_project_check:
true
)
end
protected
def
snippet
...
...
app/helpers/gitlab_markdown_helper.rb
View file @
87327c58
...
...
@@ -196,7 +196,7 @@ module GitlabMarkdownHelper
end
# Calls Banzai.post_process with some common context options
def
banzai_postprocess
(
html
,
context
)
def
banzai_postprocess
(
html
,
context
=
{}
)
context
.
merge!
(
current_user:
(
current_user
if
defined?
(
current_user
)),
...
...
changelogs/unreleased/12910-personal-snippet-prep-2.yml
0 → 100644
View file @
87327c58
---
title
:
Support Markdown previews for personal snippets
merge_request
:
10810
author
:
config/routes/snippets.rb
View file @
87327c58
...
...
@@ -3,6 +3,7 @@ resources :snippets, concerns: :awardable do
get
'raw'
get
'download'
post
:mark_as_spam
post
:preview_markdown
end
end
...
...
spec/controllers/projects/wikis_controller_spec.rb
0 → 100644
View file @
87327c58
require
'spec_helper'
describe
Projects
::
WikisController
do
let
(
:project
)
{
create
(
:project_empty_repo
,
:public
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
'POST #preview_markdown'
do
it
'renders json in a correct format'
do
sign_in
(
user
)
post
:preview_markdown
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
'page/path'
,
text:
'*Markdown* text'
expect
(
JSON
.
parse
(
response
.
body
).
keys
).
to
match_array
(
%w(body references)
)
end
end
end
spec/controllers/projects_controller_spec.rb
View file @
87327c58
...
...
@@ -398,4 +398,14 @@ describe ProjectsController do
expect
(
parsed_body
[
"Commits"
]).
to
include
(
"123456"
)
end
end
describe
'POST #preview_markdown'
do
it
'renders json in a correct format'
do
sign_in
(
user
)
post
:preview_markdown
,
namespace_id:
public_project
.
namespace
,
id:
public_project
,
text:
'*Markdown* text'
expect
(
JSON
.
parse
(
response
.
body
).
keys
).
to
match_array
(
%w(body references)
)
end
end
end
spec/controllers/snippets_controller_spec.rb
View file @
87327c58
...
...
@@ -521,4 +521,16 @@ describe SnippetsController do
end
end
end
describe
'POST #preview_markdown'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
)
}
it
'renders json in a correct format'
do
sign_in
(
user
)
post
:preview_markdown
,
id:
snippet
,
text:
'*Markdown* text'
expect
(
JSON
.
parse
(
response
.
body
).
keys
).
to
match_array
(
%w(body references)
)
end
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