我认为,CSS 语法和基本原则非常有用,而且不仅适用于样式。是否有任何 PARSE 引擎可以使用类似 CSS 的规则进行操作,例如 XML 的规则?
例如,我们可以创建类似框架的东西(是的,另一个),在其中我们以 xml 样式定义页面(只是示例,可能非常愚蠢或两个复杂):
<page id="index" url="/" controller="staticpage" />
<page id="about" url="/" controller="staticpage" action="about" />
<page id="post" url="/post/(\d+)" type="regex" controller="post" class="">
<param id="1" name="post_id" />
</page>
<page id="post_comment" url="/comment/(\d+)" type="regex" controller="post" action="comment" class="authneeded">
<param id="1" name="post_id" />
</page>
<page id="post_write" url="/write" type="regex" controller="staticpage" action="write" class="authneeded" />
然后为它写一个“CSS”:
* {
layout: "layout.html"; // default layout
}
*[action=''] {
action: "index"; // default action
}
#post_write {
layout: "adminlayout.html";
}
.authneeded {
redirect: "/";
}
.authneeded:loggedin { // pseudoclass which is set only if the user logged in.
// (maybe POSTS:loggedin .authneeded to apply only one
// pseudoclass)
redirect: false; // no, we don't need to redirect then the user logged in
}
这不是一种有趣的配置方式吗?更好的是,我们可以创建一个管理脚本(受 jquery 启发;)
./admin #about addClass authneeded
./admin "#post PARAM" attr id param_post
那么,是否有任何引擎可以使用类似 CSS 的规则进行操作?