diff options
author | Toon Claes <toon@gitlab.com> | 2017-04-06 16:47:52 +0200 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2017-04-27 13:22:17 +0200 |
commit | 05e0f504530a162d4bcb886adf504c12cffd5934 (patch) | |
tree | aeece92fb84421062c919e0c63173718db3577ba /app/helpers/markup_helper.rb | |
parent | ef4d4446e957ecbb086859d96185a27af168d11c (diff) | |
download | gitlab-ce-05e0f504530a162d4bcb886adf504c12cffd5934.tar.gz |
Cache the rendered README, but post-process on show
Because the post-processing of the rendered README is dependent on the
context (i.e. the current user), do the post-processing when the
README is being displayed.
Diffstat (limited to 'app/helpers/markup_helper.rb')
-rw-r--r-- | app/helpers/markup_helper.rb | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index f82791b88fa..c39b630aec6 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -60,12 +60,17 @@ module MarkupHelper end def markdown(text, context = {}) + html = markdown_render(text, context) + + markup_postprocess(html, context) + end + + def markdown_render(text, context = {}) return "" unless text.present? context[:project] ||= @project - html = Banzai.render(text, context) - banzai_postprocess(html, context) + Banzai.render(text, context) end def markdown_field(object, field) @@ -76,7 +81,7 @@ module MarkupHelper banzai_postprocess(html, object.banzai_render_context(field)) end - def asciidoc(text) + def asciidoc_render(text) Gitlab::Asciidoc.render( text, project: @project, @@ -90,7 +95,7 @@ module MarkupHelper ) end - def other_markup(file_name, text) + def other_markup_render(file_name, text) Gitlab::OtherMarkup.render( file_name, text, @@ -105,6 +110,14 @@ module MarkupHelper ) end + def markup_postprocess(html, context = {}) + return "" unless html.present? + + context[:project] ||= @project + + banzai_postprocess(html, context) + end + # Return the first line of +text+, up to +max_chars+, after parsing the line # as Markdown. HTML tags in the parsed output are not counted toward the # +max_chars+ limit. If the length limit falls within a tag's contents, then @@ -116,27 +129,34 @@ module MarkupHelper end def render_wiki_content(wiki_page) + context = { pipeline: :wiki, project_wiki: @project_wiki, page_slug: wiki_page.slug } case wiki_page.format when :markdown - markdown(wiki_page.content, pipeline: :wiki, project_wiki: @project_wiki, page_slug: wiki_page.slug) + html = markdown_render(wiki_page.content, context) when :asciidoc - asciidoc(wiki_page.content) + html = asciidoc_render(wiki_page.content) else - wiki_page.formatted_content.html_safe + return wiki_page.formatted_content.html_safe end + markup_postprocess(html, context) end def render_markup(file_name, file_content) + html = markup_render(file_name, file_content) + markup_postprocess(html) + end + + def markup_render(file_name, file_content) if gitlab_markdown?(file_name) - Hamlit::RailsHelpers.preserve(markdown(file_content)) + Hamlit::RailsHelpers.preserve(markdown_render(file_content)) elsif asciidoc?(file_name) - asciidoc(file_content) + asciidoc_render(file_content) elsif plain?(file_name) content_tag :pre, class: 'plain-readme' do file_content end else - other_markup(file_name, file_content) + other_markup_render(file_name, file_content) end rescue RuntimeError simple_format(file_content) |