Commit graph

74 commits

Author SHA1 Message Date
digitalcraftsman
5bfe16ef8d tpl: Add findRE template func 2016-04-05 22:26:03 +02:00
digitalcraftsman
4502c4e3ae docs: Add documentation for hasPrefix template func
Fixes #2039
2016-04-03 00:44:43 +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
digitalcraftsman
93e41a1fb2 docs: Fix typo in templates/functions.md 2016-03-28 17:04:29 +02:00
Robert Basic
50506ebeac docs: Document the split function
Fixes #1997
2016-03-28 15:58:41 +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
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
digitalcraftsman
b5c718a4de docs: Fix typos in functions.md and contributing.md 2016-03-16 13:04:41 +01:00
Bjørn Erik Pedersen
cafb784799 Add emoji support
This uses the Emoji map from https://github.com/kyokomi/emoji -- but with a custom replacement implementation.

The built-in are fine for most use cases, but in Hugo we do care about pure speed.

The benchmarks below are skewed in Hugo's direction as the source and result is a byte slice,
Kyokomi's implementation works best with strings.

Curious: The easy-to-use `strings.Replacer` is also plenty fast.

```
BenchmarkEmojiKyokomiFprint-4  	   20000	     86038 ns/op	   33960 B/op	     117 allocs/op
BenchmarkEmojiKyokomiSprint-4  	   20000	     83252 ns/op	   38232 B/op	     122 allocs/op
BenchmarkEmojiStringsReplacer-4	  100000	     21092 ns/op	   17248 B/op	      25 allocs/op
BenchmarkHugoEmoji-4           	  500000	      5728 ns/op	     624 B/op	      13 allocs/op
```

Fixes #1891
2016-03-11 15:51:37 -06: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
f3f9763afd tpl: Add time note to default func description 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
0743646f32 docs: add better default example 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
digitalcraftsman
c1f8b188f7 Add template function slice 2016-02-27 17:04:45 +01:00
Thijs de Zoute
d607f4c7df Docs: fix small typos in functions.md 2016-02-24 19:14:04 +01:00
Cameron Moore
45df4596bb tpl: Add humanize func and cleanup lint
Add humanize (inflect.Humanize) to the template funcMap.  Documentation and
tests are included.

Various code cleanups of the template funcs:

- Break pluralize and singularize out into stand-alone funcs.
- Sort the list of funcMap entries.
- Add some minimal godoc comments to all public funcs.
- Fix some issues found by golint and grind.
2016-02-06 15:31:25 +01:00
Bjørn Erik Pedersen
58a183c330 Docs: Add doc for string and int 2016-01-16 00:06:32 +01:00
Bjørn Erik Pedersen
01f71babfc docs: Add lastmod to content files
Based on last commit in Git.
2016-01-06 23:55:18 +01:00
digitalcraftsman
dfa34afd86 Add template funcs countwords and countrunes 2016-01-02 11:00:03 -05:00
Anthony Fok
cb8f459127 Docs: Add nohighlight shortcode and improve formatting
And some random formatting and copyediting fixes.

See also #1708
2015-12-23 09:31:07 -07:00
Maxime Michel
38c5db98b5 Added a missing closing tag 2015-12-11 10:51:17 -07:00
Gustav Näslund
b0b6a8c7ac Use .Site.Pages in the documentation examples instead of .Site.Recent 2015-11-30 23:31:18 -07:00
Anthony Fok
e59aabcf46 docs: Change "Github" to "GitHub" 2015-11-20 14:24:22 -07:00
digitalcraftsman
a5bd101d27 Docs: fix typo in template function section 2015-11-20 13:30:27 -07:00
Cameron Moore
c5a4c07b89 Add SafeJS template function
This commit adds a SafeJS template function.  Tests and documentation are
included.

Fixes #1579
2015-11-20 21:12:01 +01:00
Tobias
4e9a5d8bd1 Fix some typos in docs 2015-10-17 13:48:10 +02:00
NotZippy
3a27cefec1 Add dictionary function to be passed into a template
Allows templates to dynamically build maps.

Example usage: Creating and passing a map to a subtemplate while in a range on the parent.
2015-10-09 18:29:16 +02:00
digitalcraftsman
79f8bb625d Add base64Decode and base64Encode template functions
Fixes #1416
2015-09-25 21:31:55 +02:00
Bjørn Erik Pedersen
82f770a6f5 Remove superfluous g in docs 2015-09-23 09:18:20 +02:00
Bjørn Erik Pedersen
06caa025a4 Fix typo in docs
See #1438
2015-09-22 22:33:41 +02:00
Bjørn Erik Pedersen
8d695ec592 Add singularize template func
See #1438
2015-09-22 22:31:02 +02:00
Bjørn Erik Pedersen
751d4906ef Add pluralize template func
Fixes #1438
2015-09-22 22:25:25 +02:00
Benny Wu
d313bc78a4 Documentation update on Template Where Function for nil 2015-08-13 23:05:10 +02:00
Anthony Fok
5505ac0d72 doc: Strip trailing whitespace; other revisions
Make some random and non-comprehensive changes to the
template functions documentation to make them more
consistent.
2015-08-04 12:00:08 -06:00
Ariejan de Vroom
cc9536ec46 Update docs for last template function 2015-06-15 21:18:38 +02:00
Ariejan de Vroom
40a92a062d Add after to template function documentation 2015-06-15 21:18:38 +02:00
bep
be778c3160 docs: some more on absURL, relURL 2015-05-22 23:43:02 +02:00
bep
be1366074c docs: add doc for substr
Fixes #1156
2015-05-22 22:36:25 +02:00
bep
be4376a022 docs: add doc for slicestr
See #1156
2015-05-22 22:20:45 +02:00
bep
be2e08c4ad docs: add doc for seq
See #1156
2015-05-22 22:17:41 +02:00
Jeff Ramnani
7125103b1e Add ".Render" to the list of functions.
Fixes: #1153
2015-05-22 19:38:01 +02:00
bep
be82355570 Add doc for absURL and relURL
Also group URL related functions in doc.
2015-05-11 19:09:04 +02:00
bep
be4f48652d Add ToC to long pages
* A compact, fixed box in the right screen
* Only for big screens, > 1200 px wide
2015-05-11 18:39:42 +02:00
mdhender
42dcaabf4f Document getenv template function
Add `getenv` to the template function documentation.
2015-04-05 18:14:40 +02:00
mdhender
6b50c8fb82 Sort function names in templates documentation
The documentation on the functions is long.  It is easier to find
a function name when they are sorted within the sections.

Fixes #981
2015-04-04 23:30:08 +02:00
Anthony Fok
b3bd71fec9 Update Hugo docs with the initialisms suggested by golint
In particular:

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

Continued effort in fixing #959.
2015-03-18 11:30:37 +01:00