summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-04-26 12:36:25 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-04-26 12:36:25 +0000
commit8fbda3bf152b6b15f30754cbc68c7466e86b8ee9 (patch)
treeff32284427ba72a335f6e6057a79c4652c43bd43 /app
parent8c68729964d709ef8c372e41614a742cea8b6633 (diff)
parent87327c5845a7feec92e546dc0da42282ac27de40 (diff)
downloadgitlab-ce-8fbda3bf152b6b15f30754cbc68c7466e86b8ee9.tar.gz
Merge branch '12910-personal-snippet-prep-2' into 'master'
Support preview_markdown action for personal_snippets See merge request !10810
Diffstat (limited to 'app')
-rw-r--r--app/controllers/concerns/markdown_preview.rb19
-rw-r--r--app/controllers/projects/wikis_controller.rb21
-rw-r--r--app/controllers/projects_controller.rb19
-rw-r--r--app/controllers/snippets_controller.rb5
-rw-r--r--app/helpers/gitlab_markdown_helper.rb2
5 files changed, 37 insertions, 29 deletions
diff --git a/app/controllers/concerns/markdown_preview.rb b/app/controllers/concerns/markdown_preview.rb
new file mode 100644
index 00000000000..40eff267348
--- /dev/null
+++ b/app/controllers/concerns/markdown_preview.rb
@@ -0,0 +1,19 @@
+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
diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb
index c5e24b9e365..96125684da0 100644
--- a/app/controllers/projects/wikis_controller.rb
+++ b/app/controllers/projects/wikis_controller.rb
@@ -1,4 +1,6 @@
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."
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 6807c37f972..9f6ee4826e6 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -1,6 +1,7 @@
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
diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb
index f3fd3da8b20..056910fad67 100644
--- a/app/controllers/snippets_controller.rb
+++ b/app/controllers/snippets_controller.rb
@@ -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
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index cd442237086..106feb87398 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -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)),