From 34f98f362f54df17e7a6fa58ffcda5677bb0d234 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 28 Sep 2017 13:16:51 -0400 Subject: [PATCH] Add a plugin hook to specify a class on the body of the document --- app/helpers/application_helper.rb | 6 +++++- lib/plugin/instance.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 803f82e27e4..8e81cfe5d55 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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(/\//, '-')}" diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb index 3eb44c76bd1..e84ab6e413e 100644 --- a/lib/plugin/instance.rb +++ b/lib/plugin/instance.rb @@ -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)