极简的代码生成器 Agen

码农软件 · 软件分类 · 代码生成工具 · 2019-03-06 14:13:29

软件介绍

 一个极简的代码生成器,可以嵌进你自己的项目中。

Latest Version Travis CI Status Codecov Status Doc Status

    特性

  • 简化到不能再简化的API

  • 支持自定义 Jinja Env

  • 可以作为命令行工具使用

无模版

agen 本身并不提供任何代码模版,只是提供一种能力,将代码模版化。如果需要使用已有的公开模版,请通过另一个优秀的开源库 Cookiecutter 。

为什么?

    agen 十分轻量级,可以在几分钟内完美集成到你自己的项目中。

    我非常喜爱 Cookiecutter 这个非常酷的项目,但它的绝大多数功能对我来说太重了。

    安装

    使用 pip 安装:

pip install agen

    从源代码安装:

clone https://github.com/yufeiminds/agen.git
cd agen
python setup.py install

    快速指南

    在 agen 中,使用 jinja2 作为模版引擎进行渲染,所以,任何 jinja2 模版的特性都可以在agen中使用。

    文件生成

from agen import ( string_render, render, generate, generate_dir ) # Render text from a templated string string_render('{{key}}', {'key': 'value'}) > 'value' cat template.py > {{key}} # Render text from a template file render('template.py', {'key': 'value'}) > 'value' # Generate file from a template file generate('template.py', 'output.py', {'key': 'value'}) # Content of output.py value

    目录生成

    假设我们有下面这样的目录:

directory
├── __init__.py
└── {{key}}.py

    调用 generate_dir 函数:

generate_dir('directory', 'mydir', {'key': 'value'})

    将生成

mydir
├── __init__.py
└── value.py

每一个纯文本文件都会被模版引擎渲染,context {'key': 'value'} 也会在渲染时被自动传递。

本文地址:https://codercto.com/soft/d/754.html

A Guide to Monte Carlo Simulations in Statistical Physics

A Guide to Monte Carlo Simulations in Statistical Physics

Landau, David P./ Binder, Kurt / Cambridge Univ Pr / 2005-9 / 786.00元

This new and updated edition deals with all aspects of Monte Carlo simulation of complex physical systems encountered in condensed-matter physics, statistical mechanics, and related fields. After brie......一起来看看 《A Guide to Monte Carlo Simulations in Statistical Physics》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具