Mustache -> Handlebars

This commit is contained in:
Luqgreg 2018-08-08 11:31:33 +02:00
parent 6d52d0e683
commit 7fe3a39d1d
24 changed files with 121 additions and 117 deletions

View file

@ -44,8 +44,8 @@
"WikiaObject": "includes/nirvana/WikiaObject.class.php",
"WikiaRegistry": "includes/nirvana/WikiaRegistry.class.php",
"WikiaGlobalRegistry": "includes/nirvana/WikiaGlobalRegistry.class.php",
"Wikia\\Template\\MustacheEngine": "includes/mustache/MustacheEngine.class.php",
"MustacheService": "includes/mustache/MustacheService.class.php",
"Wikia\\Template\\TemplateEngine": "includes/templates/TemplateEngine.class.php",
"TemplateService": "includes/templates/TemplateService.class.php",
"HtmlHelper": "includes/filehelpers/HtmlHelper.class.php",
"FileNamespaceSanitizeHelper": "includes/filehelpers/FileNamespaceSanitizeHelper.php",
"WikiaFileHelper": "includes/filehelpers/WikiaFileHelper.class.php",
@ -69,7 +69,7 @@
"Wikia\\PortableInfobox\\Parser\\Nodes\\NodeUnimplemented": "services/Parser/Nodes/NodeUnimplemented.php",
"Wikia\\PortableInfobox\\Helpers\\InfoboxParamsValidator": "services/Helpers/InfoboxParamsValidator.php",
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxDataBag": "services/Helpers/PortableInfoboxDataBag.php",
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxMustacheEngine": "services/Helpers/PortableInfoboxMustacheEngine.php",
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxTemplateEngine": "services/Helpers/PortableInfoboxTemplateEngine.php",
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxImagesHelper": "services/Helpers/PortableInfoboxImagesHelper.php",
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxParsingHelper": "services/Helpers/PortableInfoboxParsingHelper.php",
"Wikia\\PortableInfobox\\Helpers\\PagePropsProxy": "services/Helpers/PagePropsProxy.php",

View file

@ -2,13 +2,13 @@
namespace Wikia\Template;
/**
* Mustache FileSystem-based engine for Wikia Templating System.
* Template FileSystem-based engine for Wikia Templating System.
*
* @package Wikia\Template
* @author Federico "Lox" Lucignano <federico@wikia-inc.com>
*/
class MustacheEngine {
class TemplateEngine {
protected $values = [];
protected $prefix = '';
@ -16,9 +16,9 @@ class MustacheEngine {
* Checks if a template exists.
*
* @param string $template The name of the template, will be combined with
* the value passed to MustacheEngine::setPrefix().
* the value passed to TemplateEngine::setPrefix().
* In case of FileSystem-based engines it should be the filename
* either alone (MustacheEngine::setPrefix()) or the full path, both need to
* either alone (TemplateEngine::setPrefix()) or the full path, both need to
* include the file's extension.
*
* @return bool Wether the template was found or not
@ -36,9 +36,9 @@ class MustacheEngine {
* Renders the template as a string.
*
* @param string $template The name of the template, will be combined with
* the value passed to MustacheEngine::setPrefix().
* the value passed to TemplateEngine::setPrefix().
* In case of FileSystem-based engines it should be the filename
* either alone (MustacheEngine::setPrefix()) or the full path, both need to
* either alone (TemplateEngine::setPrefix()) or the full path, both need to
* include the file's extension.
*
* @return string The rendered template
@ -49,7 +49,7 @@ class MustacheEngine {
$path = $this->prefix == '' ? $template : $this->prefix . DIRECTORY_SEPARATOR . $template;
//wfProfileIn( __METHOD__ . " - template: {$path}" );
$contents = \MustacheService::getInstance()->render( $path, $this->values );
$contents = \TemplateService::getInstance()->render( $path, $this->values );
//wfProfileOut( __METHOD__ . " - template: {$path}" );
//wfProfileOut( __METHOD__ );
@ -60,11 +60,11 @@ class MustacheEngine {
* Sets the base path for this instance.
*
* @param string $prefix The prefix to append to the template
* name passed as a parameter to MustacheEngine::render(), e.g. the path
* name passed as a parameter to TemplateEngine::render(), e.g. the path
* to a folder containing template files for filesystem-based
* engines.
*
* @return MustacheEngine The current instance
* @return TemplateEngine The current instance
*/
public function setPrefix ( $prefix ) {
$this->prefix = (string) $prefix;
@ -86,9 +86,9 @@ class MustacheEngine {
* @param array $values The values to be passed to a template
* in the form of an associative array, i.e. [IDENTIFIER => VALUE]
*
* @return MustacheEngine The current instance
* @return TemplateEngine The current instance
*
* @see MustacheEngine::setVal() if you need to set only one value
* @see TemplateEngine::setVal() if you need to set only one value
*/
public function setData( Array $values ) {
$this->values = $values;
@ -102,9 +102,9 @@ class MustacheEngine {
* @param array $values The values to be added/updated in the form of an
* associative array, i.e. [IDENTIFIER => VALUE]
*
* @return MustacheEngine The current instance
* @return TemplateEngine The current instance
*
* * @see MustacheEngine::setVal() if you need to add/overwrite only one value
* * @see TemplateEngine::setVal() if you need to add/overwrite only one value
*/
public function updateData( Array $values ) {
wfProfileIn( __METHOD__ );
@ -118,9 +118,9 @@ class MustacheEngine {
/**
* Empties the collection of values stored in an instance
*
* @return MustacheEngine The current instance
* @return TemplateEngine The current instance
*
* @see MustacheEngine::clearVal() if you need to clear only one value
* @see TemplateEngine::clearVal() if you need to clear only one value
*/
public function clearData(){
$this->values = [];
@ -133,7 +133,7 @@ class MustacheEngine {
* @return array The values set for this instance, null if the collection
* wasn't set
*
* @see MustacheEngine::getVal() if you need to get only one value
* @see TemplateEngine::getVal() if you need to get only one value
*/
public function getData() {
return $this->values;
@ -145,9 +145,9 @@ class MustacheEngine {
* @param string $name The name of the value
* @param mixed $value The real value
*
* @return MustacheEngine The current instance
* @return TemplateEngine The current instance
*
* @see MustacheEngine::setData() if you need to set multiple values instead
* @see TemplateEngine::setData() if you need to set multiple values instead
* of calling this method multiple times
*/
public function setVal( $name, $value ) {
@ -160,9 +160,9 @@ class MustacheEngine {
*
* @param string $name The name of the value
*
* @return MustacheEngine The current instance
* @return TemplateEngine The current instance
*
* @see MustacheEngine::clearData() if you need to clear the whole collection
* @see TemplateEngine::clearData() if you need to clear the whole collection
* instead of calling this method multiple times
*/
public function clearVal( $name ){
@ -177,7 +177,7 @@ class MustacheEngine {
*
* @return mixed|null The current instance
*
* @see MustacheEngine::setData() if you need to get multiple values instead
* @see TemplateEngine::setData() if you need to get multiple values instead
* of calling this method multiple times
*/
public function getVal( $name ) {

View file

@ -1,16 +1,16 @@
<?php
/**
* MustacheService is a wrapper for actual Mustache implementation
* TemplateService is a wrapper for actual Mustache/Handlebars implementation
* that automatically searches for all required partials and prefetches them
* in order to supply Mustache engine (either in PHP or JS) with all necessary
* in order to supply the engine (either in PHP or JS) with all necessary
* dependencies.
*
* @see https://github.com/wikimedia/mediawiki-vendor/tree/master/zordius/lightncandy
*
* @author Władysław Bodzek <wladek@wikia-inc.com>
*/
class MustacheService {
class TemplateService {
const REGEX_PARTIALS = '/{{>\s*([^{}]*?)}}/';
@ -20,7 +20,7 @@ class MustacheService {
private $cache = array();
/**
* Singleton - use MustacheService::getInstance() instead
* Singleton - use TemplateService::getInstance() instead
*/
private function __construct() {}
@ -29,8 +29,8 @@ class MustacheService {
*
* @param $fileName string File path (absolute)
* @return array Array containing requested data, keys are:
* - MustacheService::TEMPLATE - contains template contents
* - MustacheService::DEPENDENCIES - list of all partials that may be included
* - TemplateService::TEMPLATE - contains template contents
* - TemplateService::DEPENDENCIES - list of all partials that may be included
* @throws Exception Thrown if any partial cannot be found
*/
private function getTemplateInfo( $fileName ) {
@ -140,10 +140,10 @@ class MustacheService {
* @throws Exception Thrown if any partial cannot be found
*/
public function render( $fileName, $data ) {
$renderer = $this->getRenderer($fileName);
return $renderer($this->parseData($data));
$renderer = $this->getRenderer( $fileName );
return $renderer( $data );
}
/**
* Returns a mustache renderer
*
@ -155,19 +155,19 @@ class MustacheService {
if ( !empty($this->cache[$fileName] ) ) {
return $this->cache[$fileName];
}
list( $template, $partials ) = $this->getTemplateAndPartials( $fileName );
// @see https://github.com/wikimedia/mediawiki-vendor/tree/master/zordius/lightncandy
$renderer = LightnCandy::prepare(
LightnCandy::compile($template, array(
'flags' => LightnCandy::FLAG_MUSTACHE | LightnCandy::FLAG_BESTPERFORMANCE,
'flags' => LightnCandy::FLAG_BESTPERFORMANCE,
'partials' => $partials
))
);
$this->cache[$fileName] = $renderer;
return $renderer;
}
@ -190,9 +190,9 @@ class MustacheService {
}
/**
* Get a singleton instance of MustacheService
* Get a singleton instance of TemplateService
*
* @return MustacheService Singleton
* @return TemplateService Singleton
*/
public static function getInstance() {
static $instance;

View file

@ -3,27 +3,27 @@
namespace Wikia\PortableInfobox\Helpers;
use MediaWiki\Logger\LoggerFactory;
use Wikia\Template\MustacheEngine;
use Wikia\Template\TemplateEngine;
class PortableInfoboxMustacheEngine {
class PortableInfoboxTemplateEngine {
const TYPE_NOT_SUPPORTED_MESSAGE = 'portable-infobox-render-not-supported-type';
protected static $templates = [
'wrapper' => 'PortableInfoboxWrapper.mustache',
'title' => 'PortableInfoboxItemTitle.mustache',
'header' => 'PortableInfoboxItemHeader.mustache',
'image' => 'PortableInfoboxItemImage.mustache',
'data' => 'PortableInfoboxItemData.mustache',
'group' => 'PortableInfoboxItemGroup.mustache',
'smart-group' => 'PortableInfoboxItemSmartGroup.mustache',
'horizontal-group-content' => 'PortableInfoboxHorizontalGroupContent.mustache',
'navigation' => 'PortableInfoboxItemNavigation.mustache',
'image-collection' => 'PortableInfoboxItemImageCollection.mustache'
'wrapper' => 'PortableInfoboxWrapper.hbs',
'title' => 'PortableInfoboxItemTitle.hbs',
'header' => 'PortableInfoboxItemHeader.hbs',
'image' => 'PortableInfoboxItemImage.hbs',
'data' => 'PortableInfoboxItemData.hbs',
'group' => 'PortableInfoboxItemGroup.hbs',
'smart-group' => 'PortableInfoboxItemSmartGroup.hbs',
'horizontal-group-content' => 'PortableInfoboxHorizontalGroupContent.hbs',
'navigation' => 'PortableInfoboxItemNavigation.hbs',
'image-collection' => 'PortableInfoboxItemImageCollection.hbs'
];
protected $templateEngine;
public function __construct() {
$this->templateEngine = ( new MustacheEngine )
$this->templateEngine = ( new TemplateEngine )
->setPrefix( self::getTemplatesDir() );
}

View file

@ -1,7 +1,7 @@
<?php
use Wikia\PortableInfobox\Helpers\PortableInfoboxImagesHelper;
use Wikia\PortableInfobox\Helpers\PortableInfoboxMustacheEngine;
use Wikia\PortableInfobox\Helpers\PortableInfoboxTemplateEngine;
class PortableInfoboxRenderService {
// keep synced with scss variables ($infobox-width)
@ -16,7 +16,7 @@ class PortableInfoboxRenderService {
private $helper;
public function __construct() {
$this->templateEngine = new PortableInfoboxMustacheEngine();
$this->templateEngine = new PortableInfoboxTemplateEngine();
}
/**

View file

@ -0,0 +1,19 @@
<table class="pi-horizontal-group{{#unless renderLabels}} pi-horizontal-group-no-labels{{/unless}}">
{{#if header}}<caption class="pi-header pi-secondary-font pi-secondary-background pi-item-spacing">{{{header}}}</caption>{{/if}}
{{#if renderLabels}}
<thead>
<tr>
{{#each labels}}
<th class="pi-horizontal-group-item pi-data-label pi-secondary-font pi-border-color pi-item-spacing">{{{.}}}</th>
{{/each}}
</tr>
</thead>
{{/if}}
<tbody>
<tr>
{{#each values}}
<td class="pi-horizontal-group-item pi-data-value pi-font pi-border-color pi-item-spacing">{{{.}}}</td>
{{/each}}
</tr>
</tbody>
</table>

View file

@ -1,19 +0,0 @@
<table class="pi-horizontal-group{{^renderLabels}} pi-horizontal-group-no-labels{{/renderLabels}}">
{{#header}}<caption class="pi-header pi-secondary-font pi-secondary-background pi-item-spacing">{{{header}}}</caption>{{/header}}
{{#renderLabels}}
<thead>
<tr>
{{#labels}}
<th class="pi-horizontal-group-item pi-data-label pi-secondary-font pi-border-color pi-item-spacing">{{{.}}}</th>
{{/labels}}
</tr>
</thead>
{{/renderLabels}}
<tbody>
<tr>
{{#values}}
<td class="pi-horizontal-group-item pi-data-value pi-font pi-border-color pi-item-spacing">{{{.}}}</td>
{{/values}}
</tr>
</tbody>
</table>

View file

@ -0,0 +1,6 @@
<div class="pi-item pi-data pi-item-spacing pi-border-color{{#if cssClasses}} {{{cssClasses}}}{{/if}}"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>
{{#if label}}
<h3 class="pi-data-label pi-secondary-font">{{{label}}}</h3>
{{/if}}
<div class="pi-data-value pi-font">{{{value}}}</div>
</div>

View file

@ -1,6 +0,0 @@
<div class="pi-item pi-data pi-item-spacing pi-border-color{{#cssClasses}} {{{cssClasses}}}{{/cssClasses}}"{{#inlineStyles}} style="{{inlineStyles}}"{{/inlineStyles}}>
{{#label}}
<h3 class="pi-data-label pi-secondary-font">{{{label}}}</h3>
{{/label}}
<div class="pi-data-value pi-font">{{{value}}}</div>
</div>

View file

@ -0,0 +1 @@
<section class="pi-item pi-group pi-border-color{{#if cssClasses}} {{{cssClasses}}}{{/if}}">{{{content}}}</section>

View file

@ -1 +0,0 @@
<section class="pi-item pi-group pi-border-color{{#cssClasses}} {{{cssClasses}}}{{/cssClasses}}">{{{content}}}</section>

View file

@ -0,0 +1 @@
<h2 class="pi-item pi-header pi-secondary-font pi-item-spacing pi-secondary-background"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}}</h2>

View file

@ -1 +0,0 @@
<h2 class="pi-item pi-header pi-secondary-font pi-item-spacing pi-secondary-background"{{#inlineStyles}} style="{{inlineStyles}}"{{/inlineStyles}}>{{{value}}}</h2>

View file

@ -0,0 +1,7 @@
<figure class="pi-item pi-image{{#if isVideo}} pi-video{{/if}}">
<a href="{{url}}" class="image image-thumbnail{{#isVideo}} video video-thumbnail{{/isVideo}}" title="{{alt}}">
{{#unless isVideo}}<img src="{{thumbnail}}" srcset="{{thumbnail}} 1x, {{thumbnail2x}} 2x" class="pi-image-thumbnail" alt="{{alt}}" width="{{{width}}}" height="{{{height}}}"/>
{{else}}<video src="{{url}}" class="pi-video-player" controls="true" controlsList="nodownload" preload="metadata">{{alt}}</video>{{/unless}}
</a>
{{#if caption}}<figcaption class="pi-item-spacing pi-caption">{{{caption}}}</figcaption>{{/if}}
</figure>

View file

@ -1,7 +0,0 @@
<figure class="pi-item pi-image{{#isVideo}} pi-video{{/isVideo}}">
<a href="{{url}}" class="image image-thumbnail{{#isVideo}} video video-thumbnail{{/isVideo}}" title="{{alt}}">
{{^isVideo}}<img src="{{thumbnail}}" srcset="{{thumbnail}} 1x, {{thumbnail2x}} 2x" class="pi-image-thumbnail" alt="{{alt}}" width="{{{width}}}" height="{{{height}}}"/>{{/isVideo}}
{{#isVideo}}<video src="{{url}}" class="pi-video-player" controls controlsList="nodownload" preload="metadata">{{alt}}</video>{{/isVideo}}
</a>
{{#caption}}<figcaption class="pi-item-spacing pi-caption">{{{caption}}}</figcaption>{{/caption}}
</figure>

View file

@ -0,0 +1,15 @@
<div class="pi-image-collection">
<ul class="pi-image-collection-tabs">
{{#each images}}<li class="pi-tab-link pi-item-spacing{{#if isFirst}} current{{/if}}" data-pi-tab="pi-tab-{{ref}}">{{{caption}}}</li>{{/each}}
</ul>
{{#each images}}
<div class="pi-image-collection-tab-content{{#if isFirst}} current{{/if}}" id="pi-tab-{{ref}}">
<figure class="pi-item pi-image{{#if isVideo}} pi-video{{/if}}">
<a href="{{url}}" class="image image-thumbnail{{#isVideo}} video video-thumbnail{{/isVideo}}" title="{{alt}}">
{{#unless isVideo}}<img src="{{thumbnail}}" srcset="{{thumbnail}} 1x, {{thumbnail2x}} 2x" class="pi-image-thumbnail" alt="{{alt}}" width="{{{width}}}" height="{{{height}}}"/>
{{else}}<video src="{{url}}" class="pi-video-player" controls="true" controlsList="nodownload" preload="metadata">{{alt}}</video>{{/unless}}
</a>
</figure>
</div>
{{/each}}
</div>

View file

@ -1,11 +0,0 @@
<div class="pi-image-collection">
<ul class="pi-image-collection-tabs">
{{#images}}<li class="pi-tab-link pi-item-spacing{{#isFirst}} current{{/isFirst}}" data-pi-tab="pi-tab-{{ref}}">{{{caption}}}</li>{{/images}}
</ul>
{{#images}}
<div class="pi-image-collection-tab-content{{#isFirst}} current{{/isFirst}}" id="pi-tab-{{ref}}">
{{>PortableInfoboxItemImage}}
</div>
{{/images}}
</div>

View file

@ -1 +1 @@
<nav class="pi-navigation pi-item-spacing pi-secondary-background pi-secondary-font">{{{value}}}</nav>
<nav class="pi-navigation pi-item-spacing pi-secondary-background pi-secondary-font">{{{value}}}</nav>

View file

@ -1,14 +1,14 @@
<section class="pi-item pi-smart-group pi-border-color">
{{#renderLabels}}
{{#if renderLabels}}
<section class="pi-smart-group-head">
{{#labels}}
{{#each labels}}
<h3 class="pi-smart-data-label pi-data-label pi-secondary-font pi-item-spacing" style="{{{inlineStyles}}}">{{{value}}}</h3>
{{/labels}}
{{/each}}
</section>
{{/renderLabels}}
{{/if}}
<section class="pi-smart-group-body">
{{#values}}
{{#each values}}
<div class="pi-smart-data-value pi-data-value pi-font pi-item-spacing" style="{{{inlineStyles}}}">{{{value}}}</div>
{{/values}}
{{/each}}
</section>
</section>
</section>

View file

@ -0,0 +1 @@
<h2 class="pi-item pi-item-spacing pi-title"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}}</h2>

View file

@ -1 +0,0 @@
<h2 class="pi-item pi-item-spacing pi-title"{{#inlineStyles}} style="{{inlineStyles}}"{{/inlineStyles}}>{{{value}}}</h2>

View file

@ -1,18 +1,18 @@
<p class="pi-error-info">{{info}}</p>
<ul class="pi-debug">
{{#code}}
{{#each code}}
<li>
<div class="pi-debug-line{{#error}} error{{/error}}">
<div class="pi-debug-line{{#if error}} error{{/if}}">
<div class="pi-debug-line-number">{{line}}</div>
<div class="pi-debug-line-code">{{codeLine}}</div>
</div>
{{#error}}
{{#if error}}
<div class="pi-debug-error-message">
{{#error_messages}}
{{#each error_messages}}
<p class="pi-debug-error-message-item">{{{message}}}</p>
{{/error_messages}}
{{/each}}
</div>
{{/error}}
{{/if}}
</li>
{{/code}}
</ul>
{{/each}}
</ul>

View file

@ -0,0 +1 @@
<aside class="portable-infobox pi-background{{#if theme}} {{theme}}{{/if}}{{#if layout}} {{layout}}{{/if}}">{{{content}}}</aside>

View file

@ -1 +0,0 @@
<aside class="portable-infobox pi-background{{#theme}} {{theme}}{{/theme}}{{#layout}} {{layout}}{{/layout}}">{{{content}}}</aside>