diff options
author | Paul Duncan <pabs@pablotron.org> | 2018-09-09 11:02:08 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2018-09-09 11:02:08 -0400 |
commit | c0f4d9a505ab1a94e6b0993582c9827f5a681e05 (patch) | |
tree | 250ed30d37b8a775153acfd5514dd76229a1f1fb /js/README.mkd | |
parent | b4e1f4906a27619b3edffd791361694f00f38662 (diff) | |
download | luigi-template-c0f4d9a505ab1a94e6b0993582c9827f5a681e05.tar.bz2 luigi-template-c0f4d9a505ab1a94e6b0993582c9827f5a681e05.zip |
js: add to Usage, fix cache test, add support for cache custom filters
Diffstat (limited to 'js/README.mkd')
-rw-r--r-- | js/README.mkd | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/js/README.mkd b/js/README.mkd index 9f3e5e6..63d50e9 100644 --- a/js/README.mkd +++ b/js/README.mkd @@ -63,17 +63,8 @@ The built-in templates are: * `uc`: Upper-case string. * `lc`: Lower-case string. -* `s`: Returns `""` if the value is 1, and `"s"` otherwise. Used to - pluralize values. Example: - - console.log(LuigiTemplate.run('a: a%{a|s}, b: b%{b|s}, c: c%{c|s}'', { - a: 0, - b: 1, - c: 2, - })); - - // prints "a: as, b: b, c: cs" - +* `s`: Pluralize a value by returning `""` if the value is 1, and + `"s"` otherwise. * `length`: Get the length of an array. * `trim`: Trim leading and trailing whitespace from a string. * `h`: HTML-escape a string value. @@ -100,8 +91,8 @@ of global filters (`LuigiTemplate.FILTERS`), like so: // prints "hello bar-<Paul>-bar" -You can also create a custom filters and limit it to a particular -template by passing a hash as the second parameter to the +You can also create a custom filter and limit it to a particular +template by passing a custom filter hash as the second parameter to the `LuigiTemplate` constructor, like this: // create template with custom template-specific filter @@ -118,8 +109,7 @@ template by passing a hash as the second parameter to the // prints "hello bar-<Paul>-bar" -You can pass arguments to your custom filters as well. Here's an -example: +You can pass arguments to your custom filters. Here's an example: // create template with custom template-specific filter named // "wrap", which wraps the value in the given filter parameters @@ -167,6 +157,27 @@ Here's how you create a template cache: // prints "hello <PAUL%gt;" +Finally, template caches use their own set of custom filters by passing +the custom custom when creating a template cache: + + // create template cache with a custom filter named "reverse" + var cache = LuigiTemplate.cache({ + hello: 'hello %{name | uc | reverse | h}' + }, { + reverse: function(s) { + var cs = (s || '').split(''); + cs.reverse(); + return cs.join(''); + }, + }); + + // run template, print result to console + console.log(cache.run('hello', { + name: '<Paul>', + })); + + // prints "hello %gt;LUAP<" + Documentation ------------- *TODO* |