Commit graph

81 commits

Author SHA1 Message Date
digitalcraftsman
914e4d8535 tpl: Fix typo in FindRE test 2016-08-04 14:37:15 +02:00
Bjørn Erik Pedersen
93f3a85bf8 Fix the time template func test
By making it not depend on the locale setup.
2016-08-04 10:36:44 +02:00
Wade Fitzpatrick
70544f9e62 tpl: Add time template func
Fixes #2328
2016-08-04 01:55:24 +02:00
Cathal Garvey
20555b1630 Add htmlEscape and htmlUnescape template functions
These functions allow trivial escaping and unescaping of HTML entities,
and make it far easier to compose other functions for the creation of
parameterised URLs.
2016-07-19 00:14:05 +02:00
Bjørn Erik Pedersen
3564f09e3d tpl: Add humanize examples to smoke tests 2016-07-14 20:32:32 +02:00
Cathal Garvey
55a4f6e48e Do not double-escape in querify
Test case modified and expanded for querify to reflect original bug and changes.

Fixes #2279
2016-07-14 15:53:33 +02:00
Michael Orr
0a812beb12 tpl: Modify tpl.humanize to ordinalize integer input
Add logic to tpl.humanize such that it understands input of int literals
or strings which represent an integer. When tpl.humanize sees this type
of input, it will use inflect.Ordinalize as opposed to the standard
inflect.Humanize.

Fixes #1886
2016-07-13 22:09:59 +02:00
Bjørn Erik Pedersen
adf405496e Fix humanize when string is empty
Fixes #2272
2016-07-10 15:10:22 +02:00
Bjørn Erik Pedersen
39fe42cf6b Simplify querify 2016-07-06 20:57:37 +02:00
Jimmy Sawczuk
fbf48824ae tpl: Add a querify function to generate query strings inside templates
The query function will take a set of parameters specified like a dict and return a url.Values object which can be .Encode'd into a query string.

Example:

<a href="http://www.google.com?{{ (querify "q" "test" "page" 3).Encode | safeHTML }}">Search</a>

Returns:

<a href="http://www.google.com?page=3&q=test">Search</a>

Closes #2257
2016-07-05 19:52:45 +02:00
Bjørn Erik Pedersen
64817cc0d1 Fix broken template test 2016-05-09 23:18:18 +02:00
Bjørn Erik Pedersen
273a68400f Add non-string support in markdownify 2016-05-06 10:11:17 +02:00
Christopher Mancini
09038865c2 tpl: Add intersect operator to where function
Returns true if a given field value that is a slice / array of strings, integers or floats contains elements in common with the matching value. It follows the same rules as the intersect function.

Closes #1945
2016-04-28 00:58:47 +02:00
Bjørn Erik Pedersen
d48b986c45 Revert "tpl: Extend where to iterate over maps"
Committed by accident.

This reverts commit 0141a02160.
2016-04-13 19:13:33 +02:00
Cameron Moore
0141a02160 tpl: Extend where to iterate over maps
Refactor and extend where to iterate over maps.
2016-04-13 11:43:06 +02:00
digitalcraftsman
6c900380dc tpl: Add replaceRE to the "smoke tests"
Fixes #2063
2016-04-08 21:36:35 +02:00
digitalcraftsman
5bfe16ef8d tpl: Add findRE template func 2016-04-05 22:26:03 +02:00
Bjørn Erik Pedersen
f0dbf2c88f tpl: Add the other test case for hasPrefix 2016-04-03 01:59:47 +02:00
Bjørn Erik Pedersen
aaee038581 tpl: Sort the smoke tests 2016-04-03 01:57:22 +02:00
digitalcraftsman
80d02a14ab tpl: Add hasPrefix to the template funcs' "smoke test" 2016-04-03 01:30:14 +02:00
Cameron Moore
fe929114d3 tpl: Fix panic in sort of nil sequence
Properly handle a nil sequence in the sortSeq function.  Test included.
Discovered while using `range sort .Site.Data.source.Undefined "foo"`.
2016-04-02 23:06:48 +02:00
Cameron Moore
d15fda5000 tpl: Fix panic in pairList.Less
While sorting on data sources with missing fields, a panic can occur in
pairList.Less if `Interface()` is called on a invalid `reflect.Value`.
This commit detects an invalid Value and replacing it with a zero value
for the comparison.
2016-04-02 23:01:36 +02:00
Bjørn Erik Pedersen
c2277fcbc1 docs: Add doc and a test for readDir
Fixes #2009
2016-03-31 23:16:42 +02:00
Bjørn Erik Pedersen
4f66f790b1 Add readFile template func
This also includes a refactor of the hugofs package and its usage.

The motivation for that is:

The Afero filesystems are brilliant. Hugo's way of adding a dozen of global variables for the different filesystems was a mistake. In readFile (and also in some other places in Hugo today) we need a way to restrict the access inside the working dir. We could use ioutil.ReadFile and implement the path checking, checking the base path and the dots ("..") etc. But it is obviously better to use an Afero BasePathFs combined witha ReadOnlyFs. We could create a use-once-filesystem and handle the initialization ourselves, but since this is also useful to others and the initialization depends on some other global state (which would mean to create a new file system on every invocation), we might as well do it properly and encapsulate the predefined set of filesystems. This change also leads the way, if needed, to encapsulate the file systems in a struct, making it possible to have several file system sets in action at once (parallel multilanguage site building? With Moore's law and all...)

Fixes #1551
2016-03-31 21:24:18 +02:00
Bjørn Erik Pedersen
e5e1bcc271 Add plainify template function
To strip away any HTML. May be useful for the .Title in head etc.

People may shoot themself in the foot with this, maybe ...

The replacement function is pretty fast.
2016-03-21 20:27:25 -04:00
Bjørn Erik Pedersen
02e50c0126 Remove duplicate doArithmetic 2016-03-18 23:18:40 +01:00
Cameron Moore
df44b1930a tpl: Send actual values to in from intersect
The `intersect` function uses `in` to avoid adding duplicates to the
resulting set.  We were passing `reflect.Value` items when we should
have been using `Value.Interface()` to send the actual data structure.
This fixes that.

See #1952
2016-03-17 20:09:43 +01:00
Cameron Moore
b0326a1c0f tpl: Treat booleans as set in default function
Booleans and `default` don't really make sense together, so we'll always treat
booleans as "set" and return the given value.
2016-03-16 20:05:48 +01:00
Bjørn Erik Pedersen
3a2a4c3b07 tpl: Make the safeHTML and cousins accept more than strings 2016-03-14 22:27:40 +01:00
Bjørn Erik Pedersen
989c7487eb Add emojify to the template func smoke tests 2016-03-12 16:53:39 +01:00
Cameron Moore
b8d3651242 tpl: Add replaceRE function
This commit addes a `replaceRE` template function.  Regexp patterns are compiled
once and cached.
2016-03-11 19:59:18 +01:00
Cameron Moore
2d0650dbd9 tpl: Add custom index function
This commit adds a custom index template function that deviates from the stdlib
simply by not returning an "index out of range" error if an array, slice or
string index is out of range.  Instead, we just return nil values.  This should
help make the new default function more useful for Hugo users.

Fixes #1949
2016-03-10 17:47:59 +01:00
Cameron Moore
09c8c17bf0 tpl: fix default function
This commit fixes a few things:

1. `given` is now a variadic parameter so that piping works properly
2. add separate template tests to make sure piping works
3. support time values
4. add more tests of the dfault function
2016-03-10 17:47:59 +01:00
Cameron Moore
ce9ee3cf49 tpl: Add default function 2016-03-10 17:47:59 +01:00
digitalcraftsman
94c3825e5b Add md5 and sha1 template funcs 2016-03-10 11:03:06 +01:00
Bjørn Erik Pedersen
435e996c4f Add jsonify template func 2016-03-06 15:01:14 +01:00
Bjørn Erik Pedersen
d774b142e8 Make where accept slice
Fixes #1926
2016-03-06 13:15:07 +01:00
Bjørn Erik Pedersen
f6591eca35 tpl: Add some dateFormat testcases with both time and date
See #235
2016-03-03 23:17:35 +01:00
Bjørn Erik Pedersen
e85b821d3e tpl: Fix broken chomp test 2016-03-03 21:24:21 +01:00
Bjørn Erik Pedersen
f223f17c76 tpl: Make chomp return template.HTML 2016-03-03 19:45:23 +01:00
Bjørn Erik Pedersen
daaf4eb330 tpl: Add integration tests for most of the template funcs examples in doc 2016-03-03 19:35:04 +01:00
Bjørn Erik Pedersen
c1e4309516 Clean up the trim template func test 2016-02-16 00:47:14 +01:00
Bjørn Erik Pedersen
2b0fad79b7 tpl: Add two more doArithmetic test cases 2016-02-07 23:02:46 +01:00
Bjørn Erik Pedersen
f90b45f7f3 tpl: Test with nil value in first, last, after and shuffle 2016-02-07 21:16:43 +01:00
Bjørn Erik Pedersen
3cc468a82f tpl: Add missing test variants for slicestr 2016-02-07 20:14:24 +01:00
Bjørn Erik Pedersen
b3c2d90ba2 tpl: Add missing substr test variants 2016-02-07 15:22:57 +01:00
Bjørn Erik Pedersen
4dcb63c2f6 tpl: Add highlight test 2016-02-07 15:15:27 +01:00
Bjørn Erik Pedersen
0a8583a451 tpl: Add missing base64 tests 2016-02-07 14:58:23 +01:00
Bjørn Erik Pedersen
0888ddd01f tpl: Add tests for word and rune counting 2016-02-07 14:51:06 +01:00
Bjørn Erik Pedersen
ec49dbb8f5 tpl: Consolidate and complete the Inflect tests 2016-02-07 14:37:04 +01:00