From d953c908d2c6bbb8009f6a7895b74ad3f4a54d02 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 5 Mar 2020 18:28:18 +0530 Subject: [PATCH] FEATURE: add child theme components in theme metadata. Now theme creators can add an array of child theme components in about.json file for a top level theme. --- app/models/remote_theme.rb | 2 ++ app/models/theme.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb index e278da0ddb0..24336ee4ff0 100644 --- a/app/models/remote_theme.rb +++ b/app/models/remote_theme.rb @@ -40,6 +40,7 @@ class RemoteTheme < ActiveRecord::Base theme ||= Theme.new(user_id: user&.id || -1, name: theme_info["name"]) theme.component = theme_info["component"].to_s == "true" + theme.child_components = theme_info["components"].presence || [] remote_theme = new remote_theme.theme = theme @@ -63,6 +64,7 @@ class RemoteTheme < ActiveRecord::Base theme_info = RemoteTheme.extract_theme_info(importer) component = [true, "true"].include?(theme_info["component"]) theme = Theme.new(user_id: user&.id || -1, name: theme_info["name"], component: component) + theme.child_components = theme_info["components"].presence || [] remote_theme = new theme.remote_theme = remote_theme diff --git a/app/models/theme.rb b/app/models/theme.rb index 6a3b7a5643e..cce0005a607 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -2,6 +2,8 @@ class Theme < ActiveRecord::Base + attr_accessor :child_components + @cache = DistributedCache.new('theme') belongs_to :user @@ -61,6 +63,17 @@ class Theme < ActiveRecord::Base notify_theme_change(with_scheme: notify_with_scheme) end + after_create do + if !component? && child_components.present? + child_components.each do |url| + url = ThemeStore::GitImporter.new(url.strip).url + theme = RemoteTheme.find_by(remote_url: url)&.theme + theme ||= RemoteTheme.import_theme(url, user) + child_themes << theme + end + end + end + def update_javascript_cache! all_extra_js = theme_fields.where(target_id: Theme.targets[:extra_js]).pluck(:value_baked).join("\n") if all_extra_js.present?