Skip to content

Commit

Permalink
Replaced s:enable with an overload of s:when to simplify the language
Browse files Browse the repository at this point in the history
  • Loading branch information
KaruroChori committed Jan 21, 2025
1 parent 02f0565 commit a9b42f7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ As prop, attribute variants of `for` and `for-props`. They add attributes/values

As for the element version, to introduce the value of an expression as value of a prop `xxx`.

### enable.xxx

If the condition is true, the prop `xxx` is added with no specific value.

### prop.xxx

To generate new property whose name and value are determined by the pair passed as value.
Expand All @@ -236,4 +232,8 @@ To generate new property whose name and value are determined by the pair passed

### when

To test if the current element should be shown, if and only if the expression is `true`.
To test if the current element should be rendered, if and only if the expression is `true`.

### when.xxx

If and only if the condition is true, the prop `xxx` is added as empty string. Else it is skipped.
1 change: 0 additions & 1 deletion include/vs-templ.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ struct preprocessor{
const char *PROP_NAME_PROP;
const char *PROP_VALUE_PROP;

const char *ENABLE_PROP;

const char *WHEN_PROP;

Expand Down
4 changes: 4 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ bool includefn (const char* path, pugi::xml_document& ref){
}

int main(int argc, const char* argv[]){
//Workaround to avoid problems with pugixml... but it is not perfect.
//The solution is to never use `as_float` and always handle them externally.
std::setlocale(LC_ALL, "C");

const char* ns_prefix="s:";
if(argc==0 || argc > 4){
std::cerr<<"Wrong usage:\n\t"<<argv[0]<<" <template-file> <data-file> [namespace=`s:`]\nOR\t "<<argv[0]<<"[namespace=`s:`] and two input streams\n";
Expand Down
6 changes: 2 additions & 4 deletions src/vs-templ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ void preprocessor::ns_strings::prepare(const char * ns_prefix){
STRLEN("for-props.src")+STRLEN("for-props.filter")+STRLEN("for.order-by")+STRLEN("for-props.offset")+STRLEN("for-props.limit")+

STRLEN("value")+
STRLEN("enable")+
STRLEN("prop.name")+STRLEN("prop.value")+
STRLEN("when")
];
Expand Down Expand Up @@ -293,7 +292,6 @@ void preprocessor::ns_strings::prepare(const char * ns_prefix){

WRITE(VALUE_PROP,"value");

WRITE(ENABLE_PROP,"enable");

WRITE(PROP_NAME_PROP,"prop.name");
WRITE(PROP_VALUE_PROP,"prop.value");
Expand Down Expand Up @@ -907,12 +905,12 @@ void preprocessor::_parse(std::optional<pugi::xml_node_iterator> stop_at){
/* Error? */
}
}
else if(cexpr_strneqv(attr.name()+ns_prefix.length(),"enable.")){
else if(cexpr_strneqv(attr.name()+ns_prefix.length(),"when.")){
auto val = resolve_expr(attr.value());
if(val.has_value() && std::holds_alternative<int>(*val)){
auto v = (val.value());
if(std::get<int>(*val)==true){
last.append_attribute(attr.name()+ns_prefix.length()+sizeof("enable.")-1);
last.append_attribute(attr.name()+ns_prefix.length()+sizeof("when.")-1);
}
/* Error? */
}
Expand Down

0 comments on commit a9b42f7

Please sign in to comment.