Commit graph

45 commits

Author SHA1 Message Date
Bjørn Erik Pedersen e8ca52e93a Add one more temporary template test for linux/arm
See #1771
2016-01-13 14:26:25 +01:00
Bjørn Erik Pedersen bca2d38e52 Add temporary template test for linux/arm
See #1771
2016-01-13 14:10:14 +01:00
Anthony Fok 8509727fe8 Add copyright header to that source files that don’t have one.
See #1646
2015-12-10 15:19:38 -07:00
bep e4ed9d6b02 Add some Ace test cases
See #1178
2015-05-31 13:13:28 +02: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 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 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 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
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
bep 4784b63eeb Add test cases for Ne and Eq type normalisation
See #961
2015-03-09 15:52:32 +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 420c9e4d3d Add writable context to Node
The variable scope in the Go templates makes it hard, if possible at all, to write templates with counter variables or similar state.

This commit fixes that by adding a writable context to Node, backed by a map: Scratch.

This context has three methods, Get, Set and Add. The Add is tailored for counter variables, but can be used for any built-in numeric values or strings.
2015-01-31 22:01:30 +01:00
Tatsushi Demachi 37490ee27a Add dateFormat template function
This is the implementation of the proposal at #235 and
http://discuss.gohugo.io/t/parsing-dates-in-templates/603/3
2015-01-22 00:08:30 +01:00
bep d897b1e8a7 Add missing assertion to trim-test 2015-01-20 22:31:05 +01:00
bep 1b91fec0ac Add tests for IsSet 2015-01-20 17:15:12 +01:00
bep f77f2a9b40 Refactor TestGt to also include Lt, Ge, Le, Eq and Ne 2015-01-20 16:38:23 +01:00
bep f470cf9590 Add tests for Apply 2015-01-20 14:24:43 +01:00
bep 077d726b51 Replace regexp based Chomp with builtin TrimRight 2015-01-20 12:41:08 +01:00
bep 99aee30410 Add tests for Replace 2015-01-20 12:30:49 +01:00
bep 26856c3b75 Add tests for Trim 2015-01-20 12:23:27 +01:00
bep a6bf6f52ce Add tests for Chomp 2015-01-20 12:07:49 +01:00
Anthony Fok 724cc0ddff Add safeUrl; disable safeHtmlAttr; rename safeCSS to safeCss
- Add `safeUrl` template function (Fixes #347)
- Add TestSafeUrl() fashioned after @tatsushid great examples
- Disable `safeHtmlAttr` pending further discussions on its other
  use cases because `safeUrl` is a cleaner solution to #347.
  (There are also `safeJs` and `safeJsStr` that we could implement
  if there are legitimate demands for them.)
- Rename `safeCSS` to `safeCss` (to follow the convention of `safeHtml`)
- Add/expand documentation on `safeHtml`, `safeCss` and `safeUrl`
2015-01-19 23:41:22 -07:00
Tatsushi Demachi f5946ea3dd Add SafeHtmlAttr, SafeCSS template function
This allows a template user to keep a safe HTML attribute or CSS string
as is in a template.

This is implementation of @anthonyfok great insight

Fix #784, #347
2015-01-19 19:47:37 -07:00
Tatsushi Demachi d12f6cd775 Fix echoParam template function to accept string key name
This changes `echoParam` template function behavior to accept not only
an array or a slice and its index pair but also a map and its key pair.

This also changes the function that float and uint values are treated as
a valid result type of it.

Fix #771
2015-01-08 02:32:17 +01:00
Tatsushi Demachi 0d17ee7ed4 Add operator argument to where template function
It allows to use `where` template function like SQL `where` clause.
For example,

    {{ range where .Data.Pages "Type" "!=" "post" }}
        {{ .Content }}
    {{ end }}

Now these operators are implemented:

    =, ==, eq, !=, <>, ne, >=, ge, >, gt, <=, le, <, lt, in, not in

It also fixes `TestWhere` more readable
2015-01-04 12:15:17 +01:00
Tatsushi Demachi 975f4cf126 Refactor tpl codes
- Use indirect function instead of the same code copies
- Fix missing arguments of some test codes
2014-12-29 15:47:50 +01:00
Tatsushi Demachi fa8ac87d5e Make 'where' template function accepts dot chaining key argument
'where' template function used to accept only each element's struct
field name, method name and map key name as its second argument. This
extends it to accept dot chaining key like 'Params.foo.bar' as the
argument. It evaluates sub elements of each array elements and checks it
matches the third argument value.

Typical use case would be for filtering Pages by user defined front
matter value. For example, to filter pages which have 'Params.foo.bar'
and its value is 'baz', it is used like

    {{ range where .Data.Pages "Params.foo.bar" "baz" }}
        {{ .Content }}
    {{ end }}

It ignores all leading and trailing dots so it can also be used with
".Params.foo.bar"
2014-12-29 12:53:41 +01:00
Derek Perkins 717f702e2f Added delimit & sort template functions, tests and docs 2014-12-18 22:28:12 -05:00
bep 53c707bb1d Add markdownify template filter
Note that this is a Markdownify filter, and is named as such; it's not a Asccidoc filter or in any way connected to a Page.

Fixes #524
2014-11-24 23:17:25 -05:00
spf13 73f203ad86 Move template library into it's own package (tpl). No longer dependent on hugolib. Can be used externally. 2014-11-20 12:36:57 -05:00
Renamed from hugolib/template_test.go (Browse further)