bashible 模版使用

bashible 内置了一个模版系统,使用灵活,可以用来方便的生成html 页面,官方提供了一个比较完备的demo
可以学习

generating_html_from_a_template

  • 项目结构
 
├── README
├── generate.bash
├── index.html
├── index.tpl
├── js
├── bar.js
└── foo.js
└── parts
    ├── body.tpl
    └── head.tpl
  • 项目说明
    .tpl的都是模版引擎,index.tpl 为入口,body.tpl ,head.tpl为片段的,index.tpl 聚合片段
    index.tpl
 
<html>
  <head>
    $( template parts/head.tpl )
  </head>
  <body>
    $( template parts/body.tpl )
  </body>
</html>

head.tpl
js 内容替换,使用了变量 FOO_OR_BAR

 
<script type='text/javascript'>
  $( cat js/$FOO_OR_BAR.js )
</script>

body.tpl
时间替换

<h1> Now is $( date ) </h1>

生成模版bash
generate.bash

 
#!/usr/local/bin/bashible
use template
# this variable is used to include either foo.js or bar.js in the HTML head (see parts/head.tpl template)
FOO_OR_BAR=bar #foo
@ Building the HTML from a template
  - output_to index.html template index.tpl

运行

  • 命令
./generate.bash
  • 效果

 

 

说明

对于不太懂shell 编程的人员来说bashible是一个很不错的工具,可以和容器集成起来,搞一个灵活的配置部署系统

参考资料

https://github.com/mig1984/bashible

posted on 2020-03-25 17:09  荣锋亮  阅读(177)  评论(0编辑  收藏  举报

导航