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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
Scripting functions reference
=============================
The scripting functions that puddletag supports are listed here. Use them where ever they can be used.
* For comparison functions, **0** and an empty string (**""**) evaluate to **False**. Everything else evaluates to **True**.
* Strings that contain commas must be enclode in double quotes (**"**).
* White space before and after arguments will be discarded. Enclose the argument in quotes to preserve it as in **$left(" One space.", 3)**.
.. describe:: $ceiling()
For the floating point number x.y. Returns integer x + 1.
.. describe:: $and(a, b)
Returns True if both a and b evaluate to True. Returns False otherwise.
.. describe:: $add(x,y)
Adds x and y
.. describe:: $caps(string)
Capitalizes the first letter of each word in string and converts the rest to lower case.
.. describe:: $caps2(string)
Capitalizes the first letter of each word in string and leaves all other characters unchanged.
.. describe:: $caps3(string)
Capitalizes the first letter of the string and converts the rest to lower case.
.. describe:: $ceiling(number)
Returns the smallest integer that is greater than or equal to number.
.. describe:: $char(character)
Returns the ASCII character number of the character.
.. describe:: $div(x, y)
Divides x by y.
.. describe:: $floor()
For the floating point number x.y. Returns integer x.
.. describe:: $geql(x, y)
Returns True if x >= y. False otherwise.
.. describe:: $grtr(x, y)
Returns true if x > y. False otherwise.
.. describe:: $if(x, y, z)
If x is True, y is returned, otherwise z is returned.
.. describe:: $iflonger(a,b,x,y)
If string a is longer than string b, then x is returned, otherwise y.
.. describe:: $isdigit(x)
Returns true if x is a decimal number.
.. describe:: $left(string, n)
Leftmost n characters of string.
.. describe:: $len(string)
Returns the length of string.
.. describe:: $leql(x,y)
Returns True if x <= y. False otherwise.
.. describe:: $less(x,y)
Returns True if x < y. False otherwise.
.. describe:: $lower(string)
Converts string to lowercase.
.. describe:: $meta(field, n)
If field is multiple-valued, the field's nth value. Note that it's just the field name, **field** and not **%field%**.
.. describe:: $meta_sep(field, sep=', ')
If field is multiple-valued, returns the field's values joined by sep. Otherwise just returns the field's value.
.. describe:: $mid(string,n,i)
Returns first i characters of string, starting at n.
.. describe:: $mod(x,y)
Returns the remainder of x divided by y.
.. describe:: $mul(x,y)
Multiplies x by y.
.. describe:: $neql(x,y)
Returns True if x is not equal to y.
.. describe:: $not(x)
Returns False if x evaluates to True and vice versa.
.. describe:: $num(number, y)
Pads zeroes to number until it's of length y. If number has excess zeroes and it's length is less than y then these zeroes are removed.
.. describe:: $odd(x)
Returns True if x is odd.
.. describe:: $or(x,y)
Returns True if either x or y evaluates to True. False otherwise.
.. describe:: $rand()
Generates a pseudo-random number between 0 and 1.
.. describe:: $regex(text, regex, repl, matchcase=0)
Replaces all occurrences of **regex** with **repl** in text.
| **text**: text to search, eg. *%artist%*
| **regex**: regular expression to use as the search eg. *jay\.**
| **repl**: Text to replace all matches of regex with. Can be pattern ex *$lower($1)*, but has to be quoted like in "$lower($1)" otherwise any scripting functions used will be run before the regular expression is evaluated.
| **matchcase**: Defaults to *0*. If *1*, will have case-sensitive matching.
See :ref:`replace_with_regexp` for more examples.
.. describe:: $round()
For the floating point number x.y. Returns the integer x if y < 0.5 else x + 1.
.. describe:: $replace(string, word, replaceword, matchcase, whole)
Replaces word in string with replaceword. If matchcase is true, a case-sensitive replace is done. Whole is true implies that only whole word matches are replaced.
.. describe:: $right(string, n)
Returns rightmost n characters in string.
.. describe:: $strip(string)
Removes leading and trailing whitespace from string.
.. describe:: $sub(x, y)
Subtracts y from x.
.. describe:: $to_ascii(x)
Converts all unicode chars in x to ASCII. It uses transliteration so 'abc äéç цы キウ 藏經' will become 'abc aec tsy kiu Cang Jing'. Characters that can't be converted will be removed.
.. describe:: $upper(string)
Converts string to uppercase.
.. describe:: $validate(string, y, chars)
Removes chars (defaults to **/\\\*?;"|:**) from string and replaces them with y if specified.
|