mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
FIX: child theme component vars not resolved in parent
This commit is contained in:
parent
bf5ba5fbd1
commit
075a458489
|
@ -270,6 +270,18 @@ class Theme < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def all_theme_variables
|
||||
fields = {}
|
||||
([self] + (included_themes || [])).each do |theme|
|
||||
theme&.theme_fields.each do |field|
|
||||
next unless ThemeField.theme_var_type_ids.include?(field.type_id)
|
||||
next if fields.key?(field.name)
|
||||
fields[field.name] = field
|
||||
end
|
||||
end
|
||||
fields.values
|
||||
end
|
||||
|
||||
def add_child_theme!(theme)
|
||||
child_theme_relation.create!(child_theme_id: theme.id)
|
||||
@included_themes = nil
|
||||
|
|
|
@ -41,9 +41,7 @@ module Stylesheet
|
|||
colors.each do |n, hex|
|
||||
contents << "$#{n}: ##{hex} !default;\n"
|
||||
end
|
||||
theme&.theme_fields&.each do |field|
|
||||
next unless ThemeField.theme_var_type_ids.include?(field.type_id)
|
||||
|
||||
theme&.all_theme_variables&.each do |field|
|
||||
if field.type_id == ThemeField.types[:theme_upload_var]
|
||||
if upload = field.upload
|
||||
url = upload_cdn_path(upload.url)
|
||||
|
|
|
@ -155,6 +155,26 @@ HTML
|
|||
end
|
||||
|
||||
context 'theme vars' do
|
||||
|
||||
it 'works in parent theme' do
|
||||
|
||||
theme = Theme.new(name: 'theme', user_id: -1)
|
||||
theme.set_field(target: :common, name: :scss, value: 'body {color: $magic; }')
|
||||
theme.set_field(target: :common, name: :magic, value: 'red', type: :theme_var)
|
||||
theme.set_field(target: :common, name: :not_red, value: 'red', type: :theme_var)
|
||||
theme.save
|
||||
|
||||
parent_theme = Theme.new(name: 'parent theme', user_id: -1)
|
||||
parent_theme.set_field(target: :common, name: :scss, value: 'body {background-color: $not_red; }')
|
||||
parent_theme.set_field(target: :common, name: :not_red, value: 'blue', type: :theme_var)
|
||||
parent_theme.save
|
||||
parent_theme.add_child_theme!(theme)
|
||||
|
||||
scss, _map = Stylesheet::Compiler.compile('@import "theme_variables"; @import "desktop_theme"; ', "theme.scss", theme_id: parent_theme.id)
|
||||
expect(scss).to include("color:red")
|
||||
expect(scss).to include("background-color:blue")
|
||||
end
|
||||
|
||||
it 'can generate scss based off theme vars' do
|
||||
theme = Theme.new(name: 'theme', user_id: -1)
|
||||
theme.set_field(target: :common, name: :scss, value: 'body {color: $magic; content: quote($content)}')
|
||||
|
|
Loading…
Reference in New Issue
Block a user