• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item6085: FilterPlugin documentation - examples reworked

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Extension FilterPlugin Low Closed   n/a  

Edit Form Data

Summary:
Reported By:
Codebase:
Applies To:
Component:
Priority:
Current State:
Waiting For:
Target Release:
Released In:
 

Detail

I had no idea how much easier table extracts were with TWiki:Plugins.FilterPlugin until I saw TWiki:Blog.BlogEntry200808x7. In some ways, the blog described the plugin better than its home page. smile As KennethLavrsen indicated on 19 Jan 2007 in TWiki:Plugins.FilterPluginDev, it was hard to see what the plugin does. In part, this is because no simulated output was provided. But even after the plugin is installed, I had to switch between the raw and rendered views to understand what was going on.

Changes:

  • Added sections like "You Type:", "Expected result (simulated)", and "Actual Result (this site)", stealing that idea from TWiki:Plugins.RenderListPlugin and TWiki:Plugins.DirectedGraphPlugin, (among others). That way the plugin page is still a useful reference after installation (and it's also easier to compare the expected and actual rendering, for installation test cases).
  • The headings now clearly indicate what feature is being demonstrated (and arranged them alphabetically)
  • I found the "Safe HTML" example to be particularly terse. I added a few words as to what was done, and why it's useful.
  • I replaced the MAKEINDEX example with a shorter list, and only two columns instead of 3 to try fit in both the simulation and rendered versions (the image attached to the dev topic is required for that example).

Other comments:

  • FORMATLIST has no example, and I'm still not clear on what you could with it. A little help?
  • I probably broke whatever the %STARTINCLUDE%/%STOPINCLUDE% was being used for in the current version, so I simply removed it from this revision.
  • By the way, in "EXTRACT example 2", header needs $n at the end: is that a bug?



Examples

EXTRACT Example 1: "Convert Table into Text"

One of the uses of this plugin is to extract data from tables, which is useful for creating "database-like" TWiki applications. While it is certainly possible to do that without this plugin (see "Pattern 1: Extract values from a table" in SearchPatternCookbook), the plugin makes these requests easier to create and maintain. For another example, see TWiki:Blog.BlogEntry200808x7.

The table:

Pos Description Hours
1 onsite troubleshooting 3
2 normalizing data to new format 10
3 testing server performance 5

You type:

%EXTRACT{topic="%TOPIC%" expand="off" 
  pattern="^\|\s\s(.*?)\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|" 
  format="   * it took $3 hours $2$n"
  skip="1"
}% 

Expected result (simulated): Actual result (this site):
  • it took 3 hours onsite troubleshooting
  • it took 10 hours normalizing data to new format
  • it took 5 hours testing server performance
%EXTRACT{topic="Item6085" expand="off" pattern="^\|\s\s(.*?)\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|" format=" * it took $3 hours $2$n" skip="1" }%

EXTRACT Example 2: "Convert Text into Table"

Use CSS tags to format text comments as a tabular data (e.g., to allow sorting).

The comments:

This is the first comment.
-- TWiki:Main.MichaelDaum on 22 Aug 2005

This is the second comment.
-- TWiki:Main.MichaelDaum on 22 Aug 2005

You type:

%EXTRACT{
   topic="%TOPIC%" expand="off"
   pattern=".div class=\"text\">.*?[\r\n]+(.*?)[\r\n]+(?:.*?[\r\n]+)+?-- (.*?) on (.*?)[\r\n]+"
   format="| $3 | $2 | $1 ... |$n" header="|*Date*|*Author*|*Headline*|$n"
}%

Expected result (simulated): Actual result (this site):
Date Author Headline
22 Aug 2005 TWiki:Main.MichaelDaum This is the first comment. ...
22 Aug 2005 TWiki:Main.MichaelDaum This is the second comment. ...
%EXTRACT{topic="Item6085" expand="off" pattern=".div class=\"text\">.*?[\r\n]+(.*?)[\r\n]+(?:.*?[\r\n]+)+?-- (.*?) on (.*?)[\r\n]+" format="| $3 | $2 | $1 ... |$n" header="|*Date*|*Author*|*Headline*|$n" }%

FORMATLIST example

(example needed. Maybe use TWiki:Support.FormattingFieldValues).

MAKEINDEX example

Create an index of TWiki web (for brevity, this demonstration uses only a small subset of the web):

You type:

%MAKEINDEX{
   "%SEARCH{".*" web="%SYSTEMWEB%" scope="topic" type="regex" limit="30" nonoise="on" format="$topic" separator=", " excludetopic="CGI*,*Plugin"}%" 
   cols="2"
   format="[[TWiki/$item][$item]]"
}% 

Expected result (simulated): Actual result (this site):

SimulatedMAKEINDEX.png
%MAKEINDEX{ "ATasteOfTWiki, AccessKeys, AdminDocumentationCategory, AdminSkillsAssumptions, AdminToolsCategory, AdministrationVariables, AllowWebCreateByUserMappingManager, AnApplicationWithWikiForm, AppendixEncodeURLsWithUTF8, ApplicationsAndComponentsVariables, AttachmentsAndFilesVariables, AutonomousWebs, BackupRestoreConsole, BehaviourContrib, BookView, BulkRegistration, BumpyWord, CategoryCategory, ChangeEmailAddress, ChartingAndDrawingVariables, ClassMethod, CommentPluginExamples, CommentPluginTemplate, CopyingTopics, CustomUserGroupNotations, DatabaseAndFormsVariables, DateAndTimeVariables, DeleteOrRenameATopic, DeleteOrRenameAnAttachment, DeveloperDocumentationCategory" cols="2" format="$item" }%

SUBST example: "Safe HTML"

Use %STARTSUBST%/%STOPSUBST% to disable potentially annoying or dangerous Javascript in user provided content.

You type:

%STARTSUBST{pattern="<(a href=\"javascript:.*?)>(.*?)</a>" format="<$1>$2</a>"}%
<a href="javascript:window.alert('Pop me up');">Pop me up</a>
%STOPSUBST% 

If not installed (simulated):

Pop me up

Expected result (simulated): Actual result (this site):
<a href="javascript:window.alert('Pop me up');">Pop me up</a> %STARTSUBST{pattern="<(a href=\"javascript:.*?)>(.*?)" format="<$1>$2</a>"}% Pop me up %STOPSUBST%

Looks great! Have a checkin.

-- TWiki:Main.MichaelDaum - 23 Oct 2008

Thanks.

I have requested SVN access: TWiki:Codev.SeanCMorganWouldLikeToCheckIn

-- TWiki:Main.SeanCMorgan - 27 Oct 2008

ItemTemplate
Summary FilterPlugin documentation - examples reworked
ReportedBy TWiki:Main.SeanCMorgan
Codebase 4.2.3
SVN Range TWiki-5.0.0, Sun, 05 Oct 2008, build 17588
AppliesTo Extension
Component FilterPlugin
Priority Low
CurrentState Closed
WaitingFor

Checkins

TargetRelease n/a
ReleasedIn

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2008-10-29 - SeanCMorgan
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback