npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

perroquet

v1.0.1

Published

Compile perroquet template files into pure PHP files

Downloads

4

Readme

Build Status

	 ____                                      _   
	|  _ \ ___ _ __ _ __ ___   __ _ _   _  ___| |_ 
	| |_) / _ \ '__| '__/ _ \ / _` | | | |/ _ \ __|
	|  __/  __/ |  | | | (_) | (_| | |_| |  __/ |_ 
	|_|   \___|_|  |_|  \___/ \__, |\__,_|\___|\__|
								 |_| 

Perroquet is a small template engine that compiles into PHP. It's compiled into raw PHP files that you can run in your PHP server.

Usage

var php_code = perroquet('Hi my name is {{$name}}');
// php code = 'Hi my name is <?php echo $name; ?>'

List of template codes

| Template code | Generated php code | |---|---| |{{$variable}}|<?php echo $variable; ?>| |{{$object.attribute}}|<?php echo $object->attribute; ?>| |{{$array[key]}}|<?php echo $array['key']; ?>| |{{$variable = 'value'}}|<?php $variable = 'value'; ?>| |{{$array as $value}}|<?php foreach ($array as $value) {| |{{$array as $key => $value}}|<?php foreach ($array as $key => $value) {| |{{function() as $value}}|<?php foreach (function() as $value) { ?>| |{{=date(..)}}|<?php echo date(..); ?>| |{{#variable}}|<?php echo htmlentities($variable, ENT_COMPAT, 'utf-8'); ?>| |{{url $img}}|<?php echo rawurlencode($img); ?>| |{{>path}}|<?php include 'path'; ?>| |{{?variable}}|<?php if (!empty($variable)) { ?>| |{{!variable}}|<?php if (empty($variable)) { ?>| |{{?variable1 && !variable2}}|<?php if (!empty($variable1) && empty($variable2)) ?>| |{{if condition}}|<?php if (condition) { ?>| |{{elseif condition}}|<?php else if (condition) { ?>| |{{else}}|<?php } else { ?>| |{{for $i = 0; $i < 9; $i++}}|<?php for ($i = 0; $i < 9; $i++) { ?>| |{{while condition}}|<?php while (condition) { ?>| |{{/}}|<?php } ?>| |{{switch condition}}|<?php switch (condition) { ?>| |{{case 'awesome'}}|<?php case 'awesome': ?>| |{{bcase 'awesome'}}|<?php break; case 'awesome': ?>| |{{default}}|<?php break; default: ?>| |{{break}}|<?php break; ?>| |{{pr $variable}}|<pre><?php print_r($variable); ?></pre>| |{{js $variable}}|<?php echo json_encode($variable); ?>| |{{esc}} my escaped {{$code}} {{/esc}}|my escaped {{$code}}|

Custom functions

You can add custom functions to the compiler:

var php_code = perroquet('Today is the {{date Y-m-d}}', {
	date: function (format) {
		// format = 'Y-m-d'
		return '<?php echo date(\''+format.replace(/'/g, '\\\'')+'\'); ?>';
	}
});

Custom delimiters

You can change the default {{..}} delimiters with the third parameter of perroquet(code, custom_functions, custom_regex). For example:

var php_code = perroquet('Hi my name is --#name--', null, /--(.*?)--/g);

To suggest a feature, report a bug, or general discussion: http://github.com/blunt1337/perroquet/issues/