mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: child theme component vars not resolved in parent
This commit is contained in:
@@ -270,6 +270,18 @@ class Theme < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
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)
|
def add_child_theme!(theme)
|
||||||
child_theme_relation.create!(child_theme_id: theme.id)
|
child_theme_relation.create!(child_theme_id: theme.id)
|
||||||
@included_themes = nil
|
@included_themes = nil
|
||||||
|
@@ -41,9 +41,7 @@ module Stylesheet
|
|||||||
colors.each do |n, hex|
|
colors.each do |n, hex|
|
||||||
contents << "$#{n}: ##{hex} !default;\n"
|
contents << "$#{n}: ##{hex} !default;\n"
|
||||||
end
|
end
|
||||||
theme&.theme_fields&.each do |field|
|
theme&.all_theme_variables&.each do |field|
|
||||||
next unless ThemeField.theme_var_type_ids.include?(field.type_id)
|
|
||||||
|
|
||||||
if field.type_id == ThemeField.types[:theme_upload_var]
|
if field.type_id == ThemeField.types[:theme_upload_var]
|
||||||
if upload = field.upload
|
if upload = field.upload
|
||||||
url = upload_cdn_path(upload.url)
|
url = upload_cdn_path(upload.url)
|
||||||
|
@@ -155,6 +155,26 @@ HTML
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'theme vars' do
|
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
|
it 'can generate scss based off theme vars' do
|
||||||
theme = Theme.new(name: 'theme', user_id: -1)
|
theme = Theme.new(name: 'theme', user_id: -1)
|
||||||
theme.set_field(target: :common, name: :scss, value: 'body {color: $magic; content: quote($content)}')
|
theme.set_field(target: :common, name: :scss, value: 'body {color: $magic; content: quote($content)}')
|
||||||
|
Reference in New Issue
Block a user