Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Providing a hyphenate field method #7

Open
fvsch opened this issue May 26, 2016 · 2 comments
Open

Providing a hyphenate field method #7

fvsch opened this issue May 26, 2016 · 2 comments
Assignees
Milestone

Comments

@fvsch
Copy link

fvsch commented May 26, 2016

Would this plugin be able provide a $field->hyphenate($lang) method, without major refactoring?

As argued in #6, hyphenation is a design choice. And I'll add that a designer or client may want hyphenation for some texts (e.g. an article's body) but not for others (e.g. a big title).

What might serve this use case:

<article>
  <header>
    <h1><?php echo $page->title()->smartypants(); ?></h1>
  </header>
  <div class="article-body">
    <?php echo $page->text()->kirbytext()->hyphenate(); ?>
  </div>
</article>
@fabianmichael fabianmichael added this to the 1.1 milestone May 26, 2016
@fabianmichael
Copy link
Owner

fabianmichael commented May 26, 2016

Hi again :-)

This is really one of the features, which is harder to implement, because PHP-Typography is meant to be given a string, where features are applied to. The only possibility to do this, would be to create a new instance of PHP-Typography and then apply everything to it. It is also possible to clone the current instance of the class and change all settings. With the current codebase, this is very hard to realize.

But it should be possible to use both Smartypants an Kirby-Typography in the same template without too many changes. It also seems to be possible to override built-in field methods. With that in mind, it would be possible to override the default settings for every call to field->kirbytext() with an additional parameter or provide methods like unhyphenate(), where a simple str_replace() coudl remove all &shy; characters from the text. Custom options for Kirbytext could be a really interesting way how to do it. I could also think of providing a field->typography() method for custom configuration instead. I will think about that, but to 1.0.0, I would prefer to get rid of current bugs and leave all new features and APIs out of the initial release. Added it to the 1.1 milestone.

echo $page->text()->kirbytext([
  'typography.hyphenation' => false,
  'typography.hyphenation.minlength' => 10,
]);

or:

echo $page->text()->kirbytext()->typography([
  'hyphenation' => false,
  'hyphenation.minlength' => 10,
]);

@mundschenk-at
Copy link

You can set PHP_Typography->settings['hyphenateTitle'] to false and call PHP_Typography::process with $isTitle set to true to achieve that effect.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants