summaryrefslogtreecommitdiff
path: root/Meta
diff options
context:
space:
mode:
authorKarthik Karanth <karanth.karthik@gmail.com>2023-05-25 23:57:09 -0700
committerAndreas Kling <kling@serenityos.org>2023-05-27 16:02:33 +0200
commit72507c318a3fc8045e19c0ba5191f125e6d9a4a4 (patch)
treebb162803a6b98ed18440953b91133a0559eae9b7 /Meta
parente78d1ec03a5c5a8b5945fd41016b8931b9de38c2 (diff)
downloadserenity-72507c318a3fc8045e19c0ba5191f125e6d9a4a4.zip
LibWeb: Add logical-alias-for in Properties.json
This allows for succint definitions of logical properties, by allowing them to inherit initial values, valid identifiers, etc from another property
Diffstat (limited to 'Meta')
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp
index fae37000c1..c542b6540d 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp
@@ -12,6 +12,7 @@
#include <LibCore/ArgsParser.h>
#include <LibMain/Main.h>
+ErrorOr<void> replace_logical_aliases(JsonObject& properties);
ErrorOr<void> generate_header_file(JsonObject& properties, Core::File& file);
ErrorOr<void> generate_implementation_file(JsonObject& properties, Core::File& file);
@@ -36,6 +37,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
VERIFY(json.is_object());
auto properties = json.as_object();
+ TRY(replace_logical_aliases(properties));
+
auto generated_header_file = TRY(Core::File::open(generated_header_path, Core::File::OpenMode::Write));
auto generated_implementation_file = TRY(Core::File::open(generated_implementation_path, Core::File::OpenMode::Write));
@@ -45,6 +48,37 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
+ErrorOr<void> replace_logical_aliases(JsonObject& properties)
+{
+ AK::HashMap<DeprecatedString, DeprecatedString> logical_aliases;
+ properties.for_each_member([&](auto& name, auto& value) {
+ VERIFY(value.is_object());
+ const auto& value_as_object = value.as_object();
+ const auto logical_alias_for = value_as_object.get_deprecated_string("logical-alias-for"sv);
+ if (logical_alias_for.has_value()) {
+ logical_aliases.set(name, logical_alias_for.value());
+ }
+ });
+
+ for (auto& [name, alias] : logical_aliases) {
+ auto const maybe_alias_object = properties.get_object(alias);
+ if (!maybe_alias_object.has_value()) {
+ dbgln("No property '{}' found for logical alias '{}'", alias, name);
+ VERIFY_NOT_REACHED();
+ }
+ JsonObject alias_object = maybe_alias_object.value();
+
+ // Copy over anything the logical property overrides
+ properties.get_object(name).value().for_each_member([&](auto& key, auto& value) {
+ alias_object.set(key, value);
+ });
+
+ properties.set(name, alias_object);
+ }
+
+ return {};
+}
+
ErrorOr<void> generate_header_file(JsonObject& properties, Core::File& file)
{
StringBuilder builder;