-
Notifications
You must be signed in to change notification settings - Fork 0
Start
Razor Template Command, abreviated as barber.exe due to its relation with the Razor engine, is a small templating application that you can use from command line or from powershell. It reuses the Asp.Net MVC ViewEngine Razor with small stuff around to get the ability to use it simply in command mode with json, xml, properties models, even native objects when used from Powershell
Please note, this project starts for educational purposes and it should always be improved.
You can use it currently:
- Embedding our library in your own .Net 4 projects
- From command line
- From powershell
Get the sources and use it (a direct download to the installer prepared in order to simplify the process of registration will be available soon, also as a nuget package)
Currently the application just have two parameters:
- a string with the template
- a string with the json model
rtc.exe "Hello @Model.User" "{User : 'Rui'}"
prints:
Hello Rui
Simple example with pre-build json model:
clear
Add-PSSnapIn ArtOfNet.Powershell.RazorTemplateEngine
$template = "
=====================
Hello @Model.Name
=====================
Here is your shopping list:
@foreach(var item in @Model.List)
{
<text>- </text> @item <text></text>
}
"
$model = @{
Name = 'rui'
List = @('banana','apple','ananas')
}
$jtemp = RtcJson -value $model
rtc $template $json
A better example with native powershell objects: get a list of files and pass it to model
clear
$template = "
=====================
Hello @Model.Name
=====================
it is @DateTime.Now
Your are logged as @Model.User
Here is the files on the current folder:
@foreach(var item in @Model.List)
{
<text>- </text> @item <text></text>
}
"
$list = New-Object System.Collections.ArrayList
$files = get-childItem $home | %{ $list += $_.name}
$model = @{
Name = 'rui'
List = @($list)
User = $user
}
Add-PSSnapIn ArtOfNet.Powershell.RazorTemplateEngine -ErrorAction SilentlyContinue
$result = barber -tc $template -mc $model
$result
The improvement of the interaction is the next target as we have now a usable application:
- add real command line arguments and options
- add a read powershell command that pipes the exe (as exe is in .Net 4 and powershell limited to 3.5 snapins)
- clean up and organise temp folders for generated libs
- improve model and add specific helpers
- add the ability to use more Model sources (csv, properties, xml)
- add the ability to customise template base
- any ideas?
contact me via github or priave twitter message: @rhwy
enjoy!