teeplate

A library for rendering multiple template files
0.1.4.1 released
mosop/teeplate
16 13 2
mosop

Teeplate

A Crystal library for rendering multiple template files.

Build Status

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
  • .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(out_dir, @file, @class, @author, @year)
    super out_dir
  end
end

Here we go!

CrystalInitTemplate.new("/path/to/output", "teeplate", "Teeplate", "mosop", 2016).render

Output structure

  • spec/
    • spec_helper.cr
    • teeplate_spec.cr
  • src/
    • teeplate/
      • version.cr
    • teeplate.cr
  • .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(out_dir, @face)
    super out_dir
  end
end

Template.new("/path/to/output", ":)").render
Template.new("/path/to/output", ":(").render(force: true) # files to be overwritten
Template.new("/path/to/output", ":P").render # nothing happens

Interactive

If the :interactive option is true, Teeplate prompts us to select whether to overwrite an existing file.

shard.yml already exists...
O(overwrite)/K(keep) ?

Wish List

  • Diff option on overwriting
  • Listing rendered files (colorized)

Release Notes

  • 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

  1. Fork it ( https://github.com/mosop/teeplate/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • mosop - creator, maintainer
teeplate:
  github: mosop/teeplate
  version: ~> 0.1.4.1
License MIT
Crystal none

Authors

Dependencies 0

Development Dependencies 2

  • have_files ~> 0.3.0
    {'github' => 'mosop/have_files', 'version' => '~> 0.3.0'}
  • stdio ~> 0.1.2
    {'github' => 'mosop/stdio', 'version' => '~> 0.1.2'}

Dependents 2

Last synced .
search fire star recently