summaryrefslogtreecommitdiff
path: root/Meta
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-04-17 15:48:49 +0100
committerAndreas Kling <kling@serenityos.org>2022-04-18 14:16:28 +0200
commit872ad98ebac2a5dae9deb195921291e16d86e1c3 (patch)
treeba246f3481e04f77996fd51fbd8e4eb4ec9633d2 /Meta
parent5f3498d50f5b0d29b1c8b4f2043202c45ef7e081 (diff)
downloadserenity-872ad98ebac2a5dae9deb195921291e16d86e1c3.zip
LibWeb: Generate TransformFunction to/from string functions
Diffstat (limited to 'Meta')
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp53
1 files changed, 49 insertions, 4 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp
index 31f6c16e80..ce4c25f7cc 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp
@@ -53,6 +53,11 @@ ErrorOr<void> generate_header_file(JsonObject& transforms_data, Core::Stream::Fi
SourceGenerator generator { builder };
generator.append(R"~~~(
+#pragma once
+
+#include <AK/Optional.h>
+#include <AK/StringView.h>
+
namespace Web::CSS {
)~~~");
@@ -65,6 +70,9 @@ namespace Web::CSS {
});
generator.appendln("};");
+ generator.appendln("Optional<TransformFunction> transform_function_from_string(StringView);");
+ generator.appendln("StringView to_string(TransformFunction);");
+
generator.appendln("\n}");
TRY(file.write(generator.as_string_view().bytes()));
@@ -77,15 +85,52 @@ ErrorOr<void> generate_implementation_file(JsonObject& transforms_data, Core::St
SourceGenerator generator { builder };
generator.append(R"~~~(
+#include <LibWeb/CSS/TransformFunctions.h>
+#include <AK/Assertions.h>
+
namespace Web::CSS {
)~~~");
- transforms_data.for_each_member([&](auto& name, auto& value) {
- (void)name;
- (void)value;
+ generator.append(R"~~~(
+Optional<TransformFunction> transform_function_from_string(StringView name)
+{
+)~~~");
+ transforms_data.for_each_member([&](auto& name, auto&) {
+ auto member_generator = generator.fork();
+ member_generator.set("name", name);
+ member_generator.set("name:titlecase", title_casify_transform_function(name));
+ member_generator.append(R"~~~(
+ if (name.equals_ignoring_case("@name@"sv))
+ return TransformFunction::@name:titlecase@;
+)~~~");
+ });
+ generator.append(R"~~~(
+ return {};
+}
+)~~~");
+
+ generator.append(R"~~~(
+StringView to_string(TransformFunction transform_function)
+{
+ switch (transform_function) {
+)~~~");
+ transforms_data.for_each_member([&](auto& name, auto&) {
+ auto member_generator = generator.fork();
+ member_generator.set("name", name);
+ member_generator.set("name:titlecase", title_casify_transform_function(name));
+ member_generator.append(R"~~~(
+ case TransformFunction::@name:titlecase@:
+ return "@name@"sv;
+)~~~");
});
+ generator.append(R"~~~(
+ default:
+ VERIFY_NOT_REACHED();
+ }
+}
+)~~~");
- generator.appendln("}");
+ generator.appendln("\n}");
TRY(file.write(generator.as_string_view().bytes()));
return {};