-
Notifications
You must be signed in to change notification settings - Fork 3
/
TypogrifyTwigExtension.php
88 lines (63 loc) · 2.11 KB
/
TypogrifyTwigExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Craft;
class TypogrifyTwigExtension extends \Twig_Extension
{
public function getName()
{
return Craft::t('Typogrify');
}
public function getFilters()
{
return array(
'widont' => new \Twig_Filter_Method($this, 'widontFilter'),
'amp' => new \Twig_Filter_Method($this, 'ampFilter'),
'smartypants' => new \Twig_Filter_Method($this, 'smartypantsFilter'),
'caps' => new \Twig_Filter_Method($this, 'capsFilter'),
'initial_quotes' => new \Twig_Filter_Method($this, 'initialQuotesFilter'),
'dash' => new \Twig_Filter_Method($this, 'dashFilter'),
'typogrify' => new \Twig_Filter_Method($this, 'typogrifyFilter')
);
}
public function widontFilter($str)
{
$charset = craft()->templates->getTwig()->getCharset();
$str = widont($str);
return new \Twig_Markup($str, $charset);
}
public function ampFilter($str)
{
$charset = craft()->templates->getTwig()->getCharset();
$str = amp($str);
return new \Twig_Markup($str, $charset);
}
public function smartypantsFilter($str)
{
$charset = craft()->templates->getTwig()->getCharset();
$str = Smartypants($str);
return new \Twig_Markup($str, $charset);
}
public function capsFilter($str)
{
$charset = craft()->templates->getTwig()->getCharset();
$str = caps($str);
return new \Twig_Markup($str, $charset);
}
public function initialQuotesFilter($str)
{
$charset = craft()->templates->getTwig()->getCharset();
$str = initial_quotes($str);
return new \Twig_Markup($str, $charset);
}
public function dashFilter($str)
{
$charset = craft()->templates->getTwig()->getCharset();
$str = dash($str);
return new \Twig_Markup($str, $charset);
}
public function typogrifyFilter($str)
{
$charset = craft()->templates->getTwig()->getCharset();
$str = typogrify($str);
return new \Twig_Markup($str, $charset);
}
}