【问题标题】:What recommendations for a "simple" templating system?对于“简单”的模板系统有什么建议?
【发布时间】:2018-10-12 16:41:28
【问题描述】:

基于How do I make multiple targets from a set of templates for the source?,我现在想实现一个简单的模板引擎。

我很高兴使用 sed 直接替换,但我也想要条件。

例如,如果一个模板看起来像这样:

This is the file for engine:#if version != 'latest'##version#-#endif#alpine

不同版本的输出(例如 7.0 和最新版本)。

This is the file for engine:7.0-alpine
This is the file for engine:alpine

sed 中写这句话虽然可能,但确实意味着我不得不重新发明轮子。

对于适用于 unix 环境的简单模板有哪些建议?

【问题讨论】:

    标签: makefile templating


    【解决方案1】:

    GNUmake 是一种完整但相当笨拙的函数式编程语言。这样做的好处是,您可以随意编写代码,因为 a) 没有“GNUmake 教会”会看不起您的编码风格,并且 b) 无论如何它看起来都很难看。也就是说,从隐藏了许多奇怪之处的源库中获得一点帮助并不是一个坏建议。

    使用gmtt,您的示例可能如下所示:

    include gmtt.mk
    
    version = latest
    
    VERSION_STR = $(if $(call str-eq,$(version),latest),,$(version))
    $(info This is the file for engine: $(VERSION_STR)alpine)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      相关资源
      最近更新 更多