Typo fix, tests, README.md updated.
This commit is contained in:
parent
4e07dfc9bb
commit
4a11f8dd75
@ -24,6 +24,7 @@ All additional filters/tags will be registered automatically.
|
|||||||
- **[filesizeformat](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#filesizeformat)** (human-readable filesize; takes bytes as input)
|
- **[filesizeformat](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#filesizeformat)** (human-readable filesize; takes bytes as input)
|
||||||
- **[slugify](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#slugify)** (creates a slug for a given input)
|
- **[slugify](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#slugify)** (creates a slug for a given input)
|
||||||
- **truncatesentences** / **truncatesentences_html** (returns the first X sentences [like truncatechars/truncatewords]; please provide X as a parameter)
|
- **truncatesentences** / **truncatesentences_html** (returns the first X sentences [like truncatechars/truncatewords]; please provide X as a parameter)
|
||||||
|
- **random** (returns a random element of the input slice)
|
||||||
|
|
||||||
- Markup
|
- Markup
|
||||||
- **markdown**
|
- **markdown**
|
||||||
|
12
filters.go
12
filters.go
@ -222,16 +222,16 @@ func filterTruncatesentencesHTML(in *pongo2.Value, param *pongo2.Value) (*pongo2
|
|||||||
|
|
||||||
func filterRandom(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
func filterRandom(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||||
if !in.CanSlice() {
|
if !in.CanSlice() {
|
||||||
return nil, &pongo2.Error {
|
return nil, &pongo2.Error{
|
||||||
Sender: "filter:random",
|
Sender: "filter:random",
|
||||||
OrigError: error.New("input is not sliceable"),
|
OrigError: errors.New("input is not sliceable"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if in.Len() <= 0 {
|
if in.Len() <= 0 {
|
||||||
return nil, &pongo2.Error {
|
return nil, &pongo2.Error{
|
||||||
Sender: "filter:random",
|
Sender: "filter:random",
|
||||||
OrigError: error.New("input slice is empty"),
|
OrigError: errors.New("input slice is empty"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,4 +89,10 @@ func (s *TestSuite1) TestFilters(c *C) {
|
|||||||
c.Assert(getResult("{{ text|truncatesentences_html:3 }}", pongo2.Context{
|
c.Assert(getResult("{{ text|truncatesentences_html:3 }}", pongo2.Context{
|
||||||
"text": `<div class="test"><ul><li>This is a first sentence with a 4.50 number.</li><li>The second one is even more fun! Isn't it?</li><li>Last sentence, okay.</li></ul></div>`}),
|
"text": `<div class="test"><ul><li>This is a first sentence with a 4.50 number.</li><li>The second one is even more fun! Isn't it?</li><li>Last sentence, okay.</li></ul></div>`}),
|
||||||
Equals, `<div class="test"><ul><li>This is a first sentence with a 4.50 number.</li><li>The second one is even more fun! Isn't it?</li></ul></div>`)
|
Equals, `<div class="test"><ul><li>This is a first sentence with a 4.50 number.</li><li>The second one is even more fun! Isn't it?</li></ul></div>`)
|
||||||
|
|
||||||
|
// Random
|
||||||
|
c.Assert(getResult("{{ array|random }}",
|
||||||
|
pongo2.Context{"array": []int{42}}),
|
||||||
|
Equals, "42")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user