diff options
author | Paul Duncan <pabs@pablotron.org> | 2018-09-09 13:01:54 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2018-09-09 13:01:54 -0400 |
commit | b91c8bab0146772af20e0bc6c2f9e5d3ac167a1b (patch) | |
tree | 51863c25bdc5a43b8e98681112888cee43def106 /js | |
parent | c0f4d9a505ab1a94e6b0993582c9827f5a681e05 (diff) | |
download | luigi-template-b91c8bab0146772af20e0bc6c2f9e5d3ac167a1b.tar.bz2 luigi-template-b91c8bab0146772af20e0bc6c2f9e5d3ac167a1b.zip |
js: add cache group section, fix typos
Diffstat (limited to 'js')
-rw-r--r-- | js/README.mkd | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/js/README.mkd b/js/README.mkd index 63d50e9..f8af3c4 100644 --- a/js/README.mkd +++ b/js/README.mkd @@ -136,12 +136,9 @@ If you have a lot of separate templates, or a few large templates, then it's a good idea to use a template cache. A template cache will create templates as they are needed (also known as -"lazy initialization"), so the page or application loads quickly. A -template cache also caches instantiated (that is, created) templates for -future use, so using templates from the cache is fast, too. - -Finally, template caches serve as a good repository for all of the -templates in a script. +"lazy initialization"), so the script loads quickly. A template cache +also caches instantiated (that is, created) templates for future use, so +that using templates repeatedly from the cache is fast as well. Here's how you create a template cache: @@ -157,8 +154,8 @@ 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: +Template caches use their own set of custom filters by passing a custom +filter hash when creating a template cache: // create template cache with a custom filter named "reverse" var cache = LuigiTemplate.cache({ @@ -178,15 +175,39 @@ the custom custom when creating a template cache: // prints "hello %gt;LUAP<" +A template cache is also a convenient way to group all of the templates +in a script together: + + // add global filter named "reverse" + LuigiTemplate.FILTERS.reverse: function(s) { + var cs = (s || '').split(''); + cs.reverse(); + return cs.join(''); + }; + + // create template cache + var TEMPLATES = LuigiTemplate.cache({ + upper: 'hello %{name | uc | h}', + reverse: 'hello %{name | reverse | h}', + }); + + // run the upper and reverse templates above and populate + // the elements #upper and #reverse with their respective + // result + ['upper', 'reverse'].forEach(function(id) { + getElementByid(id).innerHTML = TEMPLATES.run(id, { + name: '<Paul>', + }); + }); + Documentation ------------- *TODO* Tests ----- -This `test/` directory contains the JavaScript test suite for the -JavaScript implementation of [Luigi Template][], written in [Mocha][] -and [Chai]. +This `test/` directory contains the test suite for the JavaScript +implementation of [Luigi Template][], written in [Mocha][] and [Chai]. To run the test suite, load `test/test.html` in a browser. |