Commit bc14c4f0 authored by Nick Thomas's avatar Nick Thomas

Remove a use of module_function

parent d79e587e
module Banzai module Banzai
module Renderer module Renderer
module_function
# Convert a Markdown String into an HTML-safe String of HTML # Convert a Markdown String into an HTML-safe String of HTML
# #
# Note that while the returned HTML will have been sanitized of dangerous # Note that while the returned HTML will have been sanitized of dangerous
...@@ -16,7 +14,7 @@ module Banzai ...@@ -16,7 +14,7 @@ module Banzai
# context - Hash of context options passed to our HTML Pipeline # context - Hash of context options passed to our HTML Pipeline
# #
# Returns an HTML-safe String # Returns an HTML-safe String
def render(text, context = {}) def self.render(text, context = {})
cache_key = context.delete(:cache_key) cache_key = context.delete(:cache_key)
cache_key = full_cache_key(cache_key, context[:pipeline]) cache_key = full_cache_key(cache_key, context[:pipeline])
...@@ -39,7 +37,7 @@ module Banzai ...@@ -39,7 +37,7 @@ module Banzai
# #banzai_render_context(field), and cannot be changed. Use #render, passing # #banzai_render_context(field), and cannot be changed. Use #render, passing
# it the field text, if a custom rendering is needed. The generated context # it the field text, if a custom rendering is needed. The generated context
# is returned along with the HTML. # is returned along with the HTML.
def render_field(object, field) def self.render_field(object, field)
html_field = object.markdown_cache_field_for(field) html_field = object.markdown_cache_field_for(field)
html = object.__send__(html_field) html = object.__send__(html_field)
...@@ -52,7 +50,7 @@ module Banzai ...@@ -52,7 +50,7 @@ module Banzai
end end
# Same as +render_field+, but without consulting or updating the cache field # Same as +render_field+, but without consulting or updating the cache field
def cacheless_render_field(object, field, options = {}) def self.cacheless_render_field(object, field, options = {})
text = object.__send__(field) text = object.__send__(field)
context = object.banzai_render_context(field).merge(options) context = object.banzai_render_context(field).merge(options)
...@@ -82,7 +80,7 @@ module Banzai ...@@ -82,7 +80,7 @@ module Banzai
# texts_and_contexts # texts_and_contexts
# => [{ text: '### Hello', # => [{ text: '### Hello',
# context: { cache_key: [note, :note] } }] # context: { cache_key: [note, :note] } }]
def cache_collection_render(texts_and_contexts) def self.cache_collection_render(texts_and_contexts)
items_collection = texts_and_contexts.each_with_index do |item, index| items_collection = texts_and_contexts.each_with_index do |item, index|
context = item[:context] context = item[:context]
cache_key = full_cache_multi_key(context.delete(:cache_key), context[:pipeline]) cache_key = full_cache_multi_key(context.delete(:cache_key), context[:pipeline])
...@@ -111,7 +109,7 @@ module Banzai ...@@ -111,7 +109,7 @@ module Banzai
items_collection.map { |item| item[:rendered] } items_collection.map { |item| item[:rendered] }
end end
def render_result(text, context = {}) def self.render_result(text, context = {})
text = Pipeline[:pre_process].to_html(text, context) if text text = Pipeline[:pre_process].to_html(text, context) if text
Pipeline[context[:pipeline]].call(text, context) Pipeline[context[:pipeline]].call(text, context)
...@@ -130,7 +128,7 @@ module Banzai ...@@ -130,7 +128,7 @@ module Banzai
# :user - User object # :user - User object
# #
# Returns an HTML-safe String # Returns an HTML-safe String
def post_process(html, context) def self.post_process(html, context)
context = Pipeline[context[:pipeline]].transform_context(context) context = Pipeline[context[:pipeline]].transform_context(context)
pipeline = Pipeline[:post_process] pipeline = Pipeline[:post_process]
...@@ -141,7 +139,7 @@ module Banzai ...@@ -141,7 +139,7 @@ module Banzai
end.html_safe end.html_safe
end end
def cacheless_render(text, context = {}) def self.cacheless_render(text, context = {})
Gitlab::Metrics.measure(:banzai_cacheless_render) do Gitlab::Metrics.measure(:banzai_cacheless_render) do
result = render_result(text, context) result = render_result(text, context)
...@@ -154,7 +152,7 @@ module Banzai ...@@ -154,7 +152,7 @@ module Banzai
end end
end end
def full_cache_key(cache_key, pipeline_name) def self.full_cache_key(cache_key, pipeline_name)
return unless cache_key return unless cache_key
["banzai", *cache_key, pipeline_name || :full] ["banzai", *cache_key, pipeline_name || :full]
end end
...@@ -162,12 +160,12 @@ module Banzai ...@@ -162,12 +160,12 @@ module Banzai
# To map Rails.cache.read_multi results we need to know the Rails.cache.expanded_key. # 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 # Other option will be to generate stringified keys on our side and don't delegate to Rails.cache.expanded_key
# method. # method.
def full_cache_multi_key(cache_key, pipeline_name) def self.full_cache_multi_key(cache_key, pipeline_name)
return unless cache_key return unless cache_key
Rails.cache.send(:expanded_key, full_cache_key(cache_key, pipeline_name)) Rails.cache.send(:expanded_key, full_cache_key(cache_key, pipeline_name))
end end
def update_object(object, html_field, html) def self.update_object(object, html_field, html)
object.update_column(html_field, html) object.update_column(html_field, html)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment