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   荣锋亮  阅读(178)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-03-25 terraform plugin 版本以及changlog 规范
2019-03-25 Terraform Detecting Drift
2019-03-25 使用terraform-provider-s3 操作minio
2019-03-25 Terraform 自定义provider 开发
2019-03-25 Writing Custom Providers
2017-03-25 luarocks 安装
2017-03-25 几个中文排版web 类库

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示