承接 eden/handlebars 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eden/handlebars

Composer 安装命令:

composer require eden/handlebars

包简介

PHP Handlebars with JS interface to match with compile time helper support and super nice compile time error reporting.

README 文档

README

Build Status

====

Install

composer install eden/handlebars

====

Enable Eden

The following documentation uses eden() in its example reference. Enabling this function requires an extra step as descirbed in this section which is not required if you access this package using the following.

Eden\Handlebars\Index::i();

When using composer, there is not an easy way to access functions from packages. As a workaround, adding this constant in your code will allow eden() to be available after.

Eden::DECORATOR;

For example:

Eden::DECORATOR;

eden()->inspect('Hello World');

====

Introduction

PHP Handlebars with JS interface to match with compile time helper support and super nice compile time error reporting. This version of Handlebars is based on caching the compiled templates and inheritently made the overall compile times faster. Loading at ~50ms uncached and ~30ms cached.

====

Basic Usage

Rendering

$template = eden('handlebars')->compile('{{foo}} {{bar}}');

echo $template(array('foo' => 'BAR', 'bar' => 'ZOO'));

Registering Helpers

$template = eden('handlebars')
	->registerHelper('bar', function($options) {
		return 'ZOO';
	})
	->compile('{{foo}} {{bar}}');

echo $template(array('foo' => 'BAR'));

Registering Partials

$template = eden('handlebars')
	->registerPartial('bar', 'zoo')
	->compile('{{foo}} {{> bar}}');

echo $template(array('foo' => 'BAR'));

====

Features

  • PHP API - designed to match the handlebars.js documentation
    • registerHelper() - Matches exactly what you expect from handlebars.js (except it's PHP syntax)
    • registerPartial() - accepts strings and functions as callbacks
    • Literals like {{./foo}} and {{../bar}} are evaluated properly
    • Comments like {{!-- Something --}} and {{! Something }} supported
    • Trims like {{~#each}} and {{~foo~}} supported
    • Mustache backwards compatibility {{#foo}}{{this}}{{/foo}}
    • Tokenizer helpers to optimize custom code generation to cache
    • Event handlers for unknown helpers and unknown partials
  • Default Helpers matching handlebars.js
    • each - and {{#each foo as |value, key|}}
      • Please note that there is an issue with each being slow depending on the size of the object
      • We need help optimizing this
    • with
    • unless
    • if

De-Features (or whatever the opposite of features is)

  • Does not support file templates.
    • You need to load them up and pass it into Handlebars.
    • If this is a problem you should consider other Handlebars PHP libraries
    • You can always create a helper for this
    • This de-feature will be considered upon requests ( create an issue :) )
  • Partial Failover
    • Something we haven't had a chance to come around doing yet as we did not have a need
    • This de-feature will be considered upon requests ( create an issue :) )
  • Safe String/Escaping
    • PHP has functions that can turn a string "safe".
    • We didn't want to create something that already exists in other contexts
    • This de-feature will be considered upon requests ( create an issue :) )
  • Utils
    • PHP has functions that support most of the listed Utils in handlebars.js
    • We didn't want to create something that already exists in other contexts
    • This de-feature will be considered upon requests ( create an issue :) )
  • Dynamic Partials
    • At the bottom of our pipe
    • because of it's difficulty to recreate
    • and practicality
    • This de-feature will be considered upon requests ( create an issue :( )
  • Inline Partials
    • TODO
  • Decorators
    • TODO
  • Frames
    • TODO

====

Production Ready

When your templates are ready for a production (live) environment, it is recommended that caching be used. To enable cache:

  • Create a cache folder and make sure permissions are properly set for handlebars to write files to it.
  • Enable cache by using eden('handlebars')->setCache(__DIR__.'/your/cache/folder/location');
  • If the folder location does not exist, caching will be disabled.

====

API

====

compile

Returns a callback that binds the data with the template

Usage

eden('handlebars')->compile(string $string);

Parameters

  • string $string - the template string

Returns function - the template binding handler

Example

eden('handlebars')->compile();

====

getCache

Returns the active cache path

Usage

eden('handlebars')->getCache();

Returns Closure

====

getHelper

Returns a helper given the name

Usage

eden('handlebars')->getHelper('if');

Parameters

  • string $name - the name of the helper

Returns Closure

====

getHelpers

Returns all the registered helpers

Usage

eden('handlebars')->getHelpers();

Parameters

Returns array

====

getPartial

Returns a partial given the name

Usage

eden('handlebars')->getPartial('foobar');

Parameters

  • string $name - the name of the partial

Returns string

====

getPartials

Returns all the registered partials

Usage

eden('handlebars')->getPartials();

Parameters

Returns array

====

registerHelper

The famous register helper matching the Handlebars API

Usage

eden('handlebars')->registerHelper(string $name, function $helper);

Parameters

  • string $name - the name of the helper
  • function $helper - the helper handler

Returns Eden\Handlebrs\Index

Example

eden('handlebars')->registerHelper();

====

registerPartial

Delays registering partials to the engine because there is no add partial method...

Usage

eden('handlebars')->registerPartial(string $name, string $partial);

Parameters

  • string $name - the name of the helper
  • string $partial - the helper handler

Returns Eden\Handlebrs\Index

Example

eden('handlebars')->registerPartial();

====

setCache

Enables the cache option

Usage

eden('handlebars')->setCache(string $path);

Parameters

  • string $path - The cache path

Returns Eden\Handlebrs\Index

Example

eden('handlebars')->setCache('/path/to/cache/folder');

====

setPrefix

Sets the file name prefix for caching

Usage

eden('handlebars')->setPrefix(string $prefix);

Parameters

  • string $prefix - Custom prefix name

Returns Eden\Handlebrs\Index

Example

eden('handlebars')->setPrefix('special-template-');

====

unregisterHelper

The opposite of registerHelper

Usage

eden('handlebars')->unregisterHelper(string $name);

Parameters

  • string $name - the helper name

Returns Eden\Handlebars\Index

Example

eden('handlebars')->unregisterHelper();

====

unregisterPartial

The opposite of registerPartial

Usage

eden('handlebars')->unregisterPartial(string $name);

Parameters

  • string $name - the partial name

Returns Eden\Handlebars\Index

Example

eden('handlebars')->unregisterPartial();

====

#Contributing to Eden

Contributions to Eden are following the Github work flow. Please read up before contributing.

##Setting up your machine with the Eden repository and your fork

  1. Fork the repository
  2. Fire up your local terminal create a new branch from the v4 branch of your fork with a branch name describing what your changes are. Possible branch name types:
    • bugfix
    • feature
    • improvement
  3. Make your changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")

##Making pull requests

  1. Please ensure to run phpunit before making a pull request.
  2. Push your code to your remote forked version.
  3. Go back to your forked version on GitHub and submit a pull request.
  4. An Eden developer will review your code and merge it in when it has been classified as suitable.

eden/handlebars 适用场景与选型建议

eden/handlebars 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.86k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「templating」 「template」 「library」 「eden」 「hamdlebars」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 eden/handlebars 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 eden/handlebars 我们能提供哪些服务?
定制开发 / 二次开发

基于 eden/handlebars 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 22
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-12