private function _generateBlocks($themeDir, $distDir, $container) { if (file_exists($themeDir . '/block.json')) { $this->filesystem->copy($themeDir . '/block.json', $distDir . '/block.json'); BlockToolkit::generateBlcokContent($themeDir . '/block.json', $distDir . '/blocks', $container); } }
public function showBlock($code) { $block = ServiceKernel::instance()->createService('Content.BlockService')->getBlockByCode($code); if (empty($block)) { return ''; } $env = $this->container->getParameter('kernel.environment'); if ($env == 'prod') { return $block['content']; } // 从data渲染生成html然后返回 return BlockToolkit::render($block, $this->container); }
public function initBlock($output) { $output->write(' 初始化编辑区'); $json = dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/web/themes/block.json'; BlockToolkit::init($json, $this->getContainer()); $json = dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/web/themes/default/block.json'; BlockToolkit::init($json, $this->getContainer()); $json = dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/web/themes/autumn/block.json'; BlockToolkit::init($json, $this->getContainer()); $json = dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/web/themes/jianmo/block.json'; BlockToolkit::init($json, $this->getContainer()); }
private function generateBlcokContent($metaFilePath) { $metas = file_get_contents($metaFilePath); $metas = json_decode($metas, true); if (empty($metas)) { throw new \RuntimeException("插件元信息文件{$metaFilePath}格式不符合JSON规范,解析失败,请检查元信息文件格式"); } foreach ($metas as $code => $meta) { $data = array(); foreach ($meta['items'] as $key => $item) { $data[$key] = $item['default']; } $block = array('templateName' => $meta['templateName'], 'data' => $data); $html = BlockToolkit::render($block, $this->getContainer()); $filename = "block-" . md5($code) . '.html'; $folder = "{$this->distDirectory}/web/install/blocks/"; if (!file_exists($folder)) { mkdir($folder); } $filename = $folder . $filename; file_put_contents($filename, $html); } }
protected function replaceContent(&$block, $output) { $output->writeln('<info>替换CONTENT数据</info>'); $newContent = BlockToolkit::render($block, $this->getContainer()); $block['content'] = $newContent; }
public function visualEditAction(Request $request, $blockId) { $block = $this->getBlockService()->getBlock($blockId); if ('POST' == $request->getMethod()) { $data = $request->request->get('data'); $block['data'] = $data; $html = BlockToolkit::render($block, $this->container); $block = $this->getBlockService()->updateBlock($blockId, array('data' => $data, 'content' => $html)); $this->setFlashMessage('success', '保存成功!'); } return $this->render('TopxiaAdminBundle:Block:block-visual-edit.html.twig', array('block' => $block, 'action' => 'edit')); }
private function initBlock($jsonFile, $container) { BlockToolkit::init($jsonFile, $container); }
protected function initBlock() { BlockToolkit::init(__DIR__ . '/block.json', null, __DIR__ . '/blocks/'); }