PDA

View Full Version : Pass html-code of a table to an extension



jeff
11-07-2008, 10:59 AM
Hi!

I'm new to dekiscript and i have a (possibly) simple question. I would like to send the contents of a table to a custom extension. The table should be editable in wiki as a normal table. To begin, i just tested it with the <b>-Tag

I tryed following:
{{myext.format("hello")}}
-> <b>-Tag is stripped out
<pre class="script" function="myext.format">hello</pre> -> is stripped out too.

if i write the tags like this:
&lt;b&gt;hello&lt;/b&gt;
they are passed to the extension, but it is not really what i want.

because this would mean, that i have to write the whole table-html on my own, and the wiki-wysiwyg disappears. So i'm actually looking for something like:
<pre class="script" option="nostrip" function="myext.format"> (only example, this does not work...)

If this is not supported, i also thought about somehow reading the table with dekiscript and passing it's html to my extension. Can you give me an example, how can i do this?

Info: the extension is purposed to reformat the table in different ways: just easy standartizing the css format of tables (alternate cell color and so on...) and also for manipulating table data (grouping values, selecting..)

Any ideas?

Guerric
11-07-2008, 06:33 PM
Don't worry jeff. Deki is awesome.

If you're creating a custom extension, then you need to specify that a function is a content transformation. When you specify a function as being a content transformation, you set which tags the extension can be applied to.

In your case you would set the extension to only transform "table" elements. Now when this is applied to a table through the "Transformations" drop down, the entire table html is sent as the first parameter to your extension. If you don't output anything else then the table will be removed from the page on render. Play around with it and you'll see what i mean.

If you are writing a dekiscript extension, specifying a function as a transformation is as simple as the following:

<function transform="table">
or

<function transform="table,p,div,pre">

Good luck!

jeff
11-08-2008, 02:57 PM
Hello, Guerric!

Thank you very much for your help! This is exactly what i was looking for! My table-format function works pretty good now! (i've had to add some additional lines to Dekiscript.php, because i did not find any support for transform-tag. But that was quite easy)

I figured out, that what clicking on the transform-list actually does is just adding two attributes to my table-tag:

<table function="tabletool.formatTable" class="script">So now i'm able to send the table-contents as HTML to my extension. I was wondering, if there is a built-in possibility to add some extra parameters to the function call?


EDIT:
after some testing, i've found a way to do that:
i write my parameter to the caption-tag of the table. i my extension i then delete the caption tag before output. like this:

<table><caption>(groupBy=c3,c4)(countColumn=count)</caption>...</table>

i use the follwing php-code to parse my config:


$tablexml = new SimpleXMLElement($table);
$caption = (string)$tablexml->body->table->caption;
$pattern = '~\(([^\(\)]*)\)~is';

//split (key1=value1)(key2=value2)
if (preg_match_all($pattern, $caption, $subpattern)) {
//split key=value
foreach($subpattern[1] as $configline) {
$expression = explode("=", $configline, 2);
$config[$expression[0]]=$expression[1];
}
}

//now you can get your config-values like this:
$groupByString = $config['groupBy'];


i hope, this helps someone!

Guerric
11-10-2008, 06:07 PM
Content transformations do support additional arguments. Here's how:

With 1 arg (default):

<table function="tabletool.formatTable" class="script">

With multiple args:

<table function="tabletool.formatTable($, 1, 2, 3)" class="script">

The dollar sign ($) represents the contents of the element.

jeff
11-11-2008, 08:32 AM
ok, thanks!

now i'm happy :rolleyes:

SteveB
11-24-2008, 11:22 PM
jeff,

Do you have a wik page about your tabletool.formatTable function? Sounds like this might be something that others could learn from!