2017 © Pedro Peláez
 

patternlab-patternengine patternengine-mustache

Mustache-based PatternEngine for Pattern Lab.

image

pattern-lab/patternengine-mustache

Mustache-based PatternEngine for Pattern Lab.

  • Tuesday, June 21, 2016
  • by EvanLovely
  • Repository
  • 6 Watchers
  • 2 Stars
  • 18,534 Installations
  • PHP
  • 10 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 6 Versions
  • 9 % Grown

The README.md

license Packagist Gitter, (*1)

Mustache PatternEngine for Pattern Lab PHP

The Mustache PatternEngine allows you to use Mustache as the template language for Pattern Lab PHP. Once the PatternEngine is installed you can use Mustache-based StarterKits and StyleguideKits., (*2)

Installation

The Mustache PatternEngine will come pre-installed with the Pattern Lab Standard Edition., (*3)

Composer

Pattern Lab PHP uses Composer to manage project dependencies with Pattern Lab Editions. To add the Mustache PatternEngine to the dependencies list for your Edition you can type the following in the command line at the base of your project:, (*4)

composer require pattern-lab/patternengine-mustache

See Packagist for information on the latest release., (*5)

Overview

This document is broken into two parts:, (*6)

Extending Mustache

Mustache comes with two ways to extend the underlying template parser:, (*7)

The Mustache PatternEngine enables these features via Helpers., (*8)

Helpers

The requirements for using helpers with Pattern Lab:, (*9)

  • Files must go in ./source/_mustache-components/helpers
  • Files must have the extension .helper.php (_this can be modified in the config_)
  • The helper must set the variable $helper
  • Only one helper per file (_e.g. can only set $helper once per file_)

An example function called verbatim.helper.mustache in ./source/_mustache-components/helpers:, (*10)


This helper would be used like this in a pattern. Note that the tag is using the filename and that this is an example of a lambda:, (*11)

{{# verbatim }}
  {{ this won't be parsed }}
{{/ verbatim }}

Mustache also allows dot notation with helpers. An example function called case.helper.mustache in ./source/_mustache-components/helpers:, (*12)

 function($value) { return strtolower((string) $value); },
    'upper' => function($value) { return strtoupper((string) $value); },
));

?>

This helper would be used like this in a pattern. Note that the tag is using the filename and that this is an example of a filter:, (*13)

{{ greeting | case.upper }}

Available Loaders

If you're building a plugin that will be parsing Mustache files you have access to three loaders. It's recommended that you use these instead of accessing Mustache directly as these loaders will work with other PatternEngines., (*14)

The String Loader

The string loader takes a simple string and compiles it. To use:, (*15)

$data         = array("hello" => "world");
$string       = "If I say hello you say {{ hello }}.";
$stringLoader = \PatternLab\Template::getStringLoader();
$output       = $stringLoader->render(array("string" => $string, "data" => $data));
print $output; // outputs "If I say hello you say world."

The Filesystem Loader

The filesystem loader will look for templates in the configured StyleguideKit directory and compile them. The template location for the filesystem loader can't be modified. To use:, (*16)

$data             = array(...);
$filesystemLoader = \PatternLab\Template::getFilesystemLoader();
$output           = $filesystemLoader->render(array("template" => "viewall", "data" => $data));
print $output; // outputs the viewall view from the configured styleguidekit

The Pattern Loader

The pattern loader looks for patterns and allows the use of the Pattern Lab-specific partial syntax. To use:, (*17)

```php $data = array(...); $patternContent = file_get_contents("path/to/pattern"); $patternEngineBasePath = \PatternLab\PatternEngine::getInstance()->getBasePath(); $patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader"; $patternLoader = new $patternLoaderClass($options); $code = $patternLoader->render(array("pattern" => $patternContent, "data" => $data)); print $output; // outputs the given pattern, (*18)

The Versions

21/06 2016

dev-master

9999999-dev http://patternlab.io

Mustache-based PatternEngine for Pattern Lab.

  Sources   Download

MIT

The Requires

 

mustache pattern lab pattern engine

21/06 2016

v2.1.0

2.1.0.0 http://patternlab.io

Mustache-based PatternEngine for Pattern Lab.

  Sources   Download

MIT

The Requires

 

mustache pattern lab pattern engine

21/06 2016

dev-develop

dev-develop http://patternlab.io

Mustache-based PatternEngine for Pattern Lab.

  Sources   Download

MIT

The Requires

 

mustache pattern lab pattern engine

20/06 2016

dev-dev

dev-dev http://patternlab.io

Mustache-based PatternEngine for Pattern Lab.

  Sources   Download

MIT

The Requires

 

mustache pattern lab pattern engine

19/05 2016

v2.0.0

2.0.0.0 http://patternlab.io

Mustache-based PatternEngine for Pattern Lab.

  Sources   Download

MIT

The Requires

 

mustache pattern lab pattern engine

06/05 2016

dev-feature-installupdate

dev-feature-installupdate http://patternlab.io

Mustache-based PatternEngine for Pattern Lab.

  Sources   Download

MIT

The Requires

 

mustache pattern lab pattern engine