![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Goji is a template engine for Node.js that conforms to the Hapi view engine requirements.
Goji was inspired by Thymeleaf. The name was picked from Wikipedia's list of herbs based on whimsy and availability.
Goji's templates are (mostly) valid HTML. Goji templates rely on custom attributes that are replaced during the compilation and rendering process.
$ npm install --save goji
<!DOCTYPE html>
<html>
<head></head>
<body>
<div g-text="foo.bar">This should be replaced with the value of foo.bar</div>
<div g-text="foobar()">This should be replaced with the result of foobar()</div>
<div g-text="answer === 41 ? foo.bar : 'nope'"></div>
<div g-text="(answer === 42) ? foo.bar : 'nope'"></div>
</body>
</html>
var goji = require('goji');
var fs = require('fs');
var template = fs.readFileSync('./template.html');
var renderer = goji.compile(template);
var context = {
foo: {
bar: 'foo.bar'
},
foobar: function foobar() {
return 'foobar() invoked';
},
answer: 42
};
console.log(renderer(context));
By default, the compiler will look for templates with a file extension of
".html" in an "html" directory that is in the same directory as your
project's node_modules
directory. If you need to change this behavior, you
can use the
Compiler Options
object.
As mentioned in the introduction, Goji uses custom attributes on standard HTML elements. Thus Goji's templating "language" is really just vanilla HTML.
However, the values of those attributes are not standard. Gogi's attribute values are a mixture of a JavaScript expression language and simple identifiers.
Goji's expression language is a subset of vanilla JavaScript. It will evaluate simple calculations, ternary operations, object lookups, and invoke methods.
Any time an expression is evaluated it is done so within a context. The context is a regular JavaScript object literal. For example, the following literal is a completely valid context that can be used as normal within the expression:
{
foo: {
bar: [1, 2, 3]
},
foobar: function foobar() {
return 'result of foobar()';
},
bar: 'bar',
baz: 42
}
The expression language used is exprjs. To see a complete rundown of the available expressions, view their test-expr.js.
g-text
substitutes the result of an expression in place of the element's
content. For example, given the following HTML:
<p>Hello <span g-text="'world'">??</span>!</p>
The rendered template would be:
<p>Hello <span>world</span>!</p>
g-each
is used to iterate over an array. It uses a simple expression to
select the array and name the iteration variable. The expression is in
the form [iteration variable name] in [array name]
. For example:
<ul>
<li g-each="item in items" g-text="item">placeholder</li>
</ul>
If the context is:
{items: ['list item 1', 'list item 2', 'list item 3']}
Then the rendered content would be:
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ul>
However, if the template is:
<table>
<tr g-each="row in rows">
<td g-text="row.cell1">cell1</td>
<td g-text="row.cell2">cell2</td>
</tr>
</table>
And the context is:
{
rows: [
{cell1: 'r1c1', cell2: 'r1c2'},
{cell1: 'r2c1', cell2: 'r2c2'}
]
}
Then the rendered content would be:
<table>
<tr>
<td>r1c1</td>
<td>r1c2</td>
</tr>
<tr>
<td>r2c1</td>
<td>r2c2</td>
</tr>
</table>
There are a few things to notice in these examples:
g-each
and g-text
attributes,
then the template element will be used as the template for the
iterations.g-each
attribute, then the parent
element's content will be used as the template for the iterations.g-include
inserts the content of a fragment in place of the element's
content. The value of g-include
is a simple identifier in the form
[templateName]::[fragmentId]
. For example, given the following HTML:
<div class="container">
<div g-include="fooTemplate::#bar">This will be replaced</div>
</div>
Goji will look for a template file named "fooTemplate", parse it, and then
retrieve the content from an element with an id
attribute value of "bar".
So, if fooTemplate's content is:
<p id="bar">bar's content</p>
Then the rendered template will be:
<div class="container">
<div>bar's content</div>
</div>
g-replace
works much like g-include
, the difference is that g-replace
replaces the element on which it is an attribute. Thus, given the same
example as in g-include
the rendered template would be:
<div class="container">
<p id="bar">bar's content</p>
</div>
http://jsumners.mit-license.org
THE MIT LICENSE (MIT) Copyright © 2014 James Sumners james.sumners@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
An HTML templating engine inspired by Thymeleaf
The npm package goji receives a total of 10 weekly downloads. As such, goji popularity was classified as not popular.
We found that goji demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.