-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplural_helper.html
125 lines (116 loc) · 5.36 KB
/
plural_helper.html
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<title>Menukaarten-docs</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="assets/css/stylesheet.css" media="screen,print">
<link rel="stylesheet" href="assets/css/print.css" media="print">
<link rel="stylesheet" type="text/css" href="assets/css/shCore.css" media="screen,print">
<link rel="stylesheet" type="text/css" href="assets/css/shThemeDefault.css" media="screen,print">
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/SyntaxHighlighter.js"></script>
<script type="text/javascript" src="assets/js/build_menu.js"></script>
</head>
<body>
<div id="header-wrapper">
<div id="header">
<h1>Documentation SexyFramework</h1>
<span>Created by Vincent Bremer & Douwe de Haan</span>
</div>
</div>
<div id="container">
<div id="menu-wrapper">
<div id="menu">
<h1>Table of contents</h1>
<ul></ul>
</div>
</div>
<div id="content-wrapper">
<div id="content">
<!-- START CONTENT -->
<h1>Plural Helper</h1>
<p>The plural helper contains functions to help with pluralizing and singularizing a single word. This is used by the framework itself for retrieving corresponding models, if they exist.</p>
<h2>Patterns</h2>
<p>The class is built on a few methods which try to match the input against a set of patterns, which are stored in arrays. The methods will try to match the key to the input and returns the value. Both key and value are made up with regex so they will match to more words and not every single word has to be put into the array. From all the arrays some patterns are shown.</p>
<ul>
<h3>Pluralize patterns</h3>
<p>The keys in this array are patterns of singular words which need to be pluralized.</p>
<pre class="brush: php">
public static $plural = array(
'/(matr|vert|ind)ix|ex$/i' => "$1ices",// returns matrices from matrix
'/([^aeiouy]|qu)y$/i' => "$1ies", // returns categories from category
'/(shea|lea|loa|thie)f$/i' => "$1ves", // returns leaves from leave
'/$/' => "s" // if nothing matched, returns the input + s
);
</pre>
<h3>Singularize patterns</h3>
<p>The keys in this array are patterns of plural words which need to be singularized.</p>
<pre class="brush: php">
public static $singular = array(
'/(vert|ind)ices$/i' => "$1ex", // returns index from indeces
'/(octop|vir)i$/i' => "$1us", // returns virus from viri
'/(shoe)s$/i' => "$1", // returns shoe from shoes
'/s$/i' => "" // if nothing matched, returns the input - s
);
</pre>
<h3>Irregular patterns</h3>
<p>Sometimes there are words which cannot easily be pluralized / singularized via patterns with regex. These words are irregular and need to be included in this array.</p>
<pre class="brush: php">
public static $irregular = array(
'move' => 'moves',
'foot' => 'feet',
'goose' => 'geese',
'sex' => 'sexes',
'child' => 'children',
'man' => 'men',
'tooth' => 'teeth',
'person' => 'people'
);
</pre>
<h3>Uncountable patterns</h3>
<p>Last but not least there are words which are uncountable. There is not a singular of plural form of the word.</p>
<pre class="brush: php">
public static $uncountable = array(
'sheep',
'fish',
'deer',
'series',
'species',
'money',
'rice',
'information',
'equipment',
'compose'
);
</pre>
<h2>Methods</h2>
<p>To use these patterns easily, three methods were created to assist you in altering your words. In the second and third method, the value passed is first matched against the list of uncountable words. If there is no match, the methods try to match it against the values of the irregular list. If there is still no match, each method then matches it against the list corresponding to the method name.</p>
<h3>Demodelize</h3>
<p>The first method that could help you is the demodelize method. The value that is passed to this method will be check for the model identifier (which is '_model). If the method detects this, it will strip this part from the rest, returning the value without the '_model' part. If it does not have that part, it will return the value that it recieved.</p>
<pre class="brush: php">
plural::demodelize('user_model');
// Will return:
'user'
</pre>
<h3>Pluralize</h3>
<p>The second method that can be accessed is the pluralize method. This method uses the demodelize method so that a model name can be passed and made plural. To make it easier to use this method, a function was created called p(). This function makes a callback to the pluralize method and returns the result.</p>
<pre class="brush: php">
p('user_model');
// Will return:
'users'
</pre>
<h3>Singularize</h3>
<p>The third and last method in this class is the singularize method. This method does what it says: it takes the value it gets passed and makes it plural. Because of the fact that the word is easily written wrong, there is a function that makes a callback to the singularize method and returns the result.</p>
<pre class="brush: php">
s('users');
// Will return:
'user'
</pre>
</ul>
<!-- END CONTENT -->
</div>
</div>
</div>
<script type="text/javascript" src="assets/js/SyntaxHighlighter_settings.js"></script>
</body>
</html>