Textpattern Forum

You are not logged in. Register | Login | Help

#1 2011-04-26 12:10:59

pacifika
New Member
Registered: 2011-04-26
Posts: 1

[textile] [Patch] CodeIgniter Helper class patch for classTextile.php

Because up to now it was easier to user markdown as a helper rather than textile (which had to be implemented as a library) in the CodeIgniter PHP framework, I created a patch to make using textile much simpler.
Download Patch for Textile v2.2 or the patched textile v2.2 CodeIgniter Helper

Instructions

  • Copy /textpattern/lib/classTextile.php to /application/helpers/textile_helper.php from a TextPattern installation
  • Apply the patch in the helpers directory: @patch < textile_ci-helper.patch
  • Then simply use textile as follows:
$this->load->helper('textile');
$text = Textile("Dude this is *my* code!");

Thanks to Michel Fortin of Markdown PHP for his PHP Markdown Extra which is implemented similarly to my patch. BTW, I’m not that experienced in making patches available, so any feedback on the process is appreciated. I’ll crosspost on the codeigniter forums.

Patch contents

# HG changeset patch
# User Sander van Dragt <no_spam>
# Date 1303818706 -3600
# Node ID 2cdd62a7582fb34141f30a99a13ad5bd7f6a3526
# Parent  32ec7d832b380362ac0a6c62033158774e8ed3fa
Textile helper code added

diff -r 32ec7d832b38 -r 2cdd62a7582f application/helpers/textile_helper.php
--- a/application/helpers/textile_helper.php	Tue Apr 26 12:50:52 2011 +0100
+++ b/application/helpers/textile_helper.php	Tue Apr 26 12:51:46 2011 +0100
@@ -330,6 +330,23 @@
 @define('txt_plusminus',          '±');
 @define('txt_has_unicode',        @preg_match('/\pL/u', 'a')); // Detect if Unicode is compiled into PCRE

+# CodeIgniter Helper class
+@define( 'TEXTILE_PARSER_CLASS',  'Textile' );
+function Textile($text) {
+#
+# Initialize the parser and return the result of its transform method.
+#
+	# Setup static parser variable.
+	static $parser;
+	if (!isset($parser)) {
+		$parser_class = TEXTILE_PARSER_CLASS;
+		$parser = new $parser_class;
+	}
+
+	# Transform text using parser.
+	return $parser->TextileThis($text);
+}
+
 class Textile
 {
 	var $hlgn;

Last edited by pacifika (2011-04-26 12:37:09)

Offline

Board footer

Powered by FluxBB