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.
This commit is contained in:
Vinoth Kannan 2020-03-05 18:28:18 +05:30
parent 83e649d08e
commit d953c908d2
2 changed files with 15 additions and 0 deletions

View File

@ -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

View File

@ -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?