This commit is contained in:
2024-08-06 17:01:14 -03:00
parent fe917da89d
commit a2394a7313
6 changed files with 133 additions and 42 deletions

View File

@ -1,6 +1,11 @@
require "xml"
module Tartrazine
def self.theme(name : String) : Theme
path = File.join("styles", "#{name}.xml")
Theme.from_xml(File.read(path))
end
class Style
# These properties are tri-state.
# true means it's set
@ -52,11 +57,7 @@ module Tartrazine
return s if s.complete?
# Form the hierarchy of parent styles
parents = ["Background"]
parts = token.underscore.split("_").map(&.capitalize)
parts.each_with_index do |_, i|
parents << parts[..i].join("")
end
parents = style_parents(token)
s = parents.map do |parent|
styles[parent]
@ -68,6 +69,15 @@ module Tartrazine
s
end
def style_parents(token)
parents = ["Background"]
parts = token.underscore.split("_").map(&.capitalize)
parts.each_with_index do |_, i|
parents << parts[..i].join("")
end
parents
end
# Load from a Chroma XML file
def self.from_xml(xml : String) : Theme
document = XML.parse(xml)
@ -100,4 +110,4 @@ module Tartrazine
theme
end
end
end
end