Nov 08 2006

Chili & Enzymes

Tag: Chili, EnzymesAndrea Ercolino @ 03:01:32

UPDATE (2008-03-20): There is a new post about Chili & Enzymes. Thanks to their new versions, it’s now much easier to config WordPress highlighting than described here.

If you post many code snippets, then Chili and Enzymes can work together for making your life simpler.Here is my proposed configuration:

1. Install Enzymes
Download the latest version to your computer, upload it to your server, in the ‘plugins’ directory under ‘/wp-content’, and activate it. No configuration needed.

2. Upload jQuery and Chili
For this configuration I’m going to put the file ‘jquery-1.0.3.pack.js’ in a ‘jquery’ directory under the ‘/wp-content’ directory, and the file ‘chili-1.1.pack.js’ in a ‘chili’ directory under the ‘jquery’ directory. In the ‘chili’ directory I’ll put also any recipes and stylesheets I’ll need.
I recommend to upload and setup at least one of the examples provided with Chili. It’ll be useful for proving that Chili is properly configured (bypassing WordPress).

3. Upload an Enzymes template for each language you’ll use
In fact there are many valid alternatives, but I think that this one is pretty simple and you can eventually expand on it. Here is the template I’m going to use for JavaScript snippets:

<pre class="chili-<?php 
	$tmp = preg_split( '/[\r\n]+/', $this->result );
	if( count( $tmp ) > 28 ) echo 'clip';
	else echo 'all'; 
?>"><code class="javascript"><?php 
	echo htmlentities( $this->result ); 
?></code></pre>
Note that the template decides the style of the ‘pre’ tag and that the result is automatically escaped. Anyway this is still a naive template, which is not suitable for javascript snippets mixed into html snippets. Remember that the base directory for Enzymes templates is ‘wp-content’.

4. Add style settings to the stylesheet of your current WordPress theme
You should provide only general format for the tags you are going to use for wrapping your code snippets. For example, I’m going to use a ‘pre’ tag wrapped around the ‘code’ tag. In the style.css file, I’ll add these definitions:

pre.chili-all {
	color: #333333; 
	background-color: #f4f4f4; 
	font-size: 9pt; 
	line-height: 120%;
	width: 450px; 
	overflow: auto; 
	}

pre.chili-clip {
	color: #333333; 
	background-color: #f4f4f4; 
	font-size: 9pt; 
	line-height: 150%;
	width: 450px; 
	height: 450px; 
	overflow: auto; 
	}

pre.chili-all code, pre.chili-clip code {
	font-size: 9pt; 
	line-height: 150%;
	}
As you see, they are very similar: chili-all adjust the height of the box to the length of the content; chili-clip fixes the height to a maximum.

5. Edit the header.php file of your current WordPress theme
This is to enable support for Chili in each HTML page of the blog. It’s just three script elements: two for loading jQuery and Chili, and one for configuring Chili.

The following two items must appear in the ‘head’ section, maybe just before the closing tag. <script type="text/javascript" src="<?php bloginfo('siteurl'); ?>/wp-content/jquery/jquery-1.0.3.pack.js"></script> <script type="text/javascript" src="<?php bloginfo('siteurl'); ?>/wp-content/jquery/chili/chili-1.1.js"></script>The following two items must appear in the ‘body’ section, maybe just after the opening tag.

<script>
ChiliBook.recipeFolder = "<?php 
	bloginfo('siteurl'); 
?>/wp-content/jquery/chili/";
ChiliBook.stylesheetFolder = "<?php 
	bloginfo('siteurl'); 
?>/wp-content/jquery/chili/";
</script>

6. Done, now test the configuration

  1. Create a new post titled “Testing Enzymes & Chili”. Hit ‘Save and Continue Editing’
  2. Add a custom field with a Key “js-snippet” and a Value “document.writeln( "Hello World!" );”
  3. Add this Enzymes statement “{[.js-snippet /enzymes/chili-js.php]}” into the post area
  4. Hit ‘Publish’ and then ‘View site’

If it looks like this

document.writeln( "Hello World!" );
then all is fine. Enjoy!


Nov 05 2006

Chili 1.1 Released Today

Tag: ChiliAndrea Ercolino @ 00:23:28

UPDATE: Chili 1.2 has been released

Changes

  • Added support for backreferences in recipe steps. Due to the mechanics of the parsing engine this was not possible before, without a proper renumbering, which is now transparently done by Chili.
  • Fixed a bug in the JavaScript recipe which prevented correct highlighting of single and double quoted strings containing escaped quotes.
  • Added support for PHP highlighting, with all of its 3309 functions.
  • Presented in the examples a new method for configuring Chili, on a per file basis.
  • The examples have been updated to reflect new versions of Chili and jQuery.
  • Added a brand new example where Chili highlights PHP. (the script was used to generate the dictionary pattern for all PHP functions, included in the PHP recipe)

Files

  • download all in a zip
  • read the manual
  • test Chili highlighting Chili
  • test Chili highlighting jQuery
  • test Chili highlighting PHP

Oct 17 2006

Chili 1.0_b Released Today

Tag: ChiliAndrea Ercolino @ 16:18:25

UPDATE: Chili 1.1 has been released

Changes

  • No code change.
  • A proper free license (MIT) has been added to all files.
  • The version number has been added to the path of the Chili site.
  • A new directory structure for examples has been added, together with a brand new example where Chili highlights jQuery.

Files

  • all
  • manual
  • Chili highlighting Chili
  • Chili highlighting jQuery

Free license
I clearly stated the terms of the license in the release post. But it’s important that any sensible information be protected by the same terms, so I added an MIT license to them.

Versioned directories
I found that without version numbers in the path I had to make adjustments to incoming links or provide some kind of redirection. Versioned directories should save me time.

  • Content previously found in /aercolino /chili/ has been moved to /aercolino /chili /1.0/
  • Content of this 1.0_b release has been placed in /aercolino /chili /1.0_b/

Examples
Starting from /aercolino /chili /1.0_b /examples/ can now be found a new directory structure for showing how Chili can be used in a sample environment. The base directory hosts generic files linked by the examples, like recipes and stylesheets.

chili-1.0.js has been configured for accessing recipes and stylesheets from this directory. Then it has been packed with the Dean Edwards’ wonderful JavaScript compressor. But it’s not been deleted, for leaving a configuration reminder and for being able to adjust it in the future.

Any example has its own directory numbered from 1 upward, like /aercolino /chili /1.0_b /examples /1 /chili-1.0-highlighting-chili-1.0.html which is the example previously available.

Chili highlighting Chili

/aercolino /chili /1.0_b /examples /1 /chili-1.0-highlighting-chili-1.0.html is the only file in its directory. It loads all the files it needs from its parent directory. This is how highlighting should generally work. With Chili there is the additional benefit that the example only links to jquery and chili. Chili itself will automatically load any file it needs.

Chili highlighting jQuery

/aercolino /chili /1.0_b /examples /2 /chili-1.0-highlighting-jquery-1.0.2.html is not the only file in its directory. This is for showing how to deal with exceptions to the general plan. This example highlights the jQuery script by marking up JavaScript and jQuery items. So special jQuery-flavored JavaScript recipe and stylesheet need to be used.


Oct 15 2006

Chili 1.0 Released Today

Tag: ChiliAndrea Ercolino @ 20:04:43

UPDATE: Chili 1.0_b has been released

Features

  • Syntax highlighting for the browser; IE, Firefox, Mozilla, and Opera friendly
  • a jQuery, AJAX, Javascript, fully documented, free application
  • Javascript and Lotusscript recipes provided
  • 100% compatible with Code Highlighter 0.4 styleSets

Files

  • chili1.0-example.html
  • chili1.0-manual.txt
  • chili1.0-all.zip

This software is gratis.
You could buy me a cappuccino, but it’s up to you.


« Previous Page