protected function compile($templateName) { $filenames = $this->lightncandy->getTemplateFilenames($templateName); if (!file_exists($filenames['template'])) { $this->error("Could not find template at: {$filenames['template']}"); } $this->lightncandy->getTemplate($templateName); if (!file_exists($filenames['compiled'])) { $this->error("Template compilation completed, but no compiled code found on disk"); } else { $this->output("Successfully compiled {$templateName} to {$filenames['compiled']}\n"); } }
protected function renderApiResponse(array $apiResponse) { // Render the flow-component wrapper if (empty($apiResponse['blocks'])) { return array(); } $out = $this->getOutput(); // Add JSON blob for OOUI widgets $out->addHTML(Html::inlineScript('mw.flow = mw.flow || {}; mw.flow.data = ' . FormatJson::encode($apiResponse) . ';')); $renderedBlocks = array(); foreach ($apiResponse['blocks'] as $block) { // @todo find a better way to do this; potentially make all blocks their own components switch ($block['type']) { case 'board-history': $flowComponent = 'boardHistory'; $page = 'history'; break; case 'topic': if ($block['submitted']['action'] === 'history') { $page = 'history'; $flowComponent = 'boardHistory'; } else { $page = 'topic'; $flowComponent = 'board'; } break; default: $flowComponent = 'board'; $page = 'board'; } // Don't re-render a block type twice in one page if (isset($renderedBlocks[$flowComponent])) { continue; } $renderedBlocks[$flowComponent] = true; // Get the block loop template $template = $this->lightncandy->getTemplate('flow_block_loop'); $classes = array('flow-component', "{$page}-page"); // Add mw-content-{ltr,rtl} text if necessary (MW core doesn't add it for non-view actions if (\Action::getActionName($this) !== 'view') { $title = Title::newFromText($apiResponse['title']); $classes[] = 'mw-content-' . $title->getPageViewLanguage()->getDir(); } // Output the component, with the rendered blocks inside it $out->addHTML(Html::rawElement('div', array('class' => implode(' ', $classes), 'data-flow-component' => $flowComponent, 'data-flow-id' => $apiResponse['workflow']), $template($apiResponse))); } }