Commit graph

110 commits

Author SHA1 Message Date
Bjørn Erik Pedersen c71e1b106e all: Refactor to nonglobal file systems
Updates #2701
Fixes #2951
2017-02-04 11:37:25 +07:00
Bjørn Erik Pedersen 85c7578313 tpl: Fix broken benchmarks
But that did not explain issue #2935:

```
BenchmarkPartial-4                       200000          6452 ns/op        1040 B/op          30 allocs/op
BenchmarkPartialCached-4                 500000          4104 ns/op         544 B/op          14 allocs/op
BenchmarkPartialCachedVariants-4         500000          3398 ns/op         624 B/op          17 allocs/op
```
2017-01-14 12:39:52 +01:00
Bjørn Erik Pedersen d6000a208c all: Refactor to nonglobal template handling
Updates #2701
2017-01-10 01:36:59 +01:00
Bjørn Erik Pedersen 45e3ed517a all: Refactor to non-global logger
Note that this looks like overkill for just the logger, and that is correct,
but this will make sense once we start with the template handling etc.

Updates #2701
2017-01-07 17:06:35 +01:00
Mathias Biilmann 2989c38245 tpl: Add truncate template function
This commit adds a truncate template function for safely truncating text without
breaking words. The truncate function is HTML aware, so if the input text is a
template.HTML it will be truncated without leaving broken or unclosed HTML tags.

    {{ "this is a very long text" | truncate 10 " ..." }}
    {{ "With [Markdown](/markdown) inside." | markdownify | truncate 10 }}
2017-01-06 10:42:32 +01:00
Anthony Fok 19b6fdf2b1 tpl: Fix Unix time test case in TestDateFormat()
Fixes #2855
2017-01-03 23:43:17 +01:00
Bjørn Erik Pedersen bc060ee1c9 tpl: Update dateFormat test expectations for epoch values
As `Cast` now supports `int` inputs.
2016-12-25 14:53:34 +01:00
Tristan Rice d055862a41 tpl: Fix crash when using imageConfig
defaultImageConfigCache is now initialized statically instead of relying on it
being initialized in the reset function.

Fixes #2806
2016-12-25 13:43:50 +01:00
Cameron Moore 29caaddce6 tpl: Update title to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Cameron Moore 661d64c46a tpl: Update upper to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Cameron Moore 4e5b4ac504 tpl: Update lower to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Cameron Moore 6b8422bb35 tpl: Update hasPrefix to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Bjørn Erik Pedersen 7862de91de tpl: Add a querify test case that is actually and URL
See #2780
2016-12-13 00:16:09 +01:00
Bjørn Erik Pedersen 5b1eee44c6 tpl: Avoid repeating the same test case in TestMD5 and TesSHA* 2016-12-05 00:27:49 +01:00
digitalcraftsman 0f6c73cf2e tpl: Add sha256 template function
Fixes #2742
2016-12-04 15:03:52 +01:00
Bjørn Erik Pedersen c33eb93548 tpl: Add some missing test cases 2016-11-23 10:37:09 +01:00
Bjørn Erik Pedersen 174f97a9dd tpl: Fix spelling in test 2016-11-23 09:17:47 +01:00
Tristan Rice a49f838cd0 tpl: Add imageConfig function
Add imageConfig function which calls image.DecodeConfig and returns the height, width and color mode of the image. (#2677)

This allows for more advanced image shortcodes and templates such as those required by AMP.

layouts/shortcodes/amp-img.html
```
{{ $src := .Get "src" }}
{{ $config := imageConfig (printf "/static/%s" $src) }}

<amp-img src="{{$src}}"
           height="{{$config.Height}}"
           width="{{$config.Width}}"
           layout="responsive">
</amp-img>
```
2016-11-16 13:00:45 +01:00
Albert Nigmatzianov f21e2f25c9 all: Unify case of config variable names
All config variables starts with low-case and uses camelCase.

If there is abbreviation at the beginning of the name, the whole
abbreviation will be written in low-case.
If there is abbreviation at the end of the name, the
whole abbreviation will be written in upper-case.
For example, rssURI.
2016-10-24 20:56:00 +02:00
Bjørn Erik Pedersen a10b2cd372 Avoid reading from Viper for path and URL funcs
The gain, given the "real sites benchmark" below, is obvious:

```
benchmark           old ns/op       new ns/op       delta
BenchmarkHugo-4     14497594101     13084156335     -9.75%

benchmark           old allocs     new allocs     delta
BenchmarkHugo-4     57404335       48282002       -15.89%

benchmark           old bytes       new bytes      delta
BenchmarkHugo-4     9933505624      9721984424     -2.13%
```

Fixes #2495
2016-10-24 13:45:30 +02:00
Cameron Moore 474eb454df tpl: Add partialCached template function
Supports an optional variant string parameter so that a given partial
will be cached based upon the name+variant.

Fixes #1368
Closes #2552
2016-10-11 23:56:06 +02:00
Cameron Moore 3908489ccd tpl: Extend where to iterate over maps
Fixes #2028
2016-09-12 11:03:53 +02:00
Cameron Moore 640121423c tpl: Fix typos in tests
Closes #2370
2016-09-12 10:56:24 +02:00
Bjørn Erik Pedersen 34fe5cd34f tpl: Fix echoParam
Fixes #2406
2016-09-07 22:03:09 +03:00
Bjørn Erik Pedersen 54141f71dd Improve language handling in URLs
The current "rendering language" is needed outside of Site. This commit moves the Language type to the helpers package, and then used to get correct correct language configuration in the markdownify template func.
This commit also adds two new template funcs: relLangURL and absLangURL.

See #2309
2016-09-06 18:32:18 +03:00
Bjørn Erik Pedersen fee9ee72a6 tpl: Add missing arg to Fatalf 2016-08-20 20:52:14 +01:00
Cameron Moore 5498a1bd56 tpl: Return all errors from casting
Most non-boolean template functions should return errors.

Fixes #2354
2016-08-16 21:42:38 -05:00
Bjørn Erik Pedersen 09612f7af8 tpl: Fix faulty ordering of relURL test cases 2016-08-13 00:36:15 +02:00
Stephan Kulla 88dcbc6efa tpl: Make absURL and relURL accept anything 2016-08-13 00:31:50 +02:00
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