diff --git a/app/Actions/TagClassGenerator.php b/app/Actions/TagClassGenerator.php new file mode 100644 index 000000000..997ace838 --- /dev/null +++ b/app/Actions/TagClassGenerator.php @@ -0,0 +1,50 @@ +tags = $tags; + } + + /** + * @return string[] + */ + public function generate(): array + { + $classes = []; + + foreach ($this->tags as $tag) { + $name = $this->normalizeTagClassString($tag->name); + $value = $this->normalizeTagClassString($tag->value); + $classes[] = 'tag-name-' . $name; + if ($value) { + $classes[] = 'tag-value-' . $value; + $classes[] = 'tag-pair-' . $name . '-' . $value; + } + } + + return array_unique($classes); + } + + public function generateAsString(): string + { + return implode(' ', $this->generate()); + } + + protected function normalizeTagClassString(string $value): string + { + $value = str_replace(' ', '', strtolower($value)); + $value = str_replace('-', '', strtolower($value)); + return $value; + } + +} \ No newline at end of file diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php index e0cb4b862..03801f9a5 100644 --- a/resources/views/books/show.blade.php +++ b/resources/views/books/show.blade.php @@ -13,6 +13,8 @@ @endif @endpush +@include('entities.body-tag-classes', ['entity' => $book]) + @section('body')
diff --git a/resources/views/chapters/show.blade.php b/resources/views/chapters/show.blade.php index 8a86900fb..a7b90ceef 100644 --- a/resources/views/chapters/show.blade.php +++ b/resources/views/chapters/show.blade.php @@ -10,6 +10,8 @@ @endpush +@include('entities.body-tag-classes', ['entity' => $chapter]) + @section('body')