conquer/jade 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

conquer/jade

Composer 安装命令:

composer require conquer/jade

包简介

Jade renderer for the Yii2 framework

README 文档

README

The Tale Jade Template Engine brings the popular and powerful Templating-Language Jade for Node.js to PHP!

Tale Jade for PHP

Requirements

  • YII 2.0
  • PHP 5.4+

Installation

The preferred way to install this extension is through composer.

To install, either run

$ php composer.phar require conquer/jade "*"

or add

"conquer/jade": "*"

to the require section of your composer.json file.

Configuration

return [
    //....
    'components' => [
        'view' => [       
            'defaultExtension' => 'jade', // Set jade as default to use base view file names without extension.
            'renderers' => [
                'jade' => [
                    'class' => 'conquer\jade\JadeRenderer',
                    'cacheDuration' => 0, // seconds. 0 - compile every time
                ],
            ],
        ],
    ],
];

Usage

class SiteController extends Controller
{
    // if you do not specify a defaultExtension, you should specify it here
    $layout = 'main.jade';
    ...
    public function actionIndex()
    {
        return $this->render('index', []);
        // or
        // return $this->render('index.jade', []);
    }
}

Examples

Main layout

-
    use yii\bootstrap\Html;
    use assets\AppAsset;
    /* @var $this \yii\web\View */
    /* @var $content string */
    AppAsset::register($this);
-$this->beginPage()
doctype html
html(lang=Yii::$app->language)
    // BEGIN HEAD
    head
        meta(charset="utf-8")
        title
            != Html::encode($this->title)
        meta(http-equiv="X-UA-Compatible", content="IE=edge")
        meta(content="width=device-width initial-scale=1", name="viewport")
        != Html::csrfMetaTags()
        meta(content="", name="description")
        meta(content="", name="author")
        link(rel="shortcut icon", href="/favicon.ico")
        - $this->head()
    // END HEAD
    body(class=$this->params['body-class'])
        - $this->beginBody()
        != $content
        - $this->endBody()
    - $this->endPage()

Sub layout

-
    use yii\web\YiiAsset;
    use yii\base\Widget;
    use yii\bootstrap\Html;
    use yii\helpers\Url;
    /* @var $this \yii\web\View */
    /* @var $content string */
    $this->params['body-class'] = 'page-header-fixed page-sidebar-closed-hide-logo';
    YiiAsset::register($this);
    
- $this->beginContent('@views/layouts/main.jade');

// BEGIN HEADER & CONTENT DIVIDER
include header

.clearfix
// END HEADER & CONTENT DIVIDER
// BEGIN CONTAINER
.page-container
    // sidebar.jade is placed at @views/layouts/partials/sidebar.jade
    // jade engine just puts rendered content here
    include partials/sidebar
    != $content
// END CONTAINER
include partials/footer

- $this->endContent();

Login

-
    use yii\helpers\Html
    use yii\bootstrap\ActiveForm
    $this->title = 'Login'
    $this->params['breadcrumbs'][] = $this->title;
    
.site-login
    h1 #{$view->title}
    p Please fill out the following fields to login:
    .row
        .col-lg-5
            - $form = ActiveForm::begin(['id' => 'login-form'])
            != $form->field($model, 'username')
            != $form->field($model, 'password')->passwordInput()
            != $form->field($model, 'rememberMe')->checkbox()
            .form-group
                !=Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button'])
            - ActiveForm::end()

Custom filters

For example, you can wrap \Yii::t('category', $message) function to short form of :t You should define a new filter in config file:

return [
    //....
    'components' => [
        'view' => [       
            'defaultExtension' => 'jade',
            'renderers' => [
            'jade' => [
                'class' => 'conquer\jade\JadeRenderer',
                'filters' => [
                    't' => function($node, $indent, $newLine){
                        return "<?=\Yii::t('category', '" . trim($node->text()) ."')?>";
                    },
                ],
            ],
        ],
    ],
];

Now you can use this filter:

-
    use yii\helpers\Html;
    use yii\widgets\ActiveForm;
    /* @var $this yii\web\View */
    /* @var $model common\models\User */
    /* @var $form yii\widgets\ActiveForm */
    
.h3
    :t Change password
-
    $form = ActiveForm::begin([
        'action' => '/user/profile#tab_1_2',
        'options' => [
            'class' => 'form-horizontal'
        ]
    ]);

!= $form->field($model, 'current_password')->passwordInput()
!= $form->field($model, 'password')->passwordInput()
!= $form->field($model, 'password_repeat')->passwordInput()

.margin-top-10
    button.btn.btn-primary(type='submit')
        :t Submit
    a.btn.default(href="javascript:;")
        :t Cancel
- ActiveForm::end();

Links

License

Jade extension for Yii2 Framework is released under the MIT license.

conquer/jade 适用场景与选型建议

conquer/jade 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 898 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 898
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-05