Skip to content

Commit

Permalink
Merge branch 'release/1.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 21, 2018
2 parents b42c9d2 + 89a3071 commit d7e7224
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 39 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Typogrify Changelog

## 1.1.6 - 2018.01.21
### Added
* Added the `typogrifyFeed` filter/function for RSS feeds
* Added an optional `isTitle` (defauling to `false`) for the `typogrify` filter

### Changed
* Code comments/cleanup

## 1.1.5 - 2018.01.06
### Changed
* Updated to `php-typography` ^6.0.0
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ Usage:
{{ content |typogrify }}
```

Or:
```
{{ typogrify(content) }}
```

Or:

```
Expand All @@ -71,6 +76,7 @@ Or:
{{ craft.typogrify.typogrify(content) }}
```

There is also an optional second parameter `isTitle` (which defaults to `false`) to give Typogrify a hint as to whether the entity that is being passed in is a title or not. This allows it to not hyphenate titles, for instance, depending on the `set_hyphenate_headings` config setting (see below).

So what does it actually do? Well, a lot:

Expand All @@ -95,6 +101,34 @@ So what does it actually do? Well, a lot:

...and more. If you don't like the default behavior, you can enable, disable, or change any of the settings via the `config.php` file. See the **Configuring Typogrify** section for details.

For RSS feeds, there is an additional `typogrifyFeed` filter/function that applies all of the same typogrify treatments, but in a way that is appropriate for RSS (or similar) feeds — i.e. excluding processes that may cause issues in contexts with limited character set intelligence.

Usage:

```
{{ content |typogrifyFeed }}
```

Or:
```
{{ typogrifyFeed(content) }}
```

Or:

```
{% filter typogrifyFeed %}
<p>Your text here</p>
{% endfilter %}
```

Or:

```
{{ craft.typogrify.typogrifyFeed(content) }}
```

#### Advanced Usage

Should you need advanced control over Typogrify in your templates, you can use the `getPhpTypographySettings()` Twig function:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft3-typogrify",
"description": "Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more",
"type": "craft-plugin",
"version": "1.1.5",
"version": "1.1.6",
"keywords": [
"craft",
"cms",
Expand Down
128 changes: 98 additions & 30 deletions src/services/TypogrifyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Typogrify plugin for Craft CMS 3.x
*
* Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more
* Typogrify prettifies your web typography by preventing ugly quotes and
* 'widows' and more
*
* @link https://nystudio107.com/
* @copyright Copyright (c) 2017 nystudio107
Expand Down Expand Up @@ -68,17 +69,45 @@ public function init()
}

/**
* @param string $text
* Typogrify applies a veritable kitchen sink of typographic treatments to
* beautify your web typography
*
* @return string
* @param string $text The text or HTML fragment to process
* @param bool $isTitle Optional. If the HTML fragment is a title.
* Default false
*
* @return string The processed HTML
*/
public function typogrify($text, $isTitle = false)
{
if (empty($text)) {
return '';
}

$result = $this->phpTypography->process($text, $this->phpTypographySettings, $isTitle);

return $result;
}

/**
* Typogrify applies a veritable kitchen sink of typographic treatments to
* beautify your web typography but in a way that is appropriate for RSS
* (or similar) feeds -- i.e. excluding processes that may cause issues in
* contexts with limited character set intelligence.
*
* @param string $text The text or HTML fragment to process
* @param bool $isTitle Optional. If the HTML fragment is a title.
* Default false
*
* @return string The processed HTML
*/
public function typogrify($text)
public function typogrifyFeed($text, $isTitle = false)
{
if (empty($text)) {
return '';
}

$result = $this->phpTypography->process($text, $this->phpTypographySettings);
$result = $this->phpTypography->process_feed($text, $this->phpTypographySettings, $isTitle);

return $result;
}
Expand Down Expand Up @@ -146,7 +175,8 @@ public function truncateOnWord($string, $length, $substring = '…'): string

/**
* Creates a Stringy object and assigns both string and encoding properties
* the supplied values. $string is cast to a string prior to assignment, and if
* the supplied values. $string is cast to a string prior to assignment,
* and if
* $encoding is not specified, it defaults to mb_internal_encoding(). It
* then returns the initialized object. Throws an InvalidArgumentException
* if the first argument is an array or object without a __toString method.
Expand All @@ -162,15 +192,19 @@ public function stringy($string = '', $encoding = null)
}

/**
* Formats the value in bytes as a size in human readable form for example `12 KB`.
* Formats the value in bytes as a size in human readable form for example
* `12 KB`.
*
* This is the short form of [[asSize]].
*
* If [[sizeFormatBase]] is 1024, [binary prefixes](http://en.wikipedia.org/wiki/Binary_prefix)
* (e.g. kibibyte/KiB, mebibyte/MiB, ...) are used in the formatting result.
* If [[sizeFormatBase]] is 1024, [binary
* prefixes](http://en.wikipedia.org/wiki/Binary_prefix)
* (e.g. kibibyte/KiB, mebibyte/MiB, ...) are used in the formatting
* result.
*
* @param string|int|float $bytes value in bytes to be formatted.
* @param int $decimals the number of digits after the decimal point.
* @param int $decimals the number of digits after the decimal
* point.
*
* @return string the formatted result.
*/
Expand All @@ -187,15 +221,31 @@ public function humanFileSize($bytes, $decimals = 1): string
/**
* Represents the value as duration in human readable format.
*
* @param \DateInterval|string|int $value the value to be formatted. Acceptable formats:
* - [DateInterval object](http://php.net/manual/ru/class.dateinterval.php)
* - integer - number of seconds. For example: value `131` represents `2 minutes, 11 seconds`
* - ISO8601 duration format. For example, all of these values represent `1 day, 2 hours, 30 minutes` duration:
* `2015-01-01T13:00:00Z/2015-01-02T13:30:00Z` - between two datetime values
* `2015-01-01T13:00:00Z/P1D2H30M` - time interval after datetime value
* `P1D2H30M/2015-01-02T13:30:00Z` - time interval before datetime value
* `P1D2H30M` - simply a date interval
* `P-1D2H30M` - a negative date interval (`-1 day, 2 hours, 30 minutes`)
* @param \DateInterval|string|int $value the value to be formatted.
* Acceptable formats:
* - [DateInterval
* object](http://php.net/manual/ru/class.dateinterval.php)
* - integer - number of seconds.
* For example: value `131`
* represents `2 minutes, 11
* seconds`
* - ISO8601 duration format. For
* example, all of these values
* represent `1 day, 2 hours, 30
* minutes` duration:
* `2015-01-01T13:00:00Z/2015-01-02T13:30:00Z`
* - between two datetime values
* `2015-01-01T13:00:00Z/P1D2H30M` -
* time interval after datetime
* value
* `P1D2H30M/2015-01-02T13:30:00Z` -
* time interval before datetime
* value
* `P1D2H30M` - simply a date
* interval
* `P-1D2H30M` - a negative date
* interval (`-1 day, 2 hours, 30
* minutes`)
*
* @return string the formatted duration.
*/
Expand All @@ -205,25 +255,40 @@ public function humanDuration($value)
}

/**
* Formats the value as the time interval between a date and now in human readable form.
* Formats the value as the time interval between a date and now in human
* readable form.
*
* This method can be used in three different ways:
*
* 1. Using a timestamp that is relative to `now`.
* 2. Using a timestamp that is relative to the `$referenceTime`.
* 3. Using a `DateInterval` object.
*
* @param int|string|\DateTime|\DateInterval $value the value to be formatted. The following
* types of value are supported:
* @param int|string|\DateTime|\DateInterval $value the value to be
* formatted. The
* following types
* of value are
* supported:
*
* - an integer representing a UNIX timestamp
* - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php).
* The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given.
* - a string that can be [parsed to create a DateTime
* object](http://php.net/manual/en/datetime.formats.php). The timestamp is
* assumed to be in [[defaultTimeZone]] unless a time zone is explicitly
* given.
* - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
* - a PHP DateInterval object (a positive time interval will refer to the past, a negative one to the future)
* - a PHP DateInterval object (a positive time interval will refer to the
* past, a negative one to the future)
*
* @param int|string|\DateTime $referenceTime if specified the value is used as a reference time instead of `now`
* when `$value` is not a `DateInterval` object.
* @param int|string|\DateTime $referenceTime if specified
* the value is
* used as a
* reference time
* instead of
* `now` when
* `$value` is not
* a
* `DateInterval`
* object.
*
* @return string the formatted result.
*/
Expand All @@ -247,7 +312,8 @@ public function ordinalize(int $number): string

/**
* Converts a word to its plural form
* For example, 'apple' will become 'apples', and 'child' will become 'children'
* For example, 'apple' will become 'apples', and 'child' will become
* 'children'
*
* @param string $word
* @param int $number
Expand All @@ -261,7 +327,8 @@ public function pluralize(string $word, int $number = 2): string

/**
* Converts a word to its singular form
* For example, 'apples' will become 'apple', and 'children' will become 'child'
* For example, 'apples' will become 'apple', and 'children' will become
* 'child'
*
* @param string $word
* @param int $number
Expand All @@ -276,7 +343,8 @@ public function singularize(string $word, int $number = 1): string
/**
* Returns transliterated version of a string
* For example, 获取到 どちら Українська: ґ,є, Српска: ђ, њ, џ! ¿Español?
* will be transliterated to huo qu dao dochira Ukrainsʹka: g,e, Srpska: d, n, d! ¿Espanol?
* will be transliterated to huo qu dao dochira Ukrainsʹka: g,e, Srpska: d,
* n, d! ¿Espanol?
*
* @param string $string
* @param null $transliterator
Expand Down
31 changes: 27 additions & 4 deletions src/twigextensions/TypogrifyTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getFilters()
{
return [
new \Twig_SimpleFilter('typogrify', [$this, 'typogrify']),
new \Twig_SimpleFilter('typogrifyFeed', [$this, 'typogrifyFeed']),
new \Twig_SimpleFilter('smartypants', [$this, 'smartypants']),
new \Twig_SimpleFilter('truncate', [$this, 'truncate']),
new \Twig_SimpleFilter('truncateOnWord', [$this, 'truncateOnWord']),
Expand All @@ -62,6 +63,7 @@ public function getFunctions()
{
return [
new \Twig_SimpleFunction('typogrify', [$this, 'typogrify']),
new \Twig_SimpleFunction('typogrifyFeed', [$this, 'typogrifyFeed']),
new \Twig_SimpleFunction('smartypants', [$this, 'smartypants']),
new \Twig_SimpleFunction('getPhpTypography', [$this, 'getPhpTypography']),
new \Twig_SimpleFunction('truncate', [$this, 'truncate']),
Expand All @@ -78,14 +80,35 @@ public function getFunctions()
}

/**
* @param string $text
* Typogrify applies a veritable kitchen sink of typographic treatments to
* beautify your web typography
*
* @return \Twig_Markup
* @param string $text The text or HTML fragment to process
* @param bool $isTitle Optional. If the HTML fragment is a title.
* Default false
*
* @return string The processed HTML
*/
public function typogrify($text, $isTitle = false)
{
return Template::raw(Typogrify::$plugin->typogrify->typogrify($text, $isTitle));
}

/**
* Typogrify applies a veritable kitchen sink of typographic treatments to
* beautify your web typography but in a way that is appropriate for RSS
* (or similar) feeds -- i.e. excluding processes that may cause issues in
* contexts with limited character set intelligence.
*
* @param string $text The text or HTML fragment to process
* @param bool $isTitle Optional. If the HTML fragment is a title.
* Default false
*
* @return string The processed HTML
*/
public function typogrify($text)
public function typogrifyFeed($text, $isTitle = false)
{
return Template::raw(Typogrify::$plugin->typogrify->typogrify($text));
return Template::raw(Typogrify::$plugin->typogrify->typogrifyFeed($text, $isTitle));
}

/**
Expand Down
29 changes: 25 additions & 4 deletions src/variables/TypogrifyVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,35 @@ class TypogrifyVariable
// =========================================================================

/**
* @param string $text
* Typogrify applies a veritable kitchen sink of typographic treatments to
* beautify your web typography
*
* @return \Twig_Markup
* @param string $text The text or HTML fragment to process
* @param bool $isTitle Optional. If the HTML fragment is a title.
* Default false
*
* @return string The processed HTML
*/
public function typogrify($text, $isTitle = false)
{
return Template::raw(Typogrify::$plugin->typogrify->typogrify($text, $isTitle));
}

/**
* Typogrify applies a veritable kitchen sink of typographic treatments to
* beautify your web typography but in a way that is appropriate for RSS
* (or similar) feeds -- i.e. excluding processes that may cause issues in
* contexts with limited character set intelligence.
*
* @param string $text The text or HTML fragment to process
* @param bool $isTitle Optional. If the HTML fragment is a title.
* Default false
*
* @return string The processed HTML
*/
public function typogrify($text)
public function typogrifyFeed($text, $isTitle = false)
{
return Template::raw(Typogrify::$plugin->typogrify->typogrify($text));
return Template::raw(Typogrify::$plugin->typogrify->typogrifyFeed($text, $isTitle));
}

/**
Expand Down

0 comments on commit d7e7224

Please sign in to comment.