gysb 是 Generate Your Swifty Boilerplate 的缩写。
Swift 对 swift/gyb 的实现
$ cat TestResources/simple1/a.txt.gysb
Hello 100%%
%{
let y = 10
let x = 42
func succ(_ a: Int) -> Int {
return a + 1
}
}%
I can assure you that ${x} < ${succ(x)}
% if y > 7 {
% for _ in 0..<3 {
y is greater than seven!
% }
% } else {
y is less than or equal to seven
% }
The End.
$ swift run gysb Examples/simple1/a.txt.gysb
Hello 100%
I can assure you that 42 < 43
y is greater than seven!
y is greater than seven!
y is greater than seven!
The End.
请参阅 Examples
和 Tests
。
$ swift run gysb --help
Usage: .build/x86_64-apple-macosx10.10/debug/gysb [mode] [flags] paths...
# mode
--help: print help
--parse: print AST
--compile: print compiled Swift
--render: render template (default)
# flags
--write: write output on same directory (extension removed)
--source-dirs: paths means directory and search *.gysb (automatically enable `--write`)
%%
: 转义的 %
$$
: 转义的 $
%{ <swift-code> }%
: 代码块% <swift-code> <newline>
: 代码行${ <swift-code> }
: 代码替换通过使用 gysb.json
,你可以使用 gysb 更多有用的功能。gysb 命令会在相同或祖先目录中搜索每个 gysb 模板文件的 gysb.json
。
Examples/simple_include
中的示例。Examples/yaml
中的示例。有一些安装方法。
$ brew install omochi/taps/gysb
检出仓库。
$ git clone https://github.com/omochi/gysb.git
$ cd gysb
构建。
$ swift build
获取路径。
$ echo $(pwd)/.build/debug
/Users/omochi/github/omochi/gysb/.build/debug
设置路径。
$ vim ~/.bash_profile
此仓库由 SwiftPM 维护。
使用 xcodeproj 并使用它进行工作。
$ swift package generate-xcodeproj
$ open gysb.xcodeproj