2017 © Pedro Peláez
 

library xbt

XBT

image

kmklabs/xbt

XBT

  • Monday, September 18, 2017
  • by kmklabs
  • Repository
  • 100 Watchers
  • 0 Stars
  • 5,539 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 11 % Grown

The README.md

XHP Block Template

Intro

This is a simple library to compile an XHP template expression into an ordinary Hack class. We do this because we need to have a template inheritance and inclusion in XHP., (*1)

Features

  • Template block/inclusion
  • Accessing outer template from within
  • Template inheritance, like <xbt:template extends="path.dot.base"> which will use path/dot/base.xbt.php
  • Accessing parent blocks with <xbt:parent />

Example

Suppose that we have this xbt template, named template.xbt.php:, (*2)

<xbt:template doctype="true">
<html>
  <body>
    <h1>This is a header</h1>
    <xbt:block name="main">
        <p>This is inside a block</p>
        <xbt:block name="submain">
            <p>This is a block inside a block</p>
        </xbt:block>
    </xbt:block>
    <p>This is a simple footer</p>
  </body>
</html>
</xbt:template>

And have a view file named welcome.xbt.php:, (*3)

<xbt:template base="template">
  <xbt:block name="main">
    <p>Welcome Home</p>
  </xbt:block>
</xbt:template>

Load the file, and using this library, we can convert the template into an XHP class, (*4)

$contents    = file_get_contents("template.xbt.php");
$tokenizer   = new Tokenizer($contents);
$tokenStream = $tokenizer->tokenize();
$parser      = new Parser($tokenStream);
$result      = $parser->parse();

$result should be like something like this:, (*5)

<?php

class __xbt_4bc492834a61e30d17d158c6a052837584b1db90 extends App\Publishing\Lib\Xbt\Runtime
{
    public function render()
    {
        return <x:frag>
    <h1>This is a header</h1>
    {$this->block_main()}
    <p>This is a simple footer</p>
</x:frag>;
    }

    public function block_main()
    {
        return <x:frag>
    <p>This is inside a block</p>
     {$this->block_submain()}
</x:frag>;
    }

    public function block_submain()
    {
        return <x:frag>
    <p>This is a block inside a block</p>
</x:frag>;
    }
}

Laravel Binding and Config

Include the Xbt\LaravelServiceProvider to your project. Compiled xhp classes are in config('view.compiled'), and compiled laravel views from that classes are in config('view.xbt_cache')., (*6)

Process


File -> Tokenizer -> TokenStream -> Parser -> Node -> Xhp

Tokenizer will tokenize the template into a TokenStream. We pass the TokenStream into the Parser, and call the method parse to get the Template node, the highest level representation node for a given template., (*7)

Node is the abstraction of xhp class in php/hack. The parsing process will turn a template file into a Node before writing into files. Method compile in Template will output XHP code., (*8)

The Versions

18/09 2017

dev-master

9999999-dev

XBT

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel xhp xbt

18/09 2017

0.2.0

0.2.0.0

XBT

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel xhp xbt

09/01 2017

0.1.2

0.1.2.0

XBT

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel xhp xbt

30/12 2016

0.1.1

0.1.1.0

XBT

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel xhp xbt

28/12 2016

0.1.0

0.1.0.0

XBT

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel xhp xbt