This repository has been archived by the owner on Apr 11, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move custom tags docs to new extending page
- Loading branch information
1 parent
5b4a192
commit 1bbb8df
Showing
7 changed files
with
245 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
{% extends "./layout.html" %} | ||
|
||
{% block title %}{% parent %} » Extending Swig{% endblock %} | ||
|
||
{% block content %} | ||
|
||
{% macro description(el) %} | ||
<p>{{ el.description|replace('\n', '</p><p>')|raw }}</p> | ||
{% endmacro %} | ||
|
||
<h1 id="extending">Extending Swig</h1> | ||
|
||
<section class="doc" id="tags"> | ||
<h2>Custom Tags</h2> | ||
|
||
<p>Swig can be extended to handle custom tags that will perform operations on full blocks of your templates. Use <a href="{{ baseurl }}/docs/api/#addTag"><code data-language="js">swig.addTag(name, parse, compile, ends)</code></a> to add your custom tag.</p> | ||
|
||
<p>All of Swig's tags are written using the same api (with a few exceptions for core modules, like <var>extends</var> and <var>block</var>). View a tag's source to see more examples to write your own custom tags.</p> | ||
|
||
{% for t in typedefs %}{% if t.name === 'parse' or t.name === 'compile' %} | ||
<section id="{{ t.name }}" class="doc"> | ||
<h3>{{ t.name }}({% for p in t.params %}{{ p.name }}{% if not loop.last %}, {% endif %}{% endfor %})</h3> | ||
|
||
<p>{{ description(t)|raw }}</p> | ||
|
||
<h4>Arguments</h4> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th>Optional</th> | ||
<th>Default</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for p in t.params %} | ||
<tr> | ||
<td><var data-language="js">{{ p.name }}</var></td> | ||
<td><code data-language="js">{{ p.type }}</code></td> | ||
<td>{% if p.optional %}✔{% endif %}</td> | ||
<td><samp data-language="js">{{ p.default }}</samp></td> | ||
<td>{{ p.description|raw }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
|
||
{% for ex in t.examples %} | ||
<pre><code data-language="js">{{ ex }}</code></pre> | ||
{% endfor %} | ||
|
||
</section> | ||
{% endif %}{% endfor %} | ||
|
||
<section id="ends" class="doc"> | ||
<h3>ends</h3> | ||
|
||
<p>Controls whether or not a tag must have an <code data-language="swig">{% raw %}{% end[tagName] %}{% endraw %}</code> declared after usage in templates.</p> | ||
|
||
<pre><code data-language="js">exports.ends = true; | ||
// => A template that fails to close this tag will throw an Error.</code></pre> | ||
|
||
<pre><code data-language="js">exports.ends = false; | ||
// => A template attempts close this tag will throw an Error.</code></pre> | ||
</section> | ||
|
||
{% for prop in properties %} | ||
{% if prop.isEnum %} | ||
<section id="{{ prop.name }}" class="doc"> | ||
<h3>{{ prop.name }}</h3> | ||
<p>{{ prop.description|replace('\n', '</p><p>')|raw }}</p> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Value</th> | ||
<th>Name</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><samp data-language="js">'*'</samp></td> | ||
<td></td> | ||
<td>For every token, run the given callback.</td> | ||
</tr> | ||
<tr> | ||
<td><samp data-language="js">'start'</samp></td> | ||
<td></td> | ||
<td>Run before any token is parsed.</td> | ||
</tr> | ||
<tr> | ||
<td><samp data-language="js">'end'</samp></td> | ||
<td></td> | ||
<td>Run after all other tokens have been parsed.</td> | ||
</tr> | ||
{% for p in prop.properties %} | ||
<tr> | ||
<td><samp data-language="js">{{ p.default }}</samp></td> | ||
<td><var data-language="js">types.{{ p.name }}</var></td> | ||
<td>{{ p.description|raw }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</section> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{# % for typedef in typedefs %} | ||
{% if typedef.type|lower === 'object' %} | ||
<section id="{{ typedef.name }}" class="doc"> | ||
<h3>{{ typedef.name }}</h3> | ||
<p>{{ description(typedef)|raw }}</p> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th>Optional</th> | ||
<th>Default</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for p in typedef.properties %} | ||
<tr> | ||
<td><var data-language="js">{{ p.name }}</var></td> | ||
<td><code data-language="js">{{ p.type }}</code></td> | ||
<td>{% if p.optional %}✔{% endif %}</td> | ||
<td><samp data-language="js">{{ p.default }}</samp></td> | ||
<td>{{ p.description|raw }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</section> | ||
{% endif %} | ||
{% endfor % #} | ||
|
||
</section> | ||
{% endblock %} | ||
|
||
{% block extendingsubnav %} | ||
<ol> | ||
<li> | ||
<a href="#tags">Custom Tags</a> | ||
<ol> | ||
<li><a href="#parse">parse</a></li> | ||
<li><a href="#compile">compile</a></li> | ||
<li><a href="#ends">ends</a></li> | ||
<li><a href="#TYPES">Token Types</a></li> | ||
</ol> | ||
</li> | ||
</ol> | ||
{% endblock %} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.