-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
169 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,6 @@ foreach( source ${SOURCE_LIST} ) | |
PRIVATE | ||
Spaic | ||
SpaicCSS | ||
SpaicDOM | ||
) | ||
endforeach( source ${SOURCE_LIST} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <spaic/VNode.hpp> | ||
|
||
namespace spaic::dom | ||
{ | ||
std::string render(spaic::vnode::VNode node); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <string> | ||
#include <spaic-dom/Render.hpp> | ||
#include <spaic/VNode.hpp> | ||
#include <type_traits> | ||
#include <variant> | ||
#include <sstream> | ||
#include <vector> | ||
|
||
namespace spaic::dom | ||
{ | ||
|
||
template <class... Ts> | ||
struct overloaded : Ts... | ||
{ | ||
using Ts::operator()...; | ||
}; | ||
template <class... Ts> | ||
overloaded(Ts...)->overloaded<Ts...>; | ||
|
||
std::string render_base(spaic::vnode::VNodeBase node) | ||
{ | ||
std::ostringstream stream; | ||
std::visit( | ||
overloaded{ | ||
[&](std::nullptr_t &arg) { | ||
// do nothing, nullptr means empty string. | ||
}, | ||
[&](std::string &arg) { stream << arg; }, | ||
[&](const char *&arg) { stream << arg; }, | ||
[&](spaic::comp::ComponentParent &arg) { | ||
if (arg.native_node_name) | ||
{ | ||
stream << "<" << *arg.native_node_name << ">\n"; | ||
} | ||
for (const auto &child : arg.children) | ||
{ | ||
stream << render(child) << "\n"; | ||
} | ||
if (arg.native_node_name) | ||
{ | ||
stream << "</" << *arg.native_node_name << ">\n"; | ||
} | ||
}, | ||
[&](spaic::comp::ComponentSingle &arg) { stream << typeid(std::decay_t<decltype(arg)>).name() << "(ComponentSingle)"; }, | ||
[&](auto arg) { | ||
using T = std::decay_t<decltype(arg)>; | ||
if constexpr (std::is_same_v<T, bool>) | ||
{ | ||
stream << std::boolalpha << arg << std::noboolalpha; | ||
} | ||
else if constexpr (std::is_fundamental_v<T>) | ||
{ | ||
stream << arg; | ||
} | ||
else | ||
{ | ||
stream << "비야네 당신은 틀렸어!" << typeid(T).name(); | ||
} | ||
}, | ||
}, | ||
node); | ||
return stream.str(); | ||
} | ||
std::string render(spaic::vnode::VNode node) | ||
{ | ||
std::ostringstream stream; | ||
std::visit( | ||
[&](auto &&arg) { | ||
// wtf is that fucking bitches | ||
using T = std::decay_t<decltype(arg)>; | ||
if constexpr (std::is_same_v<T, std::vector<spaic::vnode::VNode>>) | ||
{ | ||
for (const auto &element : arg) | ||
{ | ||
stream << render(element); | ||
} | ||
} | ||
else if constexpr (std::is_same_v<T, spaic::vnode::VNodeBase>) | ||
{ | ||
stream << render_base(arg); | ||
} | ||
else | ||
{ | ||
stream << "wtf is that you should report this: " << typeid(T).name(); | ||
} | ||
}, | ||
node.value); | ||
return stream.str(); | ||
} | ||
} // namespace spaic::dom |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <spaic/Component.hpp> | ||
#include <spaic/VNode.hpp> | ||
|
||
namespace spaic::comp | ||
{ | ||
ComponentSingle::ComponentSingle(NativeNodeName native_node_name) : native_node_name(native_node_name) {} | ||
|
||
ComponentParent::ComponentParent(NativeNodeName native_node_name, std::vector<spaic::vnode::VNode> children) : native_node_name(native_node_name), children(children) {} | ||
} // namespace spaic::comp |