Browse Source

Add HTML node member function for fetching srcs

pull/2/head
Nubben 5 years ago
parent
commit
0763086a10
  1. 13
      src/html/Node.cpp
  2. 2
      src/html/Node.h
  3. 18
      src/html/TagNode.cpp
  4. 2
      src/html/TagNode.h
  5. 2
      src/html/TextNode.h

13
src/html/Node.cpp

@ -6,3 +6,16 @@ Node::Node(NodeType type) { @@ -6,3 +6,16 @@ Node::Node(NodeType type) {
Node::~Node() {
}
std::vector<std::string> Node::getSourceList() {
std::vector<std::string> returnVec;
for (std::shared_ptr<Node>& child : children) {
auto childSrcs = std::move(child->getSourceList());
returnVec.insert(returnVec.end(),
childSrcs.begin(),
childSrcs.end());
}
return returnVec;
}

2
src/html/Node.h

@ -23,6 +23,8 @@ public: @@ -23,6 +23,8 @@ public:
std::shared_ptr<Node> parent;
std::vector<std::shared_ptr<Node>> children;
std::shared_ptr<Component> component;
virtual std::vector<std::string> getSourceList();
};
#endif

18
src/html/TagNode.cpp

@ -2,3 +2,21 @@ @@ -2,3 +2,21 @@
TagNode::TagNode() : Node(NodeType::TAG) {
}
std::vector<std::string> TagNode::getSourceList() {
std::vector<std::string> returnVec;
auto propIter = properties.find("src");
if (propIter != properties.end()) {
returnVec.push_back(propIter->second);
}
for (std::shared_ptr<Node>& child : children) {
auto childSrcs = std::move(child->getSourceList());
returnVec.insert(returnVec.end(),
childSrcs.begin(),
childSrcs.end());
}
return returnVec;
}

2
src/html/TagNode.h

@ -9,6 +9,8 @@ public: @@ -9,6 +9,8 @@ public:
TagNode();
std::string tag;
std::map<std::string, std::string> properties;
std::vector<std::string> getSourceList() override;
};
#endif

2
src/html/TextNode.h

@ -7,6 +7,8 @@ class TextNode : public Node { @@ -7,6 +7,8 @@ class TextNode : public Node {
public:
TextNode();
std::string text;
std::vector<std::string> getSourceList() override { return {}; };
};
#endif

Loading…
Cancel
Save