Add a plugin hook to specify a class on the body of the document

This commit is contained in:
Robin Ward 2017-09-28 13:16:51 -04:00
parent ca3d6921a0
commit 34f98f362f
2 changed files with 11 additions and 1 deletions

View File

@ -8,12 +8,16 @@ require_dependency 'mobile_detection'
require_dependency 'category_badge'
require_dependency 'global_path'
require_dependency 'emoji'
require_dependency 'multisite_class_var'
module ApplicationHelper
include CurrentUser
include CanonicalURL::Helpers
include ConfigurableUrls
include GlobalPath
include MultisiteClassVar
multisite_class_var(:extra_body_classes) { Set.new }
def google_universal_analytics_json(ua_domain_name = nil)
result = {}
@ -75,7 +79,7 @@ module ApplicationHelper
end
def body_classes
result = []
result = ApplicationHelper.extra_body_classes.to_a
if @category && @category.url.present?
result << "category-#{@category.url.sub(/^\/c\//, '').gsub(/\//, '-')}"

View File

@ -103,6 +103,12 @@ class Plugin::Instance
end
end
def add_body_class(class_name)
reloadable_patch do |plugin|
::ApplicationHelper.extra_body_classes << class_name if plugin.enabled?
end
end
# Extend a class but check that the plugin is enabled
# for class methods use `add_class_method`
def add_to_class(class_name, attr, &block)