Permalink
Browse files

Merge branch 'master' of http://github.com/vlucas/nijikodo into vluca…

…s-master
  • Loading branch information...
2 parents c0ca49b + bac89ff commit 65e9df277b347cf80fa68fd4eda19572a73b3e70 @ccampbell committed Oct 14, 2010
View
@@ -1,10 +1,10 @@
-<?php include 'lib/Nijikodo.php'; ?>
+<?php require 'lib/Nijikodo/Parser.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>nijikodo demo page</title>
+ <title>Nijikodo demo page</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.niji_code { width: 650px; }
@@ -26,18 +26,18 @@
<h2>usage</h2>
<p>to install put the lib directory somewhere in your include path:</p>
-<?php Nijikodo::captureStart(); ?>
+<?php Nijikodo\Parser::captureStart(); ?>
{code:php}
-include 'lib/Nijikodo.php';
+require 'lib/Nijikodo/Parser.php';
// you can optionally set a css class prefix (defaults to 'niji_')
-Nijikodo::setCssPrefix('code_');
+Nijikodo\Parser::setCssPrefix('code_');
{code}
<p>to syntax highlight code from a form field:</p>
{code:php}
$text = $_POST['text'];
-$text = Nijikodo::process($text);
+$text = Nijikodo\Parser::process($text);
{code}
<p>use these special tags in the form field to specify that this block of text is code:</p>
@@ -50,7 +50,7 @@
<p>this can also be done directly in a view using output buffering like so:</p>
{code:html}
<!-- begin capturing code -->
-&lt;?php Nijikodo::captureStart(); ?&gt;
+&lt;?php Nijikodo\Parser::captureStart(); ?&gt;
{code}
{code:shell}
&#123;code:javascript&#125;
@@ -59,21 +59,21 @@
{code}
{code:html}
<!-- output what has been captured -->
-&lt;?php echo Nijikodo::output(); ?&gt;
+&lt;?php echo Nijikodo\Parser::output(); ?&gt;
{code}
<p>additionally if you have a string that you already know is a specific type of code you can do this:</p>
{code:php}
$string = '&lt;p&gt;this is my string&lt;/p&gt;';
-$html_string = Nijikodo::toHtml($string, 'html');
+$html_string = Nijikodo\Parser::toHtml($string, 'html');
{code}
<p>finally if you would like to run your string through some other functions you can tokenize the code blocks and fill them back in later</p>
{code:php}
$text = $_POST['text'];
-$text = Nijikodo::tokenizeCodeBlocks($text);
+$text = Nijikodo\Parser::tokenizeCodeBlocks($text);
$text = nl2br($text);
-$text = Nijikodo::replaceTokens($text);
+$text = Nijikodo\Parser::replaceTokens($text);
{code}
@@ -195,6 +195,6 @@ function customFunction()
}
{code}
-<?php echo Nijikodo::output(); ?>
+<?php echo Nijikodo\Parser::output(); ?>
</body>
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,13 +1,14 @@
<?php
-include 'Language/Generic.php';
+namespace Nijikodo;
+require 'Language/Generic.php';
/**
* server side library for syntax highlighting code snippets
*
* @package Nijikodo
* @author Craig Campbell <iamcraigcampbell@gmail.com>
*/
-class Nijikodo
+class Parser
{
/**
* @var string
@@ -39,49 +40,49 @@ public static function toHtml($code, $language = null, $height = null)
switch ($language) {
case 'php':
require_once 'Language/Php.php';
- $code = new Nijikodo\Language\Php($code);
+ $code = new Language\Php($code);
break;
case 'html':
case 'xml':
require_once 'Language/Html.php';
- $code = new Nijikodo\Language\Html($code);
+ $code = new Language\Html($code);
break;
case 'css':
require_once 'Language/Css.php';
- $code = new Nijikodo\Language\Css($code);
+ $code = new Language\Css($code);
break;
case 'javascript':
require_once 'Language/Javascript.php';
- $code = new Nijikodo\Language\Javascript($code);
+ $code = new Language\Javascript($code);
break;
case 'shell':
require_once 'Language/Shell.php';
- $code = new Nijikodo\Language\Shell($code);
+ $code = new Language\Shell($code);
break;
case 'apache':
require_once 'Language/Apache.php';
- $code = new Nijikodo\Language\Apache($code);
+ $code = new Language\Apache($code);
break;
case 'ini':
require_once 'Language/Ini.php';
- $code = new Nijikodo\Language\Ini($code);
+ $code = new Language\Ini($code);
break;
case 'text':
require_once 'Language/Text.php';
- $code = new Nijikodo\Language\Text($code);
+ $code = new Language\Text($code);
break;
default:
- $code = new Nijikodo\Language\Generic($code);
+ $code = new Language\Generic($code);
break;
}
- $code->setCssPrefix(self::$_css_prefix);
+ $code->setCssPrefix(static::$_css_prefix);
// hate outputting html in php but that is the point of this library
- $output = '<div class="' . self::$_css_prefix . 'code';
+ $output = '<div class="' . static::$_css_prefix . 'code';
if ($language !== null) {
- $output .= ' ' . self::$_css_prefix . $language . '" style="';
+ $output .= ' ' . static::$_css_prefix . $language . '" style="';
}
// $output .= 'font-family: \'monaco\',courier,monospace; white-space: pre-wrap;';
@@ -105,7 +106,7 @@ public static function toHtml($code, $language = null, $height = null)
*/
public static function setCssPrefix($prefix = self::DEFAULT_CSS_PREFIX)
{
- self::$_css_prefix = $prefix;
+ static::$_css_prefix = $prefix;
}
/**
@@ -116,8 +117,8 @@ public static function setCssPrefix($prefix = self::DEFAULT_CSS_PREFIX)
*/
public static function process($text, $use_pre_tag = false)
{
- $text = self::tokenizeCodeBlocks($text);
- return self::replaceTokens($text, $use_pre_tag);
+ $text = static::tokenizeCodeBlocks($text);
+ return static::replaceTokens($text, $use_pre_tag);
}
/**
@@ -128,7 +129,7 @@ public static function process($text, $use_pre_tag = false)
*/
public static function tokenizeCodeBlocks($text)
{
- $text = preg_replace_callback('/\{code(:)?([^\}]+\b)?\}(.+?)(\{code\})(\n)?/is', 'self::_tokenizeCodeBlock', $text);
+ $text = preg_replace_callback('/\{code(:)?([^\}]+\b)?\}(.+?)(\{code\})(\n)?/is', 'static::_tokenizeCodeBlock', $text);
return $text;
}
@@ -141,7 +142,7 @@ public static function tokenizeCodeBlocks($text)
*/
public static function replaceTokens($text, $use_pre_tag = false)
{
- foreach (self::$_tokenized as $key => $value) {
+ foreach (static::$_tokenized as $key => $value) {
$text = str_replace($key, $use_pre_tag ? '<code><pre>' . $value . '</pre></code>' : $value, $text);
}
@@ -168,7 +169,7 @@ public static function output()
$text = ob_get_contents();
ob_end_clean();
// replace code blocks with magic things we will replace later
- return self::process($text);
+ return static::process($text);
}
/**
@@ -193,9 +194,9 @@ protected static function _tokenizeCodeBlock($matches)
$code = ltrim($code, "\n");
$token = 'code:' . uniqid();
- $html = self::toHtml($code, $language, $height);
+ $html = static::toHtml($code, $language, $height);
- self::$_tokenized[$token] = $html;
+ static::$_tokenized[$token] = $html;
return $token;
}

0 comments on commit 65e9df2

Please sign in to comment.