Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Increase Twig Dependency Requirement
  Fix docs
  Minor README changes
  • Loading branch information
Robert Vogt committed Jun 24, 2016
2 parents 5d1eb47 + 9edc6d4 commit 5bd3017
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
[![Total Downloads](https://poser.pugx.org/deniaz/terrific-twig/downloads.svg)](https://packagist.org/packages/deniaz/terrific-twig)
[![License](https://poser.pugx.org/deniaz/terrific-twig/license.svg)](https://packagist.org/packages/deniaz/terrific-twig)

This Twig Extension adds a new `component` tag to Twig which works just like the `component` helper from [Nitro](https://github.com/namics/generator-nitro).
Extension to embrace the [Terrific](https://github.com/brunschgi/terrificjs) frontend methodology in [Twig](http://twig.sensiolabs.org/).

Currently it adds a custom `component` tag to Twig which mimics [Nitro](https://github.com/namics/generator-nitro)'s handlebars helper.

## Installation
Using [composer](https://packagist.org/packages/deniaz/terrific-twig):

```bash
$ composer require deniaz/terrific-twig
```

## Requirements

The following versions of PHP are currently supported.
Expand All @@ -23,10 +26,10 @@ The following versions of PHP are currently supported.
+ HHVM

## Setup
Step 1: Implement `TemplateLocatorInterface`
Step 1: Implement `TemplateInformationProvider`

```php
class TemplateLocator implements TemplateLocatorInterface
class TemplateInformationProvider implements TemplateInformationProviderInterface
{
public function getPaths()
{
Expand All @@ -41,20 +44,31 @@ class TemplateLocator implements TemplateLocatorInterface
}
```

Step 2: Add `TerrificLoader`
Step 2: Implement `ContextProviderInterface`

```php
class ContextProvider implements ContextProviderInterface
{
public function compile(Twig_Compiler $compiler, Twig_Node $component, Twig_Node $dataVariant, $only) {
// ...
}
}
```

Step 3: Add `TerrificLoader`
```php
$loader = ...;
$chain = new Twig_Loader_Chain([$loader, new TerrificLoader(new TemplateLocator)]);
$chain = new Twig_Loader_Chain([$loader, new TerrificLoader(new TemplateInformationProvider)]);
$twig = new Twig_Environment($chain);
```

Step 3: Add `TerrificExtension`
Step 4: Add `TerrificExtension`
```php
$twig = new Twig_Environment($chain);
$twig->addExtension(new TerrificExtension);
$twig->addExtension(new TerrificExtension(new ContextProvider));
```

Step 4: Profit!
Step 5: Profit!

## Usage
```twig
Expand Down Expand Up @@ -92,8 +106,12 @@ The Node compiles the tokenized tag to PHP. To see some of the output, check the
### Loader
The `TerrificLoader` extends the `Twig_Loader_Filesystem` as it actually loads templates from the filesystem. An implementation of `TemplateLocatorInterface` provides the paths where the loader should search for templates.

### Locator
An implementation of `TemplateLocatorInterface` should return a list of paths where templates live. These should be in the form of `['frontend/components/atoms', 'frontend/components/molecules', 'frontend/components/organisms']`. The component directory will be provided by the `TerrificLoader` (`Example/example.[ext]`).
### Template Information Provider
An implementation of `TemplateInformationProviderInterface` should return a list of paths where templates live. These should be in the form of `['frontend/components/atoms', 'frontend/components/molecules', 'frontend/components/organisms']`. The component directory will be provided by the `TerrificLoader` (`Example/example.[ext]`).

### Context Provider
This is the tricky part. An implementation of `ContextProviderInterface` decides which data will be made available to Twig templates.
TODO: More on that.

### ConfigReader
Reads nitro's `config.json` and parses essential information such as the component paths and file extension.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
},
"require": {
"php": ">=5.4",
"twig/twig": "1.23.*"
"twig/twig": "~1.24"
}
}

0 comments on commit 5bd3017

Please sign in to comment.