Class TypographyHelper

Description

TypographyHelperクラスはタイポグラフィを手助けするヘルパーです。

  1.  class ExamplesController extends AppController {
  2.      var $helpers array('Typography');
  3.  }

Located in /typography.php (line 25)

TextHelper
   |
   --TypographyHelper
Variable Summary
Method Summary
void beforeRender ()
string horizontal (string $string, [integer $int = 2])
string mathCharacters (string $string)
string nl2brExcept (string $string, [array $except = array('pre')], [boolean $is_xhtml = true])
string nl2carriageReturn (string $string, [return $return = '↵'])
string normalizeUrl (string $string)
string normalizeUrlLink (string $string, [array $options = array()])
string oneLine (string $string)
string paragraph (string $string, [array $options = array()])
string shortenUrl (string $string, [integer $length = 50], [string $ending = null])
string specialCharacters (string $string)
string tabToScrape (string $string, [integer $multiplier = 4])
string transliteration (string $string)
string trim (string $string)
string trimExcept (string $string, [array $except = array('pre', 'script')])
string trimScrapes (string $string)
string unitCharacters (string $string)
void __replaceDecode ( $string)
void __replaceEncode ( $string, [ $except = array()])
Variables
array $helpers = array('Html') (line 32)

List of helpers used by this helper

array $mathCharacters = array(
'/([0-9.]+) ?x ?([0-9.]+)/' => '$1×$2',
'/([0-9.]+) ?X ?([0-9.]+)/' => '$1×$2',
'/([0-9.]+) ?\* ?([0-9.]+)/' => '$1×$2',
'/([0-9]+)\/([0-9]+)/' => '<sup>$1</sup>&#8260;<sub>$2</sub>',
'/([0-9.]+)\^([0-9]+)/' => '$1<sup>$2</sup>'
)
(line 60)

数学に関する記号の変換リスト

  • access: public
array $specialCharacters = array(
'(c)' => '&#169;',
'(C)' => '&#169;',
'(r)' => '&#174;',
'(R)' => '&#174;',
'(tm)' => '&#8482;',
'(TM)' => '&#8482;',
'(sm)' => '&#8480;',
'(SM)' => '&#8480;',
'(p)' => '&#8471;',
'(P)' => '&#8471;',
'...' => '&#8230;'
)
(line 40)

特別な文字の変換リスト

  • access: public
array $transliteration = array(
'/ä|æ|ǽ/' => 'ae',
'/ö|œ/' => 'oe',
'/ü/' => 'ue',
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'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ǘ|ǚ|ǜ/' => 'u',
'/Ý|Ÿ|Ŷ/' => 'Y',
'/ý|ÿ|ŷ/' => 'y',
'/Ŵ/' => 'W',
'/ŵ/' => 'w',
'/Ź|Ż|Ž/' => 'Z',
'/ź|ż|ž/' => 'z',
'/Æ|Ǽ/' => 'AE',
'/ß/'=> 'ss',
'/IJ/' => 'IJ',
'/ij/' => 'ij',
'/Œ/' => 'OE',
'/ƒ/' => 'f'
)
(line 75)

Default map of accented and special characters to ASCII characters

array $unitCharacters = array(
'/([0-9.]+) ?°C/' => '$1&#8451;',
'/([0-9.]+) ?°F/' => '$1&#8457;',
'/No. ([0-9]+)/' => '&#8470; $1',
'/([0-9]+) ?(L|l) /' => '$1 &#8467; ',
'/([0-9]+) ?(µl|µL) /' => '$1 &#13205; ',
'/([0-9]+) ?(ml|mL|ML) /' => '$1 &#13206; ',
'/([0-9]+) ?(dl|dL|DL) /' => '$1 &#13207; ',
'/([0-9]+) ?(kl|kL|KL) /' => '$1 &#13208; ',
)
(line 134)

単位に関する記号の変換リスト

  • access: public
string $_uuid = null (line 151)

UUID

  • access: protected
Methods
beforeRender (line 161)

Before render callback. beforeRender is called before the view file is rendered.

Overridden in subclasses.

  • access: public
void beforeRender ()
horizontal (line 182)

n回連続したダッシュを長いダッシュに変換します。

  1.  $typography->horizontal('-------');
  2.  
  3.  # 出力すると以下のようになります。
  4.  # ————

  • return: n回連続したダッシュが長いダッシュに変換された文字列
  • access: public
string horizontal (string $string, [integer $int = 2])
  • string $string: 処理を行う文字列
  • integer $int: 何回連続したダッシュを変換するのか
mathCharacters (line 207)

数学記号に変換します。

  1.  $typography->mathCharacters('Multiplication 100x100 Fraction 1/2');
  2.  
  3.  # 出力すると以下のようになります。
  4.  # Multiplication 100&#215;100 Fraction <sup>1</sup>&#8260;<sub>2</sub>

  • return: 数学記号に変換された文字列
  • access: public
string mathCharacters (string $string)
  • string $string: 処理を行う文字列
nl2brExcept (line 232)

基本的にはnl2brと同じ処理をしますが特定の要素内での処理は除くことができます。

  1.  $typography->nl2brExcept("foo isn't\n bar\n\n<pre>\n pre Element\n</pre>");
  2.  
  3.  # 出力すると以下のようになります。
  4.  # foo isn't<br />
  5.  #  bar<br />
  6.  # <br />
  7.  # <pre>
  8.  #  pre Element
  9.  # </pre>

  • return: 改行がbr要素に変換された文字列
  • access: public
string nl2brExcept (string $string, [array $except = array('pre')], [boolean $is_xhtml = true])
  • string $string: 入力する文字列
  • array $except: 処理を除く要素の配列
  • boolean $is_xhtml: trueの場合はXHTMLに対応した&lt;br /&gt;、falseの場合はHTMLに対応した&lt;br&gt;になります。
nl2carriageReturn (line 260)

改行の前にリターン記号を追加します。

  1.  $typography->nl2carriageReturn("foo\nbar");
  2.  
  3.  # 出力すると以下のようになります。
  4.  # foo↵
  5.  # bar

  • return: 変換された文字列
  • access: public
string nl2carriageReturn (string $string, [return $return = '↵'])
  • string $string: 処理を行う文字列
  • return $return: リターン記号
normalizeUrl (line 278)

URLを正規化します。

  1.  $typography->normalizeUrl('hxxp URL ttp://example.com/ or hxxp://example.com/example/');
  2.  
  3.  # 出力すると以下のようになります。
  4.  # hxxp URL http://example.com/ or http://example.com/example/

  • return: URLを正規化した文字列
  • access: public
string normalizeUrl (string $string)
  • string $string: 処理を行う文字列
normalizeUrlLink (line 298)

URLを正規化してリンクに変換します。

  1.  $typography->normalizeUrlLink('hxxp URL ttp://example.com/ or hxxp://example.com/example/'array('rel' => 'nofollow'));
  2.  
  3.  # 出力すると以下のようになります。
  4.  # hxxp URL <a href="http://example.com/" rel="nofollow">http://example.com/</a> or <a href="http://example.com/example/" rel="nofollow">http://example.com/example/</a>

  • return: URLを正規化してリンクに変換された文字列
  • access: public
string normalizeUrlLink (string $string, [array $options = array()])
  • string $string: 処理を行う文字列
  • array $options: Array of HTML options.
oneLine (line 424)

文字列を一行にし、2回以上連続するスペースを1つにします。

  1.  $typography->oneLine("oneLine Test.\r\nDouble Scrape  and\tTab");
  2.  
  3.  # 出力すると以下のようになります。
  4.  # oneLine Test. Double Scrape and Tab

  • return: 一行に変換された文字列
  • access: public
string oneLine (string $string)
  • string $string: 処理を行う文字列
paragraph (line 447)

改行をp要素とbr要素に変換します。

2回以上連続する改行をp要素に変換します。単一の改行はbr要素に変換します。

  1.  $typography->paragraph("paragraph method Test\r\nbr Elements\r\n\r\np Elements\r\n\r\n\r\nend.");
  2.  
  3.  # 出力すると以下のようになります。
  4.  # <p>paragraph method Test<br />
  5.  # br Elements</p><p>p Elements</p><p>end.</p>

  • return: 改行がp要素またはbr要素に変換された文字列
  • access: public
string paragraph (string $string, [array $options = array()])
  • string $string: 処理を行う文字列
  • array $options: p要素のオプション
shortenUrl (line 318)

a要素内のURLを短くします。

  1.  echo $typography->shortenUrl('The Aristotle <a href="http://ja.wikipedia.org/wiki/%E3%82%A2%E3%83%AA%E3%82%B9%E3%83%88%E3%83%86%E3%83%AC%E3%82%B9">http://ja.wikipedia.org/wiki/%E3%82%A2%E3%83%AA%E3%82%B9%E3%83%88%E3%83%86%E3%83%AC%E3%82%B9</a>'30'…');
  2.  
  3.  # 出力すると以下のようになります。
  4.  # The Aristotle <a href="http://ja.wikipedia.org/wiki/%E3%82%A2%E3%83%AA%E3%82%B9%E3%83%88%E3%83%86%E3%83%AC%E3%82%B9">http://ja.wikipedia.org/wiki/%…</a>

  • return: a要素内のURLを短くされた文字列
  • access: public
string shortenUrl (string $string, [integer $length = 50], [string $ending = null])
  • string $string: 入力する文字列
  • integer $length: 何文字まで切り詰めるか
  • string $ending: 切り詰めた後の文字列
specialCharacters (line 345)

一部の記述を記号文字へ変換します。

  1.  $typography->specialCharacters('Copyright (C) 2011 example.com All Rights Reserved.');
  2.  
  3.  # 出力すると以下のようになります。
  4.  # Copyright &#169; 2011 example.com All Rights Reserved.

  • return: 変換された文字列
  • access: public
string specialCharacters (string $string)
  • string $string: 処理を行う文字列
tabToScrape (line 491)

タブ文字をスペースに変換します。

  1.  echo $typography->tabToScrape("tabToScrape\tTest");
  2.  
  3.  # 出力すると以下のようになります。
  4.  # tabToScrape    Test

  • return: タブ文字がスペースに変換された文字列
  • access: public
string tabToScrape (string $string, [integer $multiplier = 4])
  • string $string: 処理を行う文字列
  • integer $multiplier: タブ文字をスペース何個分に変換するか
transliteration (line 502)

ASCI文字に変換します。

  • return: ASCI文字に変換された文字列
  • access: public
string transliteration (string $string)
  • string $string: 処理を行う文字列
trim (line 363)

改行やタブ文字などを消去します。

  1.  $typography->trim("<p>\r\nWelcome This is my HTML document\r\n</p>");
  2.  
  3.  # 出力すると以下のようになります。
  4.  # <p>Welcome This is my HTML document</p>

  • return: 改行やタブ文字などを消去された文字列
  • access: public
string trim (string $string)
  • string $string: 入力する文字列
trimExcept (line 384)

基本的にはtrimと同じ処理をしますが特定の要素内での処理は除くことができます。

  1.  $typography->trimExcept("<p>\r\nWelcome This is my HTML document\r\n</p>\r\n<pre>\r\n pre Element\r\n</pre>");
  2.  
  3.  # 出力すると以下のようになります。
  4.  # <p>Welcome This is my HTML document</p><pre>
  5.  #  pre Element
  6.  # </pre>

  • return: 改行やタブ文字などを消去された文字列
  • access: public
string trimExcept (string $string, [array $except = array('pre', 'script')])
  • string $string: 入力する文字列
  • array $except: 処理を除く要素の配列
trimScrapes (line 406)

2回以上連続するスペースとタブ文字を1つのスペースに変換します。

  1.  $typography->trimScrapes("Double Scrape  and\tTab");
  2.  
  3.  # 出力すると以下のようになります。
  4.  # Double Scrape and Tab

  • return: 変換された文字列
  • access: public
string trimScrapes (string $string)
  • string $string: 処理を行う文字列
unitCharacters (line 520)

単位記号に変換します。

  1.  $typography->unitCharacters('100 L 100 °C 100 °C No. 100');
  2.  
  3.  # 出力すると以下のようになります。
  4.  # 100 &#8467; 100&#8451; 100&#8451; &#8470; 100

  • return: 単位記号に変換された文字列
  • access: public
string unitCharacters (string $string)
  • string $string: 処理を行う文字列
__replaceDecode (line 547)
void __replaceDecode ( $string)
  • $string
__replaceEncode (line 524)
void __replaceEncode ( $string, [ $except = array()])
  • $string
  • $except

Documentation generated on Sat, 17 Sep 2011 04:30:04 +0000 by phpDocumentor 1.4.3