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
Tatuya Kamada
gitlab-ce
Commits
f281041f
Commit
f281041f
authored
Jul 19, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make banzai module that handles markdown singleton
parent
20a5033d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
lib/banzai/renderer.rb
lib/banzai/renderer.rb
+9
-7
No files found.
lib/banzai/renderer.rb
View file @
f281041f
module
Banzai
module
Renderer
extend
self
# Convert a Markdown String into an HTML-safe String of HTML
#
# Note that while the returned HTML will have been sanitized of dangerous
...
...
@@ -14,7 +16,7 @@ module Banzai
# context - Hash of context options passed to our HTML Pipeline
#
# Returns an HTML-safe String
def
self
.
render
(
text
,
context
=
{})
def
render
(
text
,
context
=
{})
cache_key
=
context
.
delete
(
:cache_key
)
cache_key
=
full_cache_key
(
cache_key
,
context
[
:pipeline
])
...
...
@@ -52,7 +54,7 @@ module Banzai
# texts_and_contexts
# => [{ text: '### Hello',
# context: { cache_key: [note, :note] } }]
def
self
.
cache_collection_render
(
texts_and_contexts
)
def
cache_collection_render
(
texts_and_contexts
)
items_collection
=
texts_and_contexts
.
each_with_index
do
|
item
,
index
|
context
=
item
[
:context
]
cache_key
=
full_cache_multi_key
(
context
.
delete
(
:cache_key
),
context
[
:pipeline
])
...
...
@@ -81,7 +83,7 @@ module Banzai
items_collection
.
map
{
|
item
|
item
[
:rendered
]
}
end
def
self
.
render_result
(
text
,
context
=
{})
def
render_result
(
text
,
context
=
{})
text
=
Pipeline
[
:pre_process
].
to_html
(
text
,
context
)
if
text
Pipeline
[
context
[
:pipeline
]].
call
(
text
,
context
)
...
...
@@ -100,7 +102,7 @@ module Banzai
# :user - User object
#
# Returns an HTML-safe String
def
self
.
post_process
(
html
,
context
)
def
post_process
(
html
,
context
)
context
=
Pipeline
[
context
[
:pipeline
]].
transform_context
(
context
)
pipeline
=
Pipeline
[
:post_process
]
...
...
@@ -113,7 +115,7 @@ module Banzai
private
def
self
.
cacheless_render
(
text
,
context
=
{})
def
cacheless_render
(
text
,
context
=
{})
Gitlab
::
Metrics
.
measure
(
:banzai_cacheless_render
)
do
result
=
render_result
(
text
,
context
)
...
...
@@ -126,7 +128,7 @@ module Banzai
end
end
def
self
.
full_cache_key
(
cache_key
,
pipeline_name
)
def
full_cache_key
(
cache_key
,
pipeline_name
)
return
unless
cache_key
[
"banzai"
,
*
cache_key
,
pipeline_name
||
:full
]
end
...
...
@@ -134,7 +136,7 @@ module Banzai
# To map Rails.cache.read_multi results we need to know the Rails.cache.expanded_key.
# Other option will be to generate stringified keys on our side and don't delegate to Rails.cache.expanded_key
# method.
def
self
.
full_cache_multi_key
(
cache_key
,
pipeline_name
)
def
full_cache_multi_key
(
cache_key
,
pipeline_name
)
return
unless
cache_key
Rails
.
cache
.
send
(
:expanded_key
,
full_cache_key
(
cache_key
,
pipeline_name
))
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