Added [more] tag to news

main
Igor Scheller 3 years ago committed by msquare
parent 90ec8d8d43
commit f1531ad987

@ -2883,6 +2883,9 @@ msgstr "+"
msgid "news.is_meeting"
msgstr "[Treffen]"
msgid "news.read_more"
msgstr "Weiterlesen »"
msgid "news.updated"
msgstr "Aktualisiert"
@ -2913,6 +2916,9 @@ msgstr "Oben anpinnen"
msgid "news.edit.message"
msgstr "Nachricht"
msgid "news.edit.hint"
msgstr "Du kannst Markdown und den [more] Tag benutzen"
msgid "form.search"
msgstr "Suchen"

@ -153,6 +153,9 @@ msgstr "+"
msgid "news.is_meeting"
msgstr "[Meeting]"
msgid "news.read_more"
msgstr "Continue reading »"
msgid "news.updated"
msgstr "Updated"
@ -183,6 +186,9 @@ msgstr "Pin to top"
msgid "news.edit.message"
msgstr "Message"
msgid "news.edit.hint"
msgstr "You can use Markdown and the [more] tag"
msgid "form.search"
msgstr "Search"

@ -50,6 +50,8 @@
<div class="col-md-12">
{{ f.textarea('text', __('news.edit.message'), {'required': true, 'rows': 10, 'value': news ? news.text : ''}) }}
<p>{{ m.info(__('news.edit.hint')) }}</p>
{{ f.submit() }}
{{ f.submit(m.icon('eye'), {'name': 'preview', 'btn_type': 'info', 'title': __('form.preview')}) }}

@ -60,7 +60,10 @@
{% endif %}
<div class="card-body bg-body">
{{ news.text|raw|markdown(false) }}
{{ news.text(not is_overview)|raw|markdown(false) }}
{% if is_overview and news.text != news.text(false) %}
{{ m.button(__('news.read_more'), url('news/' ~ news.id), null, 'sm') }}
{% endif %}
</div>
<div class="card-footer {% if theme.type =='light' %}bg-light{% else %}bg-dark{% endif %} text-muted">

@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Str;
/**
* @property int $id
@ -21,7 +22,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
* @property Carbon|null $updated_at
*
* @property-read Collection|NewsComment[] $comments
* @property-read int|null $comments_count
* @property-read int|null $comments_count
*
* @method static QueryBuilder|LogEntry[] whereId($value)
* @method static QueryBuilder|LogEntry[] whereTitle($value)
@ -42,7 +43,7 @@ class News extends BaseModel
/** @var array */
protected $casts = [
'is_meeting' => 'boolean',
'is_pinned' => 'boolean',
'is_pinned' => 'boolean',
];
/** @var array */
@ -62,4 +63,20 @@ class News extends BaseModel
return $this->hasMany(NewsComment::class)
->orderBy('created_at');
}
/**
* @param bool $showMore
* @return string
*/
public function text(bool $showMore = true): string
{
if ($showMore || !Str::contains($this->text, 'more')) {
// Remove more tag
return preg_replace('/(.*)\[\s*more\s*\](.*)/is', '$1$2', $this->text);
}
// Only show text before more tag
$text = preg_replace('/(.*)(\s*\[\s*more\s*\].*)/is', '$1', $this->text);
return rtrim($text);
}
}

@ -64,6 +64,26 @@ class NewsTest extends ModelTest
$this->assertEquals($comment->toArray(), $news->comments->first()->toArray());
}
/**
* Tests that text more tags work
*
* @covers \Engelsystem\Models\News::text
*/
public function testTextMore(): void
{
$news = new News($this->newsData);
$news->text = "Foo\n\n\nBar";
$this->assertEquals("Foo\n\n\nBar", $news->text);
$this->assertEquals("Foo\n\n\nBar", $news->text());
$this->assertEquals("Foo\n\n\nBar", $news->text(false));
$news->text = "Foo\n[more]\nBar";
$this->assertEquals("Foo\n[more]\nBar", $news->text);
$this->assertEquals("Foo\n\nBar", $news->text());
$this->assertEquals('Foo', $news->text(false));
}
/**
* Tests that creating a News item with all fill values works.
*

Loading…
Cancel
Save