Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
first publishing commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Tiefenbacher committed Jan 30, 2019
0 parents commit a1f21fe
Show file tree
Hide file tree
Showing 189 changed files with 11,186 additions and 0 deletions.
7 changes: 7 additions & 0 deletions LICENCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 Blue Tomato GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
TemplateEngineMustache
====================
ProcessWire module adding [Mustache](https://mustache.github.io/) templates to the TemplateEngineFactory.

## Installation
Install the module just like any other ProcessWire module. Check out the following guide: http://modules.processwire.com/install-uninstall/

This module requires TemplateEngineFactory: https://github.com/wanze/TemplateEngineFactory

After installing, don't forget to enable Mustache as engine in the TemplateEngineFactory module's settings.

## Configuration (over TemplateEngineProcesswire Module Configuration)
* **Path to templates** Path to folder where you want to store your Smarty template files.
* **Template files suffix** The suffix of the template files, default is *mustache*.

## Setting Helpers

```php
$view->setHelpers([
'myHelperFunction' => function($text) {
return trim($text);
}
]);

```

## Examples


First expose data (in this case all story pages) to the mustache view being rendered next.
```php
// In file: /site/templates/stories.php

$stories = $pages->find('template=blogstory');
$view->set('stories', $stories);
```

Then use the passed in data (story pages) in your mustache template file.
```html
<!-- In file: /site/templates/views/stories.mustache -->

<h1>Stories</h1>
<ul>
{{#stories}}
<li>
<a href="{{url}}">
{{title}}
</a>
</li>
{{/stories}}
</ul>
```
69 changes: 69 additions & 0 deletions TemplateEngineMustache.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

require_once(__DIR__ . '/mustache/src/Mustache/Autoloader.php');
Mustache_Autoloader::register();

class TemplateEngineMustache extends TemplateEngine implements Module {

public static function getModuleInfo() {
return array(
'title' => 'Template Engine Mustache',
'summary' => 'Mustache templates for the TemplateEngineFactory',
'version' => 100,
'author' => 'Blue Tomato',
'href' => 'https://github.com/blue-tomato/TemplateEngineMustache',
'singular' => false,
'autoload' => false,
'requires' => array('TemplateEngineFactory'),
);
}

public static function getDefaultConfig() {
/*
* Upcoming $config from parent's default includes configurations for
* - templates_path
* - global_template
* - template_files_suffix
*/
$config = parent::getDefaultConfig();

return array_merge($config, array(
'template_files_suffix' => 'mustache',
));
}

public function getTemplatesPath() {
$path = ltrim($this->getConfig('templates_path'), '/');
return $this->wire('config')->paths->site . rtrim($path, '/') . '/';
}

protected $mustache;
protected $data;

public function initEngine() {
$config = array(
'loader' => new Mustache_Loader_FilesystemLoader($this->getTemplatesPath()),
'cache' => $this->wire('config')->paths->assets . '/cache/mustache',
);

$partailsPath = $this->getTemplatesPath().'/partials';
if(is_dir($partailsPath)) {
$config['partials_loader'] = new Mustache_Loader_FilesystemLoader($partailsPath);
}

$this->mustache = new Mustache_Engine($config);
$this->data = (object) [];
}

public function setHelpers($helpers = []) {
$this->mustache->setHelpers($helpers);
}

public function set($key, $value) {
$this->data->$key = $value;
}

public function render() {
return $this->mustache->render($this->getFilename(), $this->data);
}
}
4 changes: 4 additions & 0 deletions mustache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.php_cs.cache
composer.lock
mustache.php
vendor
6 changes: 6 additions & 0 deletions mustache/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "vendor/spec"]
path = vendor/spec
url = https://github.com/mustache/spec.git
[submodule "vendor/yaml"]
path = vendor/yaml
url = https://github.com/fabpot/yaml.git
26 changes: 26 additions & 0 deletions mustache/.php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Symfony\CS\Config\Config;
use Symfony\CS\FixerInterface;

$config = Config::create()
// use symfony level and extra fixers:
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers(array(
'-concat_without_spaces',
'-pre_increment',
'-unalign_double_arrow',
'-unalign_equals',
'align_double_arrow',
'concat_with_spaces',
'ordered_use',
'strict',
))
->setUsingLinter(false);

$finder = $config->getFinder()
->in('bin')
->in('src')
->in('test');

return $config;
13 changes: 13 additions & 0 deletions mustache/.styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
preset: symfony

enabled:
- align_double_arrow
- concat_with_spaces
- ordered_use
- strict

disabled:
- concat_without_spaces
- pre_increment
- unalign_double_arrow
- unalign_equals
21 changes: 21 additions & 0 deletions mustache/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: php

sudo: false

matrix:
include:
- php: 5.2
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: hhvm
dist: trusty

script:
- '[[ "$TRAVIS_PHP_VERSION" = 5.2* ]] && phpunit || vendor/bin/phpunit --verbose'

install:
- '[[ "$TRAVIS_PHP_VERSION" = 5.2* ]] || composer install'
35 changes: 35 additions & 0 deletions mustache/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Contributions welcome!


### Here's a quick guide:

1. [Fork the repo on GitHub](https://github.com/bobthecow/mustache.php).

2. Update submodules: `git submodule update --init`

3. Run the test suite. We only take pull requests with passing tests, and it's great to know that you have a clean slate. Make sure you have PHPUnit 3.5+, then run `phpunit` from the project directory.

4. Add tests for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, add a test!

5. Make the tests pass.

6. Push your fork to GitHub and submit a pull request against the `dev` branch.


### You can do some things to increase the chance that your pull request is accepted the first time:

* Submit one pull request per fix or feature.
* To help with that, do all your work in a feature branch (e.g. `feature/my-alsome-feature`).
* Follow the conventions you see used in the project.
* Use `phpcs --standard=PSR2` to check your changes against the coding standard.
* Write tests that fail without your code, and pass with it.
* Don't bump version numbers. Those will be updated — per [semver](http://semver.org) — once your change is merged into `master`.
* Update any documentation: docblocks, README, examples, etc.
* ... Don't update the wiki until your change is merged and released, but make a note in your pull request so we don't forget.


### Mustache.php follows the PSR-* coding standards:

* [PSR-0: Class and file naming conventions](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)
* [PSR-1: Basic coding standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md)
* [PSR-2: Coding style guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
21 changes: 21 additions & 0 deletions mustache/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2010-2015 Justin Hileman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
72 changes: 72 additions & 0 deletions mustache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Mustache.php
============

A [Mustache](http://mustache.github.com/) implementation in PHP.

[![Package version](http://img.shields.io/packagist/v/mustache/mustache.svg?style=flat-square)](https://packagist.org/packages/mustache/mustache)
[![Build status](http://img.shields.io/travis/bobthecow/mustache.php/dev.svg?style=flat-square)](http://travis-ci.org/bobthecow/mustache.php)
[![StyleCI](https://styleci.io/repos/569670/shield)](https://styleci.io/repos/569670)
[![Monthly downloads](http://img.shields.io/packagist/dm/mustache/mustache.svg?style=flat-square)](https://packagist.org/packages/mustache/mustache)


Usage
-----

A quick example:

```php
<?php
$m = new Mustache_Engine;
echo $m->render('Hello {{planet}}', array('planet' => 'World!')); // "Hello World!"
```


And a more in-depth example -- this is the canonical Mustache template:

```html+jinja
Hello {{name}}
You have just won {{value}} dollars!
{{#in_ca}}
Well, {{taxed_value}} dollars, after taxes.
{{/in_ca}}
```


Create a view "context" object -- which could also be an associative array, but those don't do functions quite as well:

```php
<?php
class Chris {
public $name = "Chris";
public $value = 10000;

public function taxed_value() {
return $this->value - ($this->value * 0.4);
}

public $in_ca = true;
}
```


And render it:

```php
<?php
$m = new Mustache_Engine;
$chris = new Chris;
echo $m->render($template, $chris);
```


And That's Not All!
-------------------

Read [the Mustache.php documentation](https://github.com/bobthecow/mustache.php/wiki/Home) for more information.


See Also
--------

* [Readme for the Ruby Mustache implementation](http://github.com/defunkt/mustache/blob/master/README.md).
* [mustache(5)](http://mustache.github.com/mustache.5.html) man page.
Loading

0 comments on commit a1f21fe

Please sign in to comment.