mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
83e649d08e
commit
d953c908d2
@ -40,6 +40,7 @@ class RemoteTheme < ActiveRecord::Base
|
|||||||
theme ||= Theme.new(user_id: user&.id || -1, name: theme_info["name"])
|
theme ||= Theme.new(user_id: user&.id || -1, name: theme_info["name"])
|
||||||
|
|
||||||
theme.component = theme_info["component"].to_s == "true"
|
theme.component = theme_info["component"].to_s == "true"
|
||||||
|
theme.child_components = theme_info["components"].presence || []
|
||||||
|
|
||||||
remote_theme = new
|
remote_theme = new
|
||||||
remote_theme.theme = theme
|
remote_theme.theme = theme
|
||||||
@ -63,6 +64,7 @@ class RemoteTheme < ActiveRecord::Base
|
|||||||
theme_info = RemoteTheme.extract_theme_info(importer)
|
theme_info = RemoteTheme.extract_theme_info(importer)
|
||||||
component = [true, "true"].include?(theme_info["component"])
|
component = [true, "true"].include?(theme_info["component"])
|
||||||
theme = Theme.new(user_id: user&.id || -1, name: theme_info["name"], component: 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
|
remote_theme = new
|
||||||
theme.remote_theme = remote_theme
|
theme.remote_theme = remote_theme
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
class Theme < ActiveRecord::Base
|
class Theme < ActiveRecord::Base
|
||||||
|
|
||||||
|
attr_accessor :child_components
|
||||||
|
|
||||||
@cache = DistributedCache.new('theme')
|
@cache = DistributedCache.new('theme')
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
@ -61,6 +63,17 @@ class Theme < ActiveRecord::Base
|
|||||||
notify_theme_change(with_scheme: notify_with_scheme)
|
notify_theme_change(with_scheme: notify_with_scheme)
|
||||||
end
|
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!
|
def update_javascript_cache!
|
||||||
all_extra_js = theme_fields.where(target_id: Theme.targets[:extra_js]).pluck(:value_baked).join("\n")
|
all_extra_js = theme_fields.where(target_id: Theme.targets[:extra_js]).pluck(:value_baked).join("\n")
|
||||||
if all_extra_js.present?
|
if all_extra_js.present?
|
||||||
|
Loading…
Reference in New Issue
Block a user