GithubHelp home page GithubHelp logo

bem / bh-php Goto Github PK

View Code? Open in Web Editor NEW
33.0 29.0 8.0 138 KB

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

PHP 100.00%
bem bemjson php php-template template-engine

bh-php's People

Contributors

bethrezen avatar gitter-badger avatar qfox 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

Watchers

 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

bh-php's Issues

processBemJson: no tag property

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.

HHVM support

Tests are failing at hhvm env. Do we need it at all?

No html code output

why $bh->apply([ 'block' => 'button' ]); doesn't output any html
i have to use echo($bh->apply([ 'block' => 'button' ])); in order to get it

Rework incoming data normalizing

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);
    }
  }
}

use JSON as argument for apply

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.

Адаптация под php 7

Может быть типизация добавит производительности шаблонизатору. Сам php 7 должен добавть как минимум двойной прирост, а если использовать типизацию еще и памяти будем меньше использовать. Ну и скорее всего типизация с opcache хорошо себя покажет!
В общем как идея!

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.