minicli/stencil
Composer 安装命令:
composer require minicli/stencil
包简介
Dummy template generator
README 文档
README
/ˈstɛns(ə)l/ (noun): a thin sheet of card, plastic, or metal with a pattern or letters cut out of it, used to produce the cut design on the surface below by the application of ink or paint through the holes.
Minicli/Stencil is a dummy content replacer useful for generating templates.
Stencils are like lightweight templates with no advanced functionality (so it's not an engine). It simply replaces placeholders with content set up in a string-indexed array or dictionary.
If you are looking for a templating system for front-end views, this is not it! Go check Twig. Stencil is useful for generating skeleton content (such as to auto-generate classes, Markdown docs and other files following a certain structure).
Dependencies
Stencil is a tiny standalone library that has only testing dependencies.
Usage
Within Minicli
If you want to use Stencil within a Minicli app, you should have a look at the Minicli Stencil command that contains a basic implementation of a command using Stencil to generate documents based on templates. Check that repo for usage instructions.
Standalone
For more freedom to include Stencil on your codebase, install standalone Stencil via Composer:
composer require minicli/stencil
Set up a directory within your project to hold your stencils:
mkdir stencils
cd stencils
Create a new .tpl file with some variables:
#stencils/mytemplate.tpl ## This is my Template My name is {{ name }} and I am a {{ description }}.
From your project, instantiate a new Stencil, passing along the stencils directory you set up. Then, call the applyTemplate method with an array containing your values:
<?php $stencil = new Stencil(__DIR__ . '/stencils'); $values = [ 'name' => 'Stencil', 'description' => 'minimalist, dummy template generator.' ]; $parsedContent = $stencil->applyTemplate('mytemplate', $values); var_dump($parsedContent);
string(92) "## This is my Template My name is Stencil and I am a minimalist, dummy template generator.."
Querying templates for variables
You can also obtain the variables set within a template in order to build your array of values in a step-by-step way, such as interactively via command-line prompts.
This is an example code that collects variables from a Stencil template and then prompts users for each variable found, returning an array that can then be used with $stencil->applyTemplate():
$stencil = new Stencil(__DIR__ . '/stencils'); $template = 'mytemplate'; $values = []; $variables = $stencil->scanTemplateVars($template); echo "Building template $template\n"; foreach ($variables as $variable) { echo ucfirst($variable); $values[$variable] = readline(': '); } echo $stencil->applyTemplate($template, $values);
minicli/stencil 适用场景与选型建议
minicli/stencil 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.64k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「template」 「minicli」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 minicli/stencil 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 minicli/stencil 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 minicli/stencil 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A help command for Minicli
Simple ASCII output of array data
A Minicli command to generate files based on minicli/stencil templates
E2E Studios PHP Framework adaptation of leafsphp/blade package
Ensolab template project
Minicli Application Template powered with Termwind and Plates
统计信息
- 总下载量: 3.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 10
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-20