1
0
mirror of https://github.com/flarum/core.git synced 2025-07-25 10:41:24 +02:00

Live preview of post editing/replying thanks to TextFormatter 👏

This commit is contained in:
Toby Zerner
2015-07-22 16:05:00 +09:30
parent f9ef9d791b
commit 8d89b4a776
14 changed files with 130 additions and 26 deletions

View File

@@ -29,7 +29,7 @@ class AssetManager
break;
default:
throw new DomainException('Unsupported asset type: '.$ext);
throw new DomainException('Unsupported asset type: ' . $ext);
}
}
@@ -38,14 +38,14 @@ class AssetManager
array_walk($files, [$this, 'addFile']);
}
public function addLess($string)
public function addLess(callable $callback)
{
$this->less->addString($string);
$this->less->addString($callback);
}
public function addJs($strings)
public function addJs(callable $callback)
{
$this->js->addString($string);
$this->js->addString($callback);
}
public function getCssFile()

View File

@@ -4,7 +4,7 @@ interface Compiler
{
public function addFile($file);
public function addString($string);
public function addString(callable $callback);
public function getFile();
}

View File

@@ -17,8 +17,8 @@ class LessCompiler extends RevisionCompiler
$parser->parseFile($file);
}
foreach ($this->strings as $string) {
$parser->parse($string);
foreach ($this->strings as $callback) {
$parser->parse($callback());
}
return $parser->getCss();

View File

@@ -19,9 +19,9 @@ class RevisionCompiler implements Compiler
$this->files[] = $file;
}
public function addString($string)
public function addString(callable $callback)
{
$this->strings[] = $string;
$this->strings[] = $callback;
}
public function getFile()
@@ -63,8 +63,8 @@ class RevisionCompiler implements Compiler
$output .= $this->format(file_get_contents($file));
}
foreach ($this->strings as $string) {
$output .= $this->format($string);
foreach ($this->strings as $callback) {
$output .= $this->format($callback());
}
return $output;

View File

@@ -131,4 +131,15 @@ abstract class ClientAction extends BaseClientAction
'core.write_a_post',
'core.write_a_reply'
];
protected function getAssets()
{
$assets = parent::getAssets();
$assets->addJs(function () {
return app('flarum.formatter')->getJS();
});
return $assets;
}
}

View File

@@ -160,11 +160,17 @@ abstract class ClientAction extends HtmlAction
*/
protected function addCustomizations(AssetManager $assets)
{
foreach ($this->getLessVariables() as $name => $value) {
$assets->addLess("@$name: $value;");
}
$assets->addLess(function () {
$less = '';
$assets->addLess($this->settings->get('custom_less'));
foreach ($this->getLessVariables() as $name => $value) {
$less .= "@$name: $value;";
}
$less .= $this->settings->get('custom_less');
return $less;
});
}
/**