This question about Topic Markup Language and applications: Answered
Show preferences in a table
Hi irc0,
You reported on 21 Dec 2018 11:19pm that:
%TOPICLIST{format="| $web.$topic | $percntEXPAND{\"$dollarpercentSHOWPREFERENCE{\\"ALLOWTOPICCHANGE\\"}$dollarpercent\" scope=\"$topic\"}$percnt |"}%
"does not work". It does work on my Foswiki and produces:
I am not sure what problem you are trying to solve, but here is the solution to the problem I believe you are trying to solve. The use of parametrised INCLUDEs makes the development of these kind of functions a lot easier. There is often not as much to escape. And you can test them incrementally as well. I hope this example helps.
Problem
Create a table that lists for each topic in a web where a particular preference is defined. Something like:
Solution
- use SHOWPREFERENCES to display where a preference is defined and how.
- use EXPAND with topic= to show the preference definition for a particular topic
- use TOPICLIST with web= to list the topics in a web
- use vertical bars to define the table
Example implementations follow.
NOTE: For this example I have replaced TOPICLIST by SEARCH. SEARCH allows me to control what topics are inspected and the list is a bit shorter.
Instead of this: %TOPICLIST{ format="..." }%
Use %SEARCH{ "1" topic="K*" nonoise="on" format="..." }% <=== limit topics to those starting with K
Delete topic="K*" to get the complete topic list.
Implementation 0
Get the preference for the topic
First we need to get the definition of the preference for a given topic
%STARTSECTION{ "get_preference_for_topic" }%
%EXPAND{
"$percentSHOWPREFERENCE{
\"%thePREFERENCE%\"
}$percent"
scope="%theTOPIC%"
}%
%ENDSECTION{ "get_preference_for_topic" }%
%INCLUDE{ "%TOPIC%" section="get_preference_for_topic" thePREFERENCE="ALLOWTOPICCHANGE" theTOPIC="%TOPIC%" }%
gives the result:
- Set ALLOWTOPICCHANGE = "%USERSWEB%.MaintainGroup"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
Make the table row content
That's pretty close, but it will never fit in a table row, because there cannot be a new line in a table row. You can use ENCODE to change the new line to a +:
%STARTSECTION{ "make_the_table_row_content" }%
%ENCODE{
"%INCLUDE{
"%TOPIC%"
section="get_preference_for_topic"
thePREFERENCE="%thePREFERENCE%"
theTOPIC="%theTOPIC%"
}%"
old="$n,\""
new="+,\\""
}%
%ENDSECTION{ "make_the_table_row_content" }%
+ * Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"+ * ALLOWTOPICCHANGE was defined in Support.WebPreferences++
Make the table row
So now you have all the ingredients to make a table row. And we can spruce up the ENCODE to make it all happen. around the
- First we replace the new line with nothing instead of a plus
- Then we add the vertical bars around the text we are encoding
- And we add an extra column with the topic name
%STARTSECTION{ "make_the_table_row" }%
%ENCODE{
"| %theTOPIC% | %INCLUDE{
"%TOPIC%"
section="get_preference_for_topic"
thePREFERENCE="%thePREFERENCE%"
theTOPIC="%theTOPIC%"
}% |"
old="$n,\""
new=",\\""
}%
%ENDSECTION{ "make_the_table_row" }%
Question1974 |
* Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\" * ALLOWTOPICCHANGE was defined in Support.WebPreferences |
System |
* Set ALLOWTOPICCHANGE = \"%USERSWEB%.AdminGroup\" * ALLOWTOPICCHANGE was defined in System.WebPreferences |
Alternative, using the table row tag
The solution above thoroughly screws up the format of SHOWPREFERENCE to cater for the idiosyncrasies of the Foswiki table construct. Instead we could use real table tags and forget about the flattening. We still need to escape the quote using ENCODE,
%STARTSECTION{ "make_the_table_row_with_tag" }%%ENCODE{
"<tr><td> %theTOPIC% </td><td> %INCLUDE{
"%TOPIC%"
section="get_preference_for_topic"
thePREFERENCE="%thePREFERENCE%"
theTOPIC="%theTOPIC%"
}% </td></tr>"
old="\""
new="\\""
}%%ENDSECTION{ "make_the_table_row_with_tag" }%
Question1974 |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
|
System |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.AdminGroup\"
- ALLOWTOPICCHANGE was defined in System.WebPreferences
|
The list of all topics and their defined preference
Now use
make_the_table_row_with_tag
to create one row for each topic:
%STARTSECTION{ "preference_definition_by_topic" }%
<table>
%SEARCH{ "1" topic="K*" nonoise="on"
format="$percentINCLUDE{ \"%TOPIC%\" section=\"make_the_table_row_with_tag\" theTOPIC=\"$web.$topic\" thePREFERENCE=\"%thePREFERENCE%\" }$percent"
separator=""
}%
</table>
%ENDSECTION{ "preference_definition_by_topic" }%
KinoSearchContrib |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
|
KinoSearchPlugin |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
|
KnownIssues |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
|
KnownIssuesOfFoswiki01x00 |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
|
KnownIssuesOfFoswiki01x01 |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
|
KnownIssuesOfFoswiki02x00 |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
|
KnownIssuesOfFoswiki02x01 |
- Set ALLOWTOPICCHANGE = \"%USERSWEB%.MaintainGroup\"
- ALLOWTOPICCHANGE was defined in Support.WebPreferences
|
Implementation 1
There is an alternative implementation that gives much better control over the formatting. But you need to install
FilterPlugin.
FilterPlugin supports the refomatting of any string. You start from the Table row content created previously. And then you extract what you need and reformat it.
" + * Set ALLOWTOPICCHANGE = \"%USERSWEB%.AdminGroup\"+ * ALLOWTOPICCHANGE was defined in Sandbox.WebPreferences++ " <=== example text to develop regex against
%STARTSECTION{ "formatted_table_row" }%%EXTRACT{
text="%INCLUDE{ "%TOPIC%" section="make_the_table_row_content" }%"
pattern="Set\s*([^\s=]+)[\s=]+([^+]*)\+.*?defined in\s*([^+]*)"
format="| [[%theTOPIC%][%theTOPIC%]] | $1 | $2 | $3 |"
}%%ENDSECTION{ "formatted_table_row" }%
%STARTSECTION{ "example1" }%
| *Topic* | *uses Preference* | *with Value* | *Defined in* |
%INCLUDE{ "%TOPIC%" section="formatted_table_row" thePREFERENCE="ALLOWTOPICCHANGE" theTOPIC="%TOPIC%" }%
%INCLUDE{ "%TOPIC%" section="formatted_table_row" thePREFERENCE="ALLOWTOPICCHANGE" theTOPIC="System.WebPreferences" }%
%ENDSECTION{ "example1" }%
gives the result:
Topic |
uses Preference |
with Value |
Defined in |
Question1974 |
ALLOWTOPICCHANGE |
"%USERSWEB%.MaintainGroup" |
Support.WebPreferences |
System.WebPreferences |
ALLOWTOPICCHANGE |
"%USERSWEB%.AdminGroup" |
System.WebPreferences |
The complete list is obtained in the same way as in Implementation 0. But this time the row data is obtained from section
formatted_table_row
instead of section
make_the_table_row_with_tag
.
%STARTSECTION{ "fully_formatted_list_by_topic" }%
| *Topic* | *uses Preference* | *with Value* | *Defined in* |
%SEARCH{ "1" topic="K*" nonoise="on"
format="$percentINCLUDE{ \"%TOPIC%\" section=\"formatted_table_row\" theTOPIC=\"$web.$topic\" thePREFERENCE=\"%thePREFERENCE%\" }$percent"
separator="$n"
}%
%ENDSECTION{ "fully_formatted_list_by_topic" }%
--
BramVanOosterhout - 05 Jan 2019