Skip to content

Commit

Permalink
Update documentation in README, improved FluencyMarkup rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyLundy committed Dec 19, 2023
1 parent 514d03b commit 3aae420
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 184 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Fluency for ProcessWire Changelog

## 1.0.4 2023-12-19

### Enhancement, Documentation

- Added TOC to README
- Reorganized/clarified text of README for easier reading
- Fixed speling mistakes in README
- Expanded README to include Contributing section
- Expanded README to include documentation for translating multiple strings in one call
- Expanded README to include documentation for DTO methods and helpers
- FluencyMarkup now accepts `null` for `$classes` parameter
- FluencyMarkup now removes empty HTML attributes on render
- The module method `renderLanguageLinks` now adds active class to `<li>` element containing the
current page language rather than the `<a>` element contained within it.
- When when a divider value is passed to `renderLanguageLinks`, the `<li>` element is given a
`divider` class
- Added missing parameter description to docblock for `renderLanguageLink`

## 1.0.3 2023-12-18

### Enhancement, Documentation
Expand Down
33 changes: 16 additions & 17 deletions Fluency.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,15 @@ classes: $classes,
*
* #pw-group-Page-And-Markup-Utilities
*
* @param string|array|null $classes Classes to add to <ul> element
* @param string $id ID to add to <ul> element
* @param string $divider String wrapped in <li> added between link <li> elements
* @param string $languageSource 'fluency' to render using Fluency configured languages or
* 'processwire' to render using all languages in processwire
* Default: 'fluency'
* @param string|array|null $classes Classes to add to <ul> element
* @param string $id ID to add to <ul> element
* @param string $activeClass Class added to the <li> element containing the link for the
* current page.
* @param string $divider String wrapped in <li> added between link <li> elements
* @param string $languageSource 'fluency' to render using Fluency configured languages or
* 'processwire' to render using all languages in processwire
* Default: 'fluency'
* @return string
* @throws InvalidArgumentException
*/
public function renderLanguageLinks(
string|array|null $classes = null,
Expand All @@ -588,24 +589,22 @@ public function renderLanguageLinks(
$languages = $this->getLanguagesForMarkup($languageSource);

$items = array_reduce($languages, function($tags, $language) use ($activeClass, $divider) {
$tags[] = Markup::a(
href: $this->page->localUrl($language->id),
content: $language->title,
classes: $language->isCurrentLanguage ? $activeClass : null
$tags[] = Markup::li(
classes: $language->isCurrentLanguage ? $activeClass : null,
content: Markup::a(
href: $this->page->localUrl($language->id),
content: $language->title,
)
);

$divider && $tags[] = $divider;
$divider && $tags[] = Markup::li(content: $divider, classes: 'divider');

return $tags;
}, []);

end($items) === $divider && array_pop($items);

return Markup::ul(
items: Markup::li($items),
classes: $classes ?? '',
id: $id
);
return Markup::ul(items: $items, classes: $classes ?? '', id: $id);
}

/**
Expand Down
Loading

0 comments on commit 3aae420

Please sign in to comment.