极简的代码生成器 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

Struts 2 in Action

Struts 2 in Action

Don Brown、Chad Davis、Scott Stanlick / Manning Publications / 2008.3 / $44.99

The original Struts project revolutionized Java web development and its rapid adoption resulted in the thousands of Struts-based applications deployed worldwide. Keeping pace with new ideas and trends......一起来看看 《Struts 2 in Action》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具