Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Punch is a simple tool to generate a static website out of Mustache templates and content stored in either JSON or Markdown format.
App Promo sites
Portfolio sites
Project Documentation
Event Marketing sites
(or even for your cat's homepage)
Remember: Punch is not a blogging engine
(You can use Jekyll and other similar tools to power a blog)
Download and Install Node.js.
Install npm
curl http://npmjs.org/install.sh | sh
Then run npm intall punch
Start by creating a new directory to hold your site. (mkdir mysite
)
Run punch setup
to create a skeleton. (it will create a templates
directory, contents
directory and config.json
file)
Create your site's structure inside the templates
directory. Punch will try to render templates with .mustache
extension and any other file (JS, CSS & images) will be copied as it is.
When rendering a mustache template, Punch will look for relavant content for the template in contents
directory. You can serve the content in a single .json
file or as a collection of .markdown
and .json
file inside a directory.
For example, to render about.mustache
template you can provide content in about.json
file or in a directory called about
which can have bunch of content in .markdown
or .json
format.
To generate the site, run the command punch
in the main site directory. Generated site can be found inside the public
directory.
Go inside the public
directory and run python -m SimpleHTTPServer
. Then point your browser to http://localhost:8000
to see your site in action!
Partial templates
You can specify reusable partial templates with Punch. Partial templates should be named with a leading underscore character (eg. _sidebar.mustache
). To render a partial in another template, do this:
{{> sidebar }}
Shared content
If you create a JSON file with the name shared.json
or a directory named shared
under contents
its content will be automatically available for all templates in your site.
Using the renderer in browser
It's possible to use the Punch's renderer in the browser as well. All you need to do is include the latest mustache.js
and the Punch's renderer in your client-side script.
<script type="text/javascript" src="assets/mustache.js"></script>
<script type="text/javascript" src="node_modules/punch/lib/renderers/mustache.js"></script>
Here's how you can use it in the browser:
var renderer = new MustacheRenderer();
renderer.afterRender = function(output){
document.getElementById("client_block").innerHTML = output;
};
renderer.setTemplate('<p>{{content}}</p>');
renderer.setContent({"content": "test"});
renderer.setPartials({});
Since Punch's renderer is asynchronous, you can call setTemplate
, setContent
and setPartials
once you have the data (eg. after loading via AJAX). Rendering will happen when the renderer receives all 3 method calls.
Configuration options
{
"template_dir": "templates", // directory to look for templates
"content_dir": "contents", // directory to look for contents
"output_dir": "public", // directory to save the generated output
"output_extension": "html", // default extension to use for output files
"shared_content": "shared", // name of the file/directory of shared content inside `contents`
// register new renderers or parsers (paths should be valid node.js require paths)
"renderers": {
"mustache": "./renderers/mustache"
},
"parsers": {
"markdown": "./parsers/markdown"
}
};
Checkout the sample available at /sample
to understand the directory structure and configurations.
I welcome you to contribute and be part of Punch:
FAQs
A fun and easy way to build modern websites
The npm package punch receives a total of 39 weekly downloads. As such, punch popularity was classified as not popular.
We found that punch 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 digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.