Skip to content

Commit

Permalink
Add raw option for html block in order to render the html output in
Browse files Browse the repository at this point in the history
admin view. closes #1269
  • Loading branch information
nadar committed Apr 17, 2017
1 parent 7ba9475 commit a36e179
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The changelog contains informations about bug fixes, new features or bc breaking
- [#1268](https://github.com/luyadev/luya/issues/1268) Module block strict render ability in order to strict render the given action and controller paths instead of parse them trough the request component.
- [#1227](https://github.com/luyadev/luya/issues/1227) Added preloadModels() method for the Menu Query in order to collect all models for the given request. This can strongly reduce the sql count when working with properties or models.
- [#1266](https://github.com/luyadev/luya/issues/1266) render() method for the mailer component in order to provide controller template files.
- [#1269](https://github.com/luyadev/luya/issues/1269) Add raw option for html block in order to render the html output in admin view.

### Fixed

Expand Down
3 changes: 2 additions & 1 deletion modules/cms/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"phpunit/phpunit" : "~5.0",
"luyadev/luya" : "^1.0@dev",
"luyadev/luya-module-admin" : "^1.0@dev",
"satooshi/php-coveralls": "~1.0"
"satooshi/php-coveralls": "~1.0",
"twig/twig" : "^2.0"
},
"autoload" : {
"psr-4" : {
Expand Down
81 changes: 72 additions & 9 deletions modules/cms/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions modules/cms/src/frontend/blocks/HtmlBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ public function config()
{
return [
'vars' => [
['var' => 'html', 'label' => Module::t('block_html_html_label'), 'type' => 'zaa-textarea'],
['var' => 'html', 'label' => Module::t('block_html_html_label'), 'type' => self::TYPE_TEXTAREA],
],
'cfgs' => [
['var' => 'raw', 'label' => Module::t('block_html_cfg_raw_label'), 'type' => self::TYPE_CHECKBOX]
],
];
}

Expand All @@ -64,6 +67,16 @@ public function config()
*/
public function admin()
{
return '{% if vars.html is empty %}<span class="block__empty-text">' . Module::t('block_html_no_content') . '</span>{% else %}<p><code>{{ vars.html | escape }}</code></p>{% endif %}';
$message = Module::t('block_html_no_content');
return <<<EOT
{% if vars.html is empty %}
<span class="block__empty-text">{$message}</span>{% else %}
{% if cfgs.raw == 1 %}
{{ vars.html | raw }}
{% else %}
<pre><code>{{ vars.html | escape }}</code></pre>
{% endif %}
{% endif %}
EOT;
}
}
3 changes: 2 additions & 1 deletion modules/cms/src/frontend/messages/de/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',

];
3 changes: 2 additions & 1 deletion modules/cms/src/frontend/messages/el/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',

];
3 changes: 2 additions & 1 deletion modules/cms/src/frontend/messages/en/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,6 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',
];
3 changes: 2 additions & 1 deletion modules/cms/src/frontend/messages/es/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',

];
3 changes: 2 additions & 1 deletion modules/cms/src/frontend/messages/fr/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',

];
4 changes: 2 additions & 2 deletions modules/cms/src/frontend/messages/it/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',
];
3 changes: 2 additions & 1 deletion modules/cms/src/frontend/messages/pt/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',

];
3 changes: 2 additions & 1 deletion modules/cms/src/frontend/messages/ru/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',

];
3 changes: 2 additions & 1 deletion modules/cms/src/frontend/messages/ua/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@

// 1.0.0
'block_module_strictrender' => 'Strict Render',
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.'
'block_module_strictrender_help' => 'When strict render is enabled, the module will only run the provided route (module, controller, action, params) without listening to action and controller routes.',
'block_html_cfg_raw_label' => 'Render HTML in Admin',

];
16 changes: 16 additions & 0 deletions modules/cms/tests/BlockTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace cmstests;

use Twig_Loader_String;

class BlockTestCase extends CmsFrontendTestCase
{
public $blockClass = null;
Expand Down Expand Up @@ -30,6 +32,20 @@ public function renderFrontend()
$this->assertNotNull($this->block->getFieldHelp());
return $this->block->renderFrontend();
}

public function renderAdmin()
{
$twig = new \Twig_Environment(new \Twig_Loader_Filesystem());
$temp = $twig->createTemplate($this->block->renderAdmin());
return $temp->render(['cfgs' => $this->block->getCfgValues(), 'vars' => $this->block->getVarValues()]);
}

public function renderAdminNoSpace()
{
$text = trim(preg_replace('/\s+/', ' ', $this->renderAdmin()));

return str_replace(['> ', ' <'], ['>', '<'], $text);
}

public function renderFrontendNoSpace()
{
Expand Down
14 changes: 14 additions & 0 deletions modules/cms/tests/src/frontend/blocks/HtmlBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ public function testInputHtml()

$this->assertSame('<div class="foo">Hello World</div>', $this->renderFrontendNoSpace());
}

public function testAdminRawOutput()
{
$this->block->setVarValues([
'html' => '<p>hello</p>',
]);

$this->assertSame('<pre><code>&lt;p&gt;hello&lt;/p&gt;</code></pre>', $this->renderAdminNoSpace());

$this->block->setCfgValues(['raw' => 1]);

$this->assertSame('<p>hello</p>', $this->renderAdminNoSpace());

}
}

0 comments on commit a36e179

Please sign in to comment.