Git Product home page Git Product logo

buildout.recipe.mako_template's Introduction

Maintainability Test Coverage

A buildout recipe for making files out of Mako templates, with focus on manageability of large number of templates.

The reasons behind creating this 'another' template recipe for buildout are wish of having:

  • mako with all power of python and good scoping in templates,
  • simple listing of source : destinatoin mapping,
  • and collision detection.
  • files: list of couples of templates and targets files paths separated by : symbol. It allow to specify if target should be executable, and to ignore a collision. Line has following format:

    source:target[:is_executable(true or false)[:collision_allowed(just a flag))]]

  • directories : list of lookup directories of the mako templates. Templates file paths are relative to these directories. (default: ${buildout:directory})

Additional options are simply forwarded to the templates, and options from all the other parts are made available through parts[<part-name>][<option-name>].

buildout.cfg:

[buildout]
parts = foo


[foo]
recipe = buildout.recipe.mako_template
author = Me
files = foo_1.sh.mako : foo_1.sh

foo_1.sh.mako:

echo Hello ${author}!

Will result in creation of foo_1.sh:

echo Hello Me!
[buildout]
parts = docker-compose

[project]
name = MyProject

[docker-compose]
recipe = buildout.recipe.mako_template
directories = ${buildout:directory}/templates
gateway_ports = 8080:8080
files =
    backend.dockerfile.mako  : .docker/backend.dockerfile
    frontend.dockerfile.mako : .docker/frontend.dockerfile
    gateway.dockerfile.mako  : .docker/gateway.dockerfile
    docker-compose.yaml.mako : docker-compose.yaml

docker-compose.yaml.mako:

...
gateway:
    container_name: ${parts['project']['name']}_gateway
    ports:
      - "${gateway_ports}"
...

Cases where one's template target are overridden by another template are detected automatically. For example, case:

files =
    foo_1.sh.mako : foo_1.sh
    foo_2.sh.mako : foo_1.sh  # overwrites ``target`` form above

will result in a build fail with the message:

Target collision is detected at 'foo_2.sh.mako : foo_1.sh'

Yet in some cases, it may be a desirable behavior, so it's possible to allow overwriting by adding collision_allowed flag.

This recipe is heavily inspired by brodul.recipe.template.

To get more examples and information on using mako templates visit makotemplates.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.