Craeted whiledir tag.
This commit is contained in:
parent
2dd41238de
commit
426b98805c
4
Tag.cpp
4
Tag.cpp
@ -17,6 +17,7 @@
|
|||||||
#include "__jet.h"
|
#include "__jet.h"
|
||||||
#include "__while.h"
|
#include "__while.h"
|
||||||
#include "__header.h"
|
#include "__header.h"
|
||||||
|
#include "__whiledir.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace jet {
|
namespace jet {
|
||||||
@ -155,6 +156,9 @@ namespace jet {
|
|||||||
} else if(ifTagName(in, "header")) {
|
} else if(ifTagName(in, "header")) {
|
||||||
__header _header(in, out, global);
|
__header _header(in, out, global);
|
||||||
continue;
|
continue;
|
||||||
|
} else if(ifTagName(in, "whiledir")) {
|
||||||
|
__whiledir _whiledir(in, out, global);
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
out.write(in.charAt(0));
|
out.write(in.charAt(0));
|
||||||
in.nextChar();
|
in.nextChar();
|
||||||
|
@ -25,7 +25,7 @@ namespace jet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
parseContainer(container);
|
processContainer(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
36
__whiledir.cpp
Normal file
36
__whiledir.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "__whiledir.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
#include "__mysql.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace jet {
|
||||||
|
|
||||||
|
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
||||||
|
if(!variableDefined("path"))
|
||||||
|
throw coreutils::Exception("whiledir tag must specify a path.");
|
||||||
|
if(!variableDefined("name"))
|
||||||
|
throw coreutils::Exception("whiledir tag requires a name tag.");
|
||||||
|
if(variableDefined("sort") && (variables["sort"] == "true")) {
|
||||||
|
std::vector<std::filesystem::directory_entry> entries;
|
||||||
|
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str()))
|
||||||
|
entries.push_back(entry);
|
||||||
|
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); });
|
||||||
|
for(const auto &entry : entries) {
|
||||||
|
variables[variables["name"]] = entry.path();
|
||||||
|
processContainer(container);
|
||||||
|
container.reset();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) {
|
||||||
|
variables[variables["name"]] = entry.path();
|
||||||
|
processContainer(container);
|
||||||
|
container.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
__whiledir.h
Normal file
19
__whiledir.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef ____whiledir_h__
|
||||||
|
#define ____whiledir_h__
|
||||||
|
|
||||||
|
#include "Tag.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include "MString.h"
|
||||||
|
|
||||||
|
namespace jet {
|
||||||
|
|
||||||
|
class __whiledir : public Tag {
|
||||||
|
|
||||||
|
public:
|
||||||
|
__whiledir(coreutils::ZString &in, coreutils::MString &parent, Global &global);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -55,5 +55,8 @@
|
|||||||
$[ls]
|
$[ls]
|
||||||
<read file="compile" name="file" />
|
<read file="compile" name="file" />
|
||||||
$[filex]
|
$[filex]
|
||||||
|
<whiledir path="." name="file" sort="true">
|
||||||
|
#[file]
|
||||||
|
</whiledir>
|
||||||
</html>
|
</html>
|
||||||
</jet>
|
</jet>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user