DAT-3147 assets entry point added

This commit is contained in:
idradm 2015-08-27 10:30:25 +02:00
parent 8e6bffbb7f
commit 9b020ee4fb
3 changed files with 30 additions and 4 deletions

View file

@ -55,6 +55,7 @@ $wgAutoloadClasses[ 'ApiPortableInfobox' ] = $dir . 'controllers/ApiPortableInfo
$wgAutoloadClasses[ 'ApiQueryPortableInfobox' ] = $dir . 'controllers/ApiQueryPortableInfobox.class.php';
$wgAutoloadClasses[ 'PortableInfoboxHooks' ] = $dir . 'PortableInfoboxHooks.class.php';
$wgAutoloadClasses[ 'ApiQueryAllinfoboxes' ] = $dir . 'controllers/ApiQueryAllinfoboxes.class.php';
$wgAutoloadClasses[ 'PortableInfoboxBuilderController' ] = $dir . 'controllers/PortableInfoboxBuilderController.class.php';
// query pages
$wgAutoloadClasses[ 'AllinfoboxesQueryPage' ] = $dir . 'querypage/AllinfoboxesQueryPage.php';

View file

@ -0,0 +1,16 @@
<?php
class PortableInfoboxBuilderController extends WikiaController {
public function getAssets() {
$dir = PortableInfoboxRenderService::getTemplatesDir();
$result = array_map( function ( $template ) use ( $dir ) {
return file_get_contents( "{$dir}/{$template}" );
}, PortableInfoboxRenderService::getTemplates() );
$response = $this->getResponse();
$response->setFormat( WikiaResponse::FORMAT_JSON );
$response->setVal( "css", AssetsManager::getInstance()->getURL( "portable_infobox_scss" ) );
$response->setVal( "templates", $result );
}
}

View file

@ -1,11 +1,11 @@
<?php
use \Wikia\PortableInfobox\Helpers\PortableInfoboxRenderServiceHelper;
use Wikia\PortableInfobox\Helpers\PortableInfoboxRenderServiceHelper;
class PortableInfoboxRenderService extends WikiaService {
const MOBILE_TEMPLATE_POSTFIX = '-mobile';
private $templates = [
private static $templates = [
'wrapper' => 'PortableInfoboxWrapper.mustache',
'title' => 'PortableInfoboxItemTitle.mustache',
'header' => 'PortableInfoboxItemHeader.mustache',
@ -21,7 +21,15 @@ class PortableInfoboxRenderService extends WikiaService {
function __construct() {
$this->templateEngine = ( new Wikia\Template\MustacheEngine )
->setPrefix( dirname( __FILE__ ) . '/../templates' );
->setPrefix( self::getTemplatesDir() );
}
public static function getTemplatesDir() {
return dirname( __FILE__ ) . '/../templates';
}
public static function getTemplates() {
return self::$templates;
}
/**
@ -67,7 +75,7 @@ class PortableInfoboxRenderService extends WikiaService {
if ( !empty( $infoboxHtmlContent ) ) {
$output = $this->renderItem( 'wrapper', [ 'content' => $infoboxHtmlContent, 'theme' => $theme,
'layout' => $layout ] );
'layout' => $layout ] );
} else {
$output = '';
}
@ -134,6 +142,7 @@ class PortableInfoboxRenderService extends WikiaService {
*
* @param string $type
* @param array $data
*
* @return bool|string - HTML
*/
private function renderItem( $type, array $data ) {