teeplate
Teeplate
A Crystal library for rendering multiple template files.
Installation
Add this to your application's shard.yml
:
dependencies:
teeplate:
github: mosop/teeplate
Supported Template Engines
- ECR
Usage
require "teeplate"
Example
Let's make our crystal init
template.
Template structure
- spec/
- spec_helper.cr.ecr
- {{file}}_spec.cr.ecr
- src/
- {{file}}/
- version.cr.ecr
- {{file}}.cr.ecr
- {{file}}/
- .gitignore
- .travis.yml
- LICENSE.ecr
- README.md.ecr
- shard.yml.ecr
Template file example
# shard.yml.ecr
name: <%= @file %>
version: 0.1.0
authors:
- <%= @author %>
license: MIT
Template class definition
class CrystalInitTemplate < Teeplate::FileTree
directory "#{__DIR__}/path/to/template"
@file : String
@class : String
@author : String
@year : Int32
def initialize(@file, @class, @author, @year)
end
end
Here we go!
CrystalInitTemplate.new("teeplate", "Teeplate", "mosop", 2016).render("/path/to/output")
Output structure
- spec/
- spec_helper.cr
- teeplate_spec.cr
- src/
- teeplate/
- version.cr
- teeplate.cr
- teeplate/
- .gitignore
- .travis.yml
- LICENSE
- README.md
- shard.yml
Output example
# shard.yml
name: teeplate
version: 0.1.0
authors:
- mosop
license: MIT
Overwriting
Forced
If a file already exists, Teeplate skips rendering the file. To force overwriting, set the :force
option:
class Template < Teeplate::FileTree
directory "/path/to/template"
@face : String
def initialize(@face)
end
end
Template.new(":)").render("/path/to/output")
Template.new(":(").render("/path/to/output", force: true) # files may be overwritten
Template.new(":P").render("/path/to/output") # nothing happens
Interactive
If the :interactive
option is true, Teeplate prompts us to select whether to overwrite an existing file.
shard.yml already exists...
overwrite(o)/keep(k)/diff(d)/overwrite all(a)/keep all(n) ?
Want to Do
- Listing rendered files (colorized)
Release Notes
- v0.2.0
- (Breaking Change) FileTree#initialize does not receive an output directory. Instead, FileTree#render does.
- Diff on overwriting confirmation
- Overwrite All / Keep All on overwriting confirmation
- v0.1.3
- :interactive option to select whether to overwrite existing files
- v0.1.2
- :force option to overwrite output files if they exist
Contributing
- Fork it ( https://github.com/mosop/teeplate/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- mosop - creator, maintainer