[PowerShell]template engine
今天讨论的是如何在Powershell里实现一个简单的Template Engine的功能。
假设模板文件的内容如下:template.tt
hello $name
welcome $company
模板引擎的函数定义在Invoke-Template.ps1
function Invoke-Template {
param(
[string]$Path,
[Scriptblock]$ScriptBlock
)
function Get-Template {
param($TemplateFileName)
$content = [IO.File]::ReadAllText(
(Join-Path $Path $TemplateFileName) )
$res = Invoke-Expression "@`"`r`n$content`r`n`"@"
return $res
}
& $ScriptBlock
}
调用的Powershell script是
. .\Invoke-Template.ps1
$root = $PSScriptRoot
$res = invoke-Template -Path $root -scriptblock { $name="andy"
$company="hp"
Get-Template tempalte.tt
} $res
输出为

[PowerShell]template engine的更多相关文章
- The template engine
Play has an efficient templating system which allows to dynamically generate HTML, XML, JSON or any ...
- 如何选择Javascript模板引擎(javascript template engine)?
译者 jjfat 日期:2012-9-17 来源: GBin1.com 随着前端开发的密集度越来越高,Ajax和JSON的使用越来越频繁,大家肯定免不了在前台开发中大量的使用标签,常见到的例子如下: ...
- JFinal Template Engine 使用
官方文档:JFinal Template Engine 文档
- 【Reship】use of tangible T4 template engine
1.first of all 之前在 “使用T4模板生成代码 – 初探” 文章简单的使用了T4模板的生成功能,但对于一个模板生成多个实例文件,如何实现这个方式呢?无意发现一个解决方案 “Multipl ...
- 最近兰州的js风格写个插件和一个template engine
/* *@Product Name: Rational Framework Author: Calos Description: pager !important: pager */ (functio ...
- Js template engine
P http://www.jquery4u.com/javascript/10-javascript-jquery-templates-engines/ http://www.creativebloq ...
- Juicer——a fast template engine
https://blog.csdn.net/yutao_struggle/article/details/79201688 当前最新版本: 0.6.8-stable Juicer 是一个高效.轻量的前 ...
- 500 Lines or Less: A Template Engine(模板引擎)
介绍: 多数项目都是包含很多的逻辑处理,只有少部分的文字文本处理.编程语言非常擅长这类项目.但是有一些项目只包含了少量的逻辑处理,大量的文本数据处理.对于这些任务,我们期望有一个工具能够很好的处理这些 ...
- [Pug] Template Engine -- Jade/ Pug
Looking at the follow code: .wrapper - const upName = name && name.toUpperCase(); h2 | Hello ...
随机推荐
- 6-EasyNetQ之订阅
一个EasyNetQ订阅者订阅一种消息类型(消息类为.NET 类型).通过调用Subcribe方法一旦对一个类型设置了订阅,一个持久化队列就会在RabbitMQ broker上被创建,这个类型的任何消 ...
- matlab学习笔记(3)
数据分析: 多项式: 多项式表示:p = [1 2 3 0]; //表示 1*x^3+2*x^2+3*x^1+0 ,系数从高次向低次项,0系数不能省略. roots函数:求解多项式的根.roots(p ...
- 装饰器,装饰器多参数的使用(*arg, **kwargs),装饰器的调用顺序
一.#1.执行outer函数,并且将其下面的函数名,当作参数 #2.将outer的返回值重新赋值给f1 = outer的返回值 #3.新f1 = inner #4.func = 原f1 #!/usr/ ...
- koa1链接mongodb
1.项目下安装mongodb和mongoose npm install mongodb --save-dev npm install mongoose --save-dev 2.router中 var ...
- GUI编程01
1 tkinter TkInter是标准的Python GUI库.的Python与Tkinter的结合提供了一个快速和容易的方法来创建GUI应用程序. Tkinter的提供了一个强大的面向对象的接口T ...
- ZROI2018提高day1t3
传送门 分析 考场上想到了先枚举p的长度,在枚举这个长度的所有子串,期望得分40~50pts,但是最终只得了20pts,这是因为我写的代码在验证中总是不断删除s'中的第一个p,而这种方式不能解决形如a ...
- Luogu 2831 [NOIP2016] 愤怒的小鸟
第一眼看成爆搜的状压dp,膜Chester大神犇. 考虑到三个不在同一直线上的点可以确定一条抛物线,而固定点$(0, 0)$和不在同一直线上这两个条件是题目中给定的,所以我们只要枚举两个点然后暴力算抛 ...
- 《Effective Java》第8章 通用程序设计
第47条:了解和使用类库 Top 100 Java Libraries on Github 2016 Library Number of Projects Type % of projects jun ...
- JQuery UI - selectable
·概述 Selectable插件允许用户对指定的元素进行选中的动作.此外还支持按住Ctrl键单击或拖拽选择多个元素. 官方示例地址:http://jqueryui.com/demos/selectab ...
- sqlserver清楚文本中的换行符
REPLACE(@string,CHAR(13)+CHAR(10),char(32))