Commit graph

104 commits

Author SHA1 Message Date
Ariejan de Vroom 0a2e5424ab Add last template function
`last` allows the user to select the last X items of
and array.
2015-06-15 21:18:38 +02:00
Ariejan de Vroom 627d016cc9 Refactor var name limit to index 2015-06-15 21:18:38 +02:00
Ariejan de Vroom c335efdd06 Add after template function
Where `first` will return the first N items of a rangeable list,
`after` will return all items after the Nth item.

This allows the user to do something with the first N items and
something different with the remaining items after N.
2015-06-15 21:18:38 +02:00
Tatsushi Demachi 51cabe6faf Fix substr tpl func's int type variant issue
`substr` template function takes one or two range arguments. Both
arguments must be int type values but if it is used with a calclation
function e.g. `add`, `len` etc, it causes a wrong type error.

This fixes the issue to allow the function to take other integer type
variant like `int64` etc.

This also includes a small fix on no range argument case.

Fix #1190
2015-06-06 21:03:30 +02:00
Cyrill Schumacher cc5d63c37a GetJSON/GetCSV: Add retry on invalid content
The retry gets triggered when the parsing of the content fails.

Fixes #1166
2015-06-01 12:05:16 +02:00
bep be0314b1d5 Fix Windows Ace path issue
Ace doesn't like Windows style filepath separators.

Fixes #1178
2015-05-31 13:13:21 +02:00
bep e4ed9d6b02 Add some Ace test cases
See #1178
2015-05-31 13:13:28 +02:00
bep be45399cba Extract Ace handling to a method
To prepare for some testing.

See #1178
2015-05-29 11:31:26 +02:00
Tatsushi Demachi 601a2ce124 Add time.Time type support to where tpl func
`where` tpl function doesn't support `time.Time` type so if people want
to compare such values, it's required that these values are converted
into `int` and compare them.

This improves it. If `time.Time` values are passed to `where`, it
converts them into `int` internally, compares them and returns the
result.

See also
http://discuss.gohugo.io/t/future-posts-and-past-posts/1229/3
2015-05-26 15:59:36 +02:00
bep befb54da46 Apply gofmt -s 2015-05-25 12:54:13 +02:00
Juan B. Rodriguez d0a4645a34 Set s.Info.LastChange to Lastmod
Set sitemap.xml <lastmod> field to Lastmod.

See #733
2015-05-15 13:10:11 +02:00
bep bec839e652 Add relURL template func
Fixes #1126
2015-05-11 13:59:02 +02:00
bep be0cbeee7f Add absURL template func
Fixes #1106
2015-05-11 12:28:35 +02:00
bep a52e508d46 Update test logs for uniformity and consistency
Many minor fixes to make test logs more consistent and correct a
mispelling.

Standardize on "[%i] got X but expected Y" for log messages. Using
a consistent layout makes it easier to read the test results. This
was mostly changing "Got" to "got". Swapped the order of values on
several calls to bring them in line with the convention.

A few log messages had a sequence number added to identify the
exact scenario that failed. Otherwise, there would be no way to
ascertain which failed When there are many scenarios.

Correct spelling of "expected."

Fixes #1028
Merged be2097e1ad

[close #1040]
2015-05-08 22:27:00 -04:00
bep be6482603e Disable faulty range validation in apply
Fixed #1098
2015-05-02 11:32:28 +02:00
bep be15927819 tpl: check that types in args match the target func's type
Fixes #1095
2015-05-01 17:00:34 +02:00
bep be7b830f33 tpl: add sanity check to prevent panic in seq on big nums
Fixes #1092
2015-04-30 13:25:46 +02:00
bep be190fdb0d tpl: check for too many arguments in apply
Fixes #1091
2015-04-30 11:41:27 +02:00
bep be017f187e tpl: check slice bounds in slicestr
Fixes #1090
2015-04-30 11:26:45 +02:00
bep be3b8a132b tpl: avoid panic on too few args to apply
Fixes #1089
2015-04-30 10:51:10 +02:00
bep beff680534 Expand the ACE base template lookup pattern
The previous implementation didn't easily support the use case "I want one base template for the single pages, another for the rest".

The new lookup order is:

1. <current-path>/<template-name>-baseof.ace, e.g. list-baseof.ace
2. <current-path>/baseof.ace
3. _default/<template-name>-baseof.ace, e.g. list-baseof.ace.
4. _default/baseof.ace
2015-04-18 13:58:20 +02:00
bep bee52f85ae Fix broken Highlight test 2015-04-16 02:20:10 +02:00
bep be24457acf Add more options to highlight
Fixes #1021
2015-04-15 20:31:06 +02:00
bep be2097e1ad tpl: split template.go
The template funcs get their own file. This prevents having to scroll miles to get to the template infrastructure.
2015-04-05 21:03:12 +02:00
bep be627fa718 Remove paragraph tags produced by markdownify
Fixes #1025
2015-04-01 15:40:09 +02:00
bep be6696c34b Handle views in combo with Ace base templates
As views looks like a regular template, but doesn't need a base template, we have to look inside it.

Altough really not needed by this commit, reading the full file content into memory just to do a substring search is a waste.
So this commit implements a `ReaderContains` func that in most cases should be much faster than doing an `ioutil.ReadAll` and `bytes.Contains`:

```
benchmark                   old ns/op     new ns/op     delta
BenchmarkReaderContains     78452         20260         -74.18%

benchmark                   old allocs     new allocs     delta
BenchmarkReaderContains     46             20             -56.52%

benchmark                   old bytes     new bytes     delta
BenchmarkReaderContains     46496         1258          -97.29%
```

Fixes #999
2015-03-29 21:12:13 +02:00
bep be8c067577 Add support for Ace base and inner templates
Fixes #994
Fixes #511
2015-03-26 17:22:35 +01:00
bep be84f93716 Change to variadic int args in Slicestr
Makes for a better template api.
2015-03-23 19:17:55 +01:00
Anthony Fok 5b0245ca59 Implement substr template function
Its behavior is similar to that in JavaScript
with special handling of negative length as found in in PHP.

Fixes #991
2015-03-23 18:56:58 +01:00
bep beb423a2d9 Rename Slice to Slicestr
Fixes #990
2015-03-23 16:24:15 +01:00
bep be82b5a94f Polish Slice doc 2015-03-23 12:42:54 +01:00
bep be19f4eb91 Rename Substr to Slice
That is whas was implemented, not Substr.

Also make the API more similar to Go's internal slice by making both the start and end indices optional.

See #990
2015-03-23 12:18:27 +01:00
bep be4fe8f8af Polish Substr and Split tests 2015-03-22 13:52:22 +01:00
Xin Fan 04817c7b83 Add Substr and Split template functions
Both of these can take any type the cast lib can turn into a string.
2015-03-22 13:24:47 +01:00
bep a8bfaba081 template: add some missing test cases for First 2015-03-18 20:47:10 +01:00
Anthony Fok 8b8fb417ae More initialism corrections (golint)
Thanks to @bep's new, brilliant helpers.Deprecated() function,
the following functions or variables are transitioned to their
new names, preserving backward compatibility for v0.14
and warning the user of upcoming obsolescence in v0.15:

 * .Url → .URL (for node, menu and paginator)
 * .Site.BaseUrl → .Site.BaseURL
 * .Site.Indexes → .Site.Taxonomies
 * .Site.Recent → .Site.Pages
 * getJson → getJSON
 * getCsv → getCSV
 * safeHtml → safeHTML
 * safeCss → safeCSS
 * safeUrl → safeURL

Also fix related initialisms in strings and comments.

Continued effort in fixing #959.
2015-03-18 11:30:37 +01:00
quoha a044734541 Add "getenv" as an wrapper for os.Getenv
Add a wrapper for the os.Getenv function. The
wrapper takes as input a string that is assumed to be an exported
variable name.

Fixes #977
2015-03-16 18:38:43 +01:00
bep 27ed49e532 Revert "Added image support to the sitemap.xml template"
This reverts commit 3c147bd419.

Fixes #972
2015-03-14 00:03:34 +01:00
Derek Perkins 3c147bd419 Added image support to the sitemap.xml template
Conflicts:
	tpl/template_embedded.go
2015-03-12 22:13:42 -04:00
bep 0be2aade99 Add Seq template func
Very similar to GNU's seq.

Fixes #552

Conflicts:
	tpl/template.go
2015-03-12 22:08:36 -04:00
Anthony Fok 67df33f500 Correct initialisms as suggested by golint
First step to use initialisms that golint suggests,
for example:

    Line 116: func GetHtmlRenderer should be GetHTMLRenderer

as see on http://goreportcard.com/report/spf13/hugo

Thanks to @bep for the idea!

Note that command-line flags (cobra and pflag)
as well as struct fields like .BaseUrl and .Url
that are used in Go HTML templates need more work
to maintain backward-compatibility, and thus
are NOT yet dealt with in this commit.

First step in fixing #959.
2015-03-11 21:55:00 +01:00
bep 00f07c5374 doArithmetic: add test for division by zero 2015-03-11 10:25:53 +01:00
bep 43742e0277 Add some basic tests for doArithmetic
We might have to take precision into account for floating point nubers ... at some point.
2015-03-11 01:30:41 +01:00
Anthony Fok 3ba279c2e5 Do not parse backup files with trailing '~' as templates
Fixes #964
2015-03-10 10:18:40 -06:00
bep 4784b63eeb Add test cases for Ne and Eq type normalisation
See #961
2015-03-09 15:52:32 +01:00
Tatsushi Demachi 44cdb37b03 Fix eq and ne tpl function issue
`eq` and `ne` template functions don't work as expected when those are
used with a raw number and a calculated value by add, sub etc. It's
caused by both numbers type differences. For example, `eq 5 (add 2 3)`
returns `false` because raw 5 is `int` while `add 2 3` returns 5 with
`int64`

This normalizes `int`, `uint` and `float` type values to `int64`,
`uint64` and `float64` before comparing them. Other type of value is
passed to comparing function without any changes.

Fix #961
2015-03-09 15:28:31 +01:00
bep 103ea842f8 Fix errors reported by Go Vet 2015-03-06 15:25:19 +01:00
bep 6e1b0e0c00 Apply gofmt -s 2015-03-05 23:57:38 +01:00
bep f0c8585b50 Use $.Paginator in template
Since there will only be one paginator per page, this can get rid of some scoping confusion.
2015-02-19 11:36:09 +01:00
René Jochum d2e022f2a7 Suppress errors for symbolic links witch point to a file. 2015-02-17 19:18:28 -08:00