bem / bh-php Goto Github PK
View Code? Open in Web Editor NEWPHP port of https://github.com/bem/bh. It's cool thing but better use this:
Home Page: https://github.com/zxqfox/php-fpm-bem-demo-heroku
License: MIT License
PHP port of https://github.com/bem/bh. It's cool thing but better use this:
Home Page: https://github.com/zxqfox/php-fpm-bem-demo-heroku
License: MIT License
Just for prettified json_encode on nodes.
These object we need for passing them thru tParam, applying map, concat, etc. for arrays, etc.
Code:
require "vendor/autoload.php";
$bh = new \BEM\BH();
$bh->match('button', function ($ctx) {
$ctx->tag('button');
});
var_dump($bh->processBemJson([ 'block' => 'block' ]));
// [ 'block' => 'button', 'tag' => 'button' ]
Expected:
class BEM\Json#4 (9) {
public $block =>
string(5) "block"
public $tag =>
string(6) "button"
// ...
Actual: no tag property at all.
Tests are failing at hhvm env. Do we need it at all?
Need to add an ability to fail on js code and skip comments parsing
Also need some tests and readme update
To save some ms
why $bh->apply([ 'block' => 'button' ]);
doesn't output any html
i have to use echo($bh->apply([ 'block' => 'button' ]));
in order to get it
We should create a special classes for mods, bemjson nodes, etc.
Mods:
class Mods implements Iterator {
protected $content = [];
// etc.
}
JsonNode (or Json, or Node):
class JsonNode {
protected $block = 'page';
protected $elem = 'content';
protected $mods = null; // Mods
protected $blockMods = null; // Mods
protected $elemMods = null; // Mods
protected $attrs = 'page';
protected $content = [];
// etc.
function __construct (array $bemjson) {
$this->block = $bemjson['block'];
$this->elem = $bemjson['elem'];
$this->content = $bemjson['content'];
}
function iterate (callable $cb) {
// call cb for each node
}
public static buildTree ($bemjson) {
if (is_array($bemjson)) {
$res = [];
foreach ($bemjson as $node) {
$res[] = static::buildTree($node);
}
return $res;
} elseif ($bemjson instanceof self) {
return $bemjson;
} else {
// etc.
return new self($bemjson);
}
}
}
I think $BH->apply()
should use JSON as an argument or (if it's somehow possible) support both JSON and JS object syntax to have interoperability with current BEMJSON bundles or server responses.
it would be nice to have some form of demo code which can be directly executed on download.
Может быть типизация добавит производительности шаблонизатору. Сам php 7 должен добавть как минимум двойной прирост, а если использовать типизацию еще и памяти будем меньше использовать. Ну и скорее всего типизация с opcache хорошо себя покажет!
В общем как идея!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.