Giter VIP home page Giter VIP logo

blade's Introduction

Blade

【简体中文】

This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

Installation

With Composer, you just need to run

composer require xiaoler/blade

If you haven't use composer, you should add all the files in folder src to your project folder, and then require them in your code.

Usage

<?php

require '../src/Autoloader.php';

Xiaoler\Blade\Autoloader::register();

use Xiaoler\Blade\FileViewFinder;
use Xiaoler\Blade\Factory;
use Xiaoler\Blade\Compilers\BladeCompiler;
use Xiaoler\Blade\Engines\CompilerEngine;
use Xiaoler\Blade\Filesystem;
use Xiaoler\Blade\Engines\EngineResolver;

$path = ['/view_path'];         // your view file path, it's an array
$cachePath = '/cache_path';     // compiled file path

$file = new Filesystem;
$compiler = new BladeCompiler($file, $cachePath);

// you can add a custom directive if you want
$compiler->directive('datetime', function($timestamp) {
    return preg_replace('/(\(\d+\))/', '<?php echo date("Y-m-d H:i:s", $1); ?>', $timestamp);
});

$resolver = new EngineResolver;
$resolver->register('blade', function () use ($compiler) {
    return new CompilerEngine($compiler);
});

// get an instance of factory
$factory = new Factory($resolver, new FileViewFinder($file, $path));

// if your view file extension is not php or blade.php, use this to add it
$factory->addExtension('tpl', 'blade');

// render the template file and echo it
echo $factory->make('hello', ['a' => 1, 'b' => 2])->render();

You can enjoy almost all the features of blade with this extension. However, remember that some of exclusive features are removed.

You can't:

  • use @inject @can @cannot @lang in a template file
  • add any events or middleawares

Documentation: http://laravel.com/docs/5.4/blade

Thanks for Laravel and it authors. That is a great project.

blade's People

Contributors

salkhwlani avatar xleliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blade's Issues

xiaoler/blade depends on symfony/debug

The Engines/PhpEngine.php uses `Symfony\Component\Debug\Exception\FatalThrowableError´.

In effect, this means that xiaoler/blade depends on symfony/debug.

Error while registering autoloader

Hello, Im trying to do a basic render but after requiring the autoload.php and doing

Xiaoler\Blade\Autoloader::register();

I'm getting the following error:

( ! ) Warning: require(./helpers.php): failed to open stream: No such file or directory in /var/www/html/some-path/vendor/xiaoler/blade/src/Autoloader.php on line 12

the line responsible inside Autoloader is:
require './helpers.php';

presumably because the ./

不兼容linux

/src/FileViewFinder.php
line132 protected function findInPaths($name, $paths)
有一句

trim($path, DS).'/' 

应该改为

rtrim($path, DS).'/' 

Undefined offset: 3

protected function compileStatements($value)
{
$callback = function ($match) {
if (strpos($match[1], '@') !== false) {
$match[0] = isset($match[3]) ? $match[1].$match[3] : $match[1];
} elseif (isset($this->customDirectives[$match[1]])) {
$match[0] = call_user_func($this->customDirectives[$match[1]], ($match[3] ?: ''));
} elseif (method_exists($this, $method = 'compile'.ucfirst($match[1]))) {
$match[0] = $this->$method(($match[3] ?: ''));
}

    return isset($match[3]) ? $match[0] : $match[0].$match[2];
};

return preg_replace_callback('/\B@(@?\w+)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', $callback, $value);

}
xiaoler\blade\src\Compilers\BladeCompiler.php 248 line

会提示一个错误这个依赖好像没有去除

ERROR: Error: Class 'Symfony\Component\Debug\Exception\FatalThrowableError' not found in D:\phpStudy\WWW\teebphp\library\blade\src\Engines\PhpEngine.php:46
Stack trace:
#0 D:\phpStudy\WWW\teebphp\library\blade\src\Engines\CompilerEngine.php(60): Xiaoler\Blade\Engines\PhpEngine->evaluatePath('D:\phpStudy\WWW...', Array)
#1 D:\phpStudy\WWW\teebphp\library\blade\src\View.php(132): Xiaoler\Blade\Engines\CompilerEngine->get('D:\phpStudy\WWW...', Array)
#2 D:\phpStudy\WWW\teebphp\library\blade\src\View.php(115): Xiaoler\Blade\View->getContents()
#3 D:\phpStudy\WWW\teebphp\library\blade\src\View.php(82): Xiaoler\Blade\View->renderContents()
#4 D:\phpStudy\WWW\teebphp\library\blade\src\Blade.class.php(51): Xiaoler\Blade\View->render()
#5 [internal function]: Blade->make('admin/index', Array)
#6 D:\phpStudy\WWW\teebphp\app\Component\Blade\BladeManager.php(41): call_user_func_array(Array, Array)
#7 D:\phpStudy\WWW\teebphp\app\Http\AdminController.php(25): App\Component\Blade\BladeManager->__call('make', Array)
#8 D:\phpStudy\WWW\teebphp\app\Http\AdminController.php(15): App\Http\AdminController->actionBlade()
#9 [internal function]: App\Http\AdminController->actionIndex(Object(Teeb\Http\Request))
#10 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Controller.php(72): call_user_func_array(Array, Array)
#11 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Controller.php(49): Teeb\Http\Controller->runAction('index')
#12 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Core.php(73): Teeb\Http\Controller->run('index', Array)
#13 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Core.php(56): Teeb\Http\Core->handleRequest('admin', Array)
#14 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Core.php(45): Teeb\Http\Core->handle()
#15 D:\phpStudy\WWW\teebphp\public\index.php(7): Teeb\Http\Core->run()
#16 {main} []
in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Log\Logger.php:72
in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Log\Logger.php:62
in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Log\Logger.php:37
in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Log\Log.php:11
in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Exception\Handler.php:27
in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Bootstrap\HandleException.php:44

Argument 1 passed to Xiaoler\Blade\Compilers\Compiler::__construct()

Hi guys,

An uncaught Exception was encountered

Type: TypeError

Message: Argument 1 passed to Xiaoler\Blade\Compilers\Compiler::__construct() must be an instance of Xiaoler\Blade\Filesystem, string given, called in C:\xampp\htdocs\application\libraries\Blade.php on line 18

Filename: C:\xampp\htdocs\vendor\xiaoler\blade\src\Compilers\Compiler.php

Line Number: 33

Backtrace:

File: C:\xampp\htdocs\application\libraries\Blade.php
Line: 18
Function: __construct

File: C:\xampp\htdocs\index.php
Line: 315
Function: require_once

Fatal error: require(): Failed opening required '../src/helpers.php'

I get a fatal error when I'm trying to use the example code. Am I doing something wrong?

Warning: require(../src/helpers.php): failed to open stream: No such file or directory in /vendor/xiaoler/blade/src/Autoloader.php on line 12

Warning: require(../src/helpers.php): failed to open stream: No such file or directory in /vendor/xiaoler/blade/src/Autoloader.php on line 12

Fatal error: require(): Failed opening required '../src/helpers.php' (include_path='.:/opt/php56/lib/php') in /vendor/xiaoler/blade/src/Autoloader.php on line 12

EDIT

Just changed require '../src/helpers.php'; to require 'helpers.php'; inside the Autoloader.php and it's now working. Why do I get this error? I just C/P the sample code and created a simple view. Also why does the include use ../src/ for helpers.php, a file that it's inside the same directory with the Autoloader.php?

Version of blade?

because I found that you had mentioned 5.3 in readme, but your source code seem didn't update yet,
I'm using @php @endphp but it doesn't work

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.