Skip to content

Commit

Permalink
Clone and adapt conarwelsh/mustache-l4 to lightncandy
Browse files Browse the repository at this point in the history
  • Loading branch information
Arsène Dernière committed Apr 22, 2014
1 parent d3851f1 commit 1d2de35
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "arseneDerniere/lightncandy-l4",
"type": "library",
"description": "A lightncandy (\"A PHP library to support almost all features of handlebars\" by zordius) wrapper for Laravel 4.",
"keywords": ["laravel", "laravel 4", "lightncandy", "handlebars", "php"],
"homepage": "https://github.com/arseneDerniere/lightncandy-l4",
"license": "MIT",
"authors": [
{
"name": "Arsène Dernière"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "~4",
"zordius/lightncandy": "dev-master"
},
"autoload": {
"psr-0": {
"ArseneDerniere\\LightnCandyL4": "src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
32 changes: 32 additions & 0 deletions src/ArseneDerniere/LightnCandyL4/FilesystemLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace ArseneDerniere\LightnCandyL4;

use LightnCandy_Loader;
use Illuminate\Filesystem\Filesystem;

class FilesystemLoader implements LightnCandy_loader {

private $templates = array();

public function __construct(Filesystem $files)
{
$this->app = app();
$this->files = $files;
$this->finder = $this->app['view.finder'];
}

public function load($name)
{
if (!isset($this->templates[$name])) {
$this->templates[$name] = $this->loadFile($name);
}
return $this->templates[$name];
}

public function loadFile($name)
{
$path = $this->finder->find($name);
return $this->files->get($path);
}

}
28 changes: 28 additions & 0 deletions src/ArseneDerniere/LightnCandyL4/LightnCandyEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace ArseneDerniere\LightnCandyL4;

use Illuminate\View\Engines\EngineInterface;
use Illuminate\Filesystem\Filesystem;
use LightnCandy_Engine;

class LightnCandyEngine implements EngineInterface {

public function __construct(Filesystem $files)
{
$this->files = $files;
}

public function get($path, array $data = array())
{
$view = $this->files->get($path);
$app = app();
$m = new LightnCandy_Engine( $app['config']->get('lightncandy-l4::config') );

$data = array_map(function($item){
return (is_object($item) && method_exists($item, 'toArray')) ? $item->toArray() : $item;
}, $data);

return $m->render($view, $data);
}

}
51 changes: 51 additions & 0 deletions src/ArseneDerniere/LightnCandyL4/LightnCandyL4ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php namespace ArseneDerniere\LightnCandyL4;

use Illuminate\Support\ServiceProvider;

class LightnCandyL4ServiceProvider extends ServiceProvider {

/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->package('arseneDerniere/lightncandy-l4');

$app = $this->app;

$app->extend('view.engine.resolver', function($resolver, $app)
{
$resolver->register('lightncandy', function() use($app)
{
return $app->make('ArseneDerniere\LightnCandyL4\LightnCandyEngine');
});
return $resolver;
});

$app->extend('view', function($env, $app)
{
$env->addExtension('lightncandy', 'lightncandy');
return $env;
});
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('lightncandy-l4');
}

}
46 changes: 46 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

return array(

// The class prefix for compiled templates.
'template_class_prefix' => '__LightnCandy_',

// A cache directory for compiled templates. Mustache will not cache templates unless this is set.
'cache' => storage_path() . '/cache/views/lightncandy',

// Override default permissions for cache files. Defaults to using the system-defined umask.
// It is strongly recommended that you configure your umask properly rather than overriding permissions here.
// 'cache_file_mode' => 0666,

// A Mustache loader instance for partials. If none is specified, defaults to an ArrayLoader for the supplied
// partials option, if present, and falls back to the specified template loader.
'partials_loader' => App::make('ArseneDerniere\LightnCandyL4\FilesystemLoader'),

// An array of Mustache partials. Useful for quick-and-dirty string template loading,
// but not as efficient or lazy as a Filesystem (or database) loader.
// 'partials' => array(),

// An array of 'helpers'. Helpers can be global variables or objects, closures (e.g. for higher order sections),
// or any other valid Mustache context value. They will be prepended to the context stack,
// so they will be available in any template loaded by this Mustache instance.
// 'helpers' => array(),

// An 'escape' callback, responsible for escaping double-mustache variables. Defaults to htmlspecialchars.
// 'escape' => function($value) {
// return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
// },

// Character set for htmlspecialchars. Defaults to UTF-8.
// 'charset' => 'ISO-8859-1',

// A Mustache logger instance. No logging will occur unless this is set. Using a PSR-3 compatible logging
// library—such as Monolog—is highly recommended. A simple stream logger implementation is available as well.
// 'logger' => new LightnCandy_Logger_StreamLogger('php://stderr'),

// Only treat Closure instances and invokable classes as callable. If true, values like
// array('ClassName', 'methodName') and array($classInstance, 'methodName'), which are
// traditionally "callable" in PHP, are not called to resolve variables for interpolation
// or section contexts. This helps protect against arbitrary code execution when user input
// is passed directly into the template.
// 'strict_callables' => true,
);
Empty file added tests/.gitkeep
Empty file.

0 comments on commit 1d2de35

Please sign in to comment.