存在哪些模板系统适合编写服务创建方法

发布于 2024-11-03 07:53:49 字数 911 浏览 0 评论 0原文

我需要构建一个批量服务创建守护进程,该守护进程可以提供一个数据表,然后创建一组预先固定的服务。然而,服务的类型可能是多种多样的,并且后面的步骤可能需要前面步骤的输出。

看来我需要用某种特定于领域的语言来实现,这样我就可以定义模板配方。然后可以通过模板引擎传递该数据,并在最终运行之前从数据表中进行替换。

重用现有的语言基础设施以允许更复杂的配方使用流程控制并定义一组受限制的基本操作是有意义的。然而,我希望简单的食谱不需要改变语言知识,因为最终用户可能没有软件经验。

我会设想一个简单的模板配方,看起来像这样:

# Create a service from NodeA to NodeC via NodeB
# Parameters are:
#   node a id, node a port, node b id, node c id, node c port, comment
node_a = node_a_type($1)
conn_a = node_a.create_connection($2, $7)
node_b = node_b_type($3)
conn_b = node_b.create_connection(conn_a.output_port, $7)
node_c = node_c_type($4)
conn_c = node_c.terminate_connection(conn_b.output_port, $5, $7)

我建议使用 python 作为基本语言,因为我熟悉它。然而,Python wiki 建议了很多不同的选项(http://wiki.python.org/moin/Templated< /a>),大多数都是针对 HTML/XML 模板解决方案。深入了解不同系统的优缺点将不胜感激。

I have a requirement to build a bulk service creation daemon that can be fed a table of data and then go off and create a set of pre-canned services. However the type of services are potentially many and varied and potentially later steps will require the output of previous steps.

It seems what I need to implement in some sort of domain specific language that allow me to define a template recipe. This can then be passed through a template engine with substitutions made from the table of data before finally being run.

It would make sense to re-use an existing language infrastructure to allow the more complex recipes to use flow control and to define a restricted set of base operations. However I'd like the simple recipes to not require knowledge of the language to alter as the end users will not likely have software experience.

I would envision a simple template recipe looking something like:

# Create a service from NodeA to NodeC via NodeB
# Parameters are:
#   node a id, node a port, node b id, node c id, node c port, comment
node_a = node_a_type($1)
conn_a = node_a.create_connection($2, $7)
node_b = node_b_type($3)
conn_b = node_b.create_connection(conn_a.output_port, $7)
node_c = node_c_type($4)
conn_c = node_c.terminate_connection(conn_b.output_port, $5, $7)

I suggest python as a base language as I'm familiar with it. However the Python wiki suggests a lot of different options (http://wiki.python.org/moin/Templating) with most being aimed HTML/XML template solutions. Insight into the pros and cons of different systems would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2024-11-10 07:53:49

我认为 MakoJinja2 都可以满足要求。

  • 两者都不是 html/xml 模板,而是基于文本的。
  • 两者都很受欢迎并且有据可查。
  • Mako 具有更多 Python 语法,而 Jinja 的一大优势是它支持沙箱,这可能对您有用。

I think Mako or Jinja2 both can fit the bill.

  • Both are not html/xml templates but are text based.
  • Both are popular and well documented.
  • Mako has more pythonic syntax where as BIG advantage with Jinja is, it supports sandboxing which might be useful for you.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文