Skip to content

Commit

Permalink
Item13905: Merge branch 'Item13905'
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed May 2, 2017
2 parents 796ecf3 + b80f83f commit 7f103a0
Show file tree
Hide file tree
Showing 19 changed files with 297 additions and 169 deletions.
4 changes: 2 additions & 2 deletions PatternSkin/data/System/WebLeftBarPersonalTemplate.txt
Expand Up @@ -4,8 +4,8 @@
Customise this topic; samples and ideas available at %SYSTEMWEB%.WebLeftBarCookbook.
-->
*My links:*
* [[%TMPL:WIKIUSERNAME%][My home page]]
* [[%SCRIPTURLPATH{search}%/%BASEWEB%/?search=%TMPL:WIKINAME%;order=modified;limit=50;reverse=on][My %BASEWEB% activities]]
* [[%CREATE:WIKIUSERNAME%][My home page]]
* [[%SCRIPTURLPATH{search}%/%BASEWEB%/?search=%CREATE:WIKINAME%;order=modified;limit=50;reverse=on][My %BASEWEB% activities]]
*
<a class="foswikiSmallish" href="%SCRIPTURLPATH{"edit"}%/%WEB%/%TOPIC%?t=%GM%NOP%TIME{"$epoch"}%">edit</a>

4 changes: 2 additions & 2 deletions TipsContrib/data/System/TipsOfTheDayTemplate.txt
@@ -1,10 +1,10 @@
%META:TOPICINFO{author="ProjectContributor" date="1452261257" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1487619523" format="1.1" version="1"}%
%META:TOPICPARENT{name="TipsOfTheDayAdmin"}%
---+ Heading

Quick Summary with link to more information.

[[%SYSTEMWEB%.TipsOfTheDay][See More Tips...]]

-- %TMPL:WIKIUSERNAME% - %TMPL:DATE%
-- %CREATE:WIKIUSERNAME% - %CREATE:DATE%

4 changes: 2 additions & 2 deletions TopicUserMappingContrib/data/Main/GroupTemplate.txt
@@ -1,8 +1,8 @@
%META:TOPICINFO{author="ProjectContributor" date="1287695166" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1487619533" format="1.1" version="1"}%
%META:TOPICPARENT{name="WikiGroups"}%

Edit this topic to add a description to the !%URLPARAM{"topic"}%

%META:PREFERENCE{name="GROUP" title="GROUP" value=""}%
%META:PREFERENCE{name="VIEW_TEMPLATE" title="VIEW_TEMPLATE" value="GroupView"}%
%META:PREFERENCE{name="ALLOWTOPICCHANGE" title="ALLOWTOPICCHANGE" type="Set" value="%URLPARAM{"topic"}%"}%
%META:PREFERENCE{name="ALLOWTOPICCHANGE" title="ALLOWTOPICCHANGE" type="Set" value="%CREATE:URLPARAM{"topic"}%"}%
4 changes: 2 additions & 2 deletions TopicUserMappingContrib/data/System/NewUserTemplate.txt
@@ -1,12 +1,12 @@
%META:TOPICINFO{author="ProjectContributor" date="1418937051" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1487619523" format="1.1" version="1"}%
%META:TOPICPARENT{name="WikiUsers"}%
---+ <nop>%TOPIC%

%SPLIT%
* %KEY%: %VALUE%%SPLIT%

<!--
* Set ALLOWTOPICCHANGE = %WIKIUSERNAME%
* Set ALLOWTOPICCHANGE = %CREATE:WIKIUSERNAME%
-->


Expand Down
18 changes: 18 additions & 0 deletions UnitTestContrib/test/unit/SkinTemplatesTests.pm
Expand Up @@ -742,4 +742,22 @@ sub test_TMPL_PREV {
return;
}

sub test_comments {
my $this = shift;
my $data;

write_template(
'yview', '%TMPL:%{goway}%DEF{"junk"}%A
%{die}%
B%TMPL:END%%TMPL:P{junk}%-%TMPL:%{goway}%DEF{"clunk"}%C #{die}# D%TMPL:END%%TMPL:P{clunk}%'
);

$data = $tmpls->readTemplate('yview');
$this->assert_str_equals( 'AB-C D', $data );

return;
}

1;
83 changes: 71 additions & 12 deletions UnitTestContrib/test/unit/TopicTemplatesTests.pm
Expand Up @@ -226,23 +226,22 @@ sub test_templateTopicWithAttachments {
return;
}

sub test_templateTopicWithMacros {
my $this = shift;
sub test_templateTopicWithEOTCMacros {
my $this = shift;
$Foswiki::cfg{DisableEOTC} = 0;
my $query = Unit::Request->new(
{
text => [<<'TEXT'],
* NOP: No%NOP%Link
* DATE: %DATE%
* TMPL:DATE: %TMPL:DATE%
* CREATE:DATE: %CREATE:DATE%
* GMTIME: %GMTIME%
* SERVERTIME: %SERVERTIME%
* USERNAME: %USERNAME%
* TMPL:USERNAME: %TMPL:USERNAME%
* URLPARAM: %URLPARAM{"purple"}%
* WIKINAME: %WIKINAME%
* WIKIUSERNAME: %WIKIUSERNAME%
* TMPL:IF: %TMPL:IF{"1=1" then="OK" else="BAD"}%
* TMPL:P:%TMPL:P{"sep"}%
* NOP: No%NOP%Link
* COMMENT: #{ ... comment }#
%STARTSECTION{type="templateonly"}%
Mither me not
%ENDSECTION{type="templateonly"}%
Expand All @@ -268,23 +267,21 @@ TEXT
$this->createNewFoswikiSession( $this->{test_user_login}, $query );
my ( $responseText, $result, $stdout, $stderr ) =
$this->captureWithKey( save => $UI_FN, $this->{session} );

print STDERR $stderr;
my ($meta) =
Foswiki::Func::readTopic( $this->{test_web}, 'TemplatedTopic' );
my $text = $meta->text;
$this->assert( $text =~ s/^\s*\* DATE: \d+ \w+ \d+$//m, $text );
$this->assert( $text =~ s/^\s*\* TMPL:DATE: \d+ \w+ \d+$//m, $text );
$this->assert( $text =~ s/^\s*\* CREATE:DATE: \d+ \w+ \d+$//m, $text );
$this->assert( $text =~ s/^\s*\* GMTIME: \d+ \w+ \d+ - \d+:\d+$//m, $text );
$this->assert( $text =~ s/^\s*\* SERVERTIME: \d+ \w+ \d+ - \d+:\d+$//m,
$text );
$this->assert( $text =~ s/^\s*\* USERNAME: scum$//m, $text );
$this->assert( $text =~ s/^\s*\* TMPL:USERNAME: scum$//m, $text );
$this->assert( $text =~ s/^\s*\* WIKINAME: ScumBag$//m, $text );
$this->assert( $text =~ s/^\s*\* WIKIUSERNAME: \w+\.ScumBag$//m, $text );
$this->assert( $text =~ s/^\s*\* URLPARAM: ok$//m, $text );
$this->assert( $text =~ s/^\s*\* NOP: NoLink$//m, $text );
$this->assert( $text =~ s/^\s*\* TMPL:IF: OK$//m, $text );
$this->assert( $text =~ s/^\s*\* TMPL:P: \| $//m, $text );
$this->assert( $text =~ s/^\s*\* COMMENT: $//m, $text );
$this->assert( $text =~ s/^TemplatedTopic$//m, $text );
$this->assert( $text =~ s/^%TOPIC%$//m, $text );
$this->assert( $text !~ /Mither me not/s, $text );
Expand All @@ -295,4 +292,66 @@ TEXT
return;
}

sub test_templateTopicWithCREATEMacros {
my $this = shift;
$Foswiki::cfg{DisableEOTC} = 1;
my $query = Unit::Request->new(
{
text => [<<'TEXT'],
* NOP: No%NOP%Link
* DATE: %DATE%
* CREATE:DATE: %CREATE:DATE%
* CREATE:USERNAME: %CREATE:USERNAME%
* CREATE:URLPARAM: %CREATE:URLPARAM{"purple"}%
* URLPARAM: %URLPARAM{"purple"}%
* COMMENT: %{ ... comment }%
* CREATE:IF: %CREATE:IF{"1=1" then="OK" else="BAD"}%
%STARTSECTION{type="templateonly"}%
Mither me not
%ENDSECTION{type="templateonly"}%
%STARTSECTION{type="expandvariables"}%
%TOPIC%
%ENDSECTION{type="expandvariables"}%
%TOPIC%
TEXT
action => ['save'],
topic => [ $this->{test_web} . '.TemplateTopic' ]
}
);
$this->createNewFoswikiSession( $this->{test_user_login}, $query );
$this->captureWithKey( save => $UI_FN, $this->{session} );
$query = Unit::Request->new(
{
templatetopic => ['TemplateTopic'],
action => ['save'],
purple => ['ok'],
topic => [ $this->{test_web} . '.TemplatedTopic' ]
}
);
$this->createNewFoswikiSession( $this->{test_user_login}, $query );
my ( $responseText, $result, $stdout, $stderr ) =
$this->captureWithKey( save => $UI_FN, $this->{session} );
print STDERR $stderr;
my ($meta) =
Foswiki::Func::readTopic( $this->{test_web}, 'TemplatedTopic' );
my $text = $meta->text;
$this->assert( $text =~ s/^\s*\* DATE: %DATE%$//m, $text );
$this->assert( $text =~ s/^\s*\* CREATE:DATE: \d+ \w+ \d+$//m, $text );
$this->assert( $text =~ s/^\s*\* CREATE:USERNAME: scum$//m, $text );
$this->assert( $text =~ s/^\s*\* CREATE:URLPARAM: ok$//m, $text );
$this->assert( $text =~ s/^\s*\* URLPARAM: %URLPARAM\{"purple"\}%$//m,
$text );
$this->assert( $text =~ s/^\s*\* NOP: NoLink$//m, $text );
$this->assert( $text =~ s/^\s*\* CREATE:IF: OK$//m, $text );
$this->assert( $text =~ s/^\s*\* COMMENT: %\{ ... comment \}%$//m, $text );
$this->assert( $text =~ s/^TemplatedTopic$//m, $text );
$this->assert( $text =~ s/^%TOPIC%$//m, $text );
$this->assert( $text !~ /Mither me not/s, $text );
$text =~ s/\s+//gs;
$this->assert_equals( "", $text );
$meta->finish();

return;
}

1;
10 changes: 7 additions & 3 deletions UnitTestContrib/test/unit/VariableTests.pm
Expand Up @@ -70,6 +70,7 @@ sub test_embeddedExpansions {
return;
}

# SMELL: this duplicates TopicTemplatesTests
sub test_topicCreationExpansions {
my $this = shift;

Expand Down Expand Up @@ -146,22 +147,24 @@ sub test_macroParams {
# Check default given, given but null, not given
# Check quotes and other standard expansions
# Check override of standard macros
# Check comment #{...}# expansion in difficult sites
$this->{session}->{prefs}->setSessionPreferences(
ARFLE => '%BARFLE{default="gloop"}%',
TING => '%DEFAULT% %DEFAULT{default="tong"}%',
ALING => '\'%DEFAULT%\' \'%DEFAULT{default="tong"}%\'',
ALING => '\'%DEF#{i}#AULT%\' \'%DEFAULT{#{i}#default="tong"}%\'',
TOOT => '\'%NOP%\'',
WOOF => '%MIAOW{default="$quot$percent$quot"}%',
Test => '"%arg{default="%DEFAULT{default="Y"}%"}%"'
);
my $input = <<'INPUT';
| gloop | %BARFLE{default="gloop"}% |
| C | #{ ignore me }# |#{i}#
| gloop | %BARFLE{def#{i}#ault="gloop"}% |
| mong | %ARFLE{BARFLE="mong"}% |
| %DEFAULT% tong | %TING% |
| ding ding | %TING{"ding"}% |
| '' '' | %ALING{""}% |
| 'sweet' | %TOOT{NOP="sweet"}% |
| "%" | %WOOF% |
| "%" | %#{i}#WOOF#{i}#% |
| p"r"r | %WOOF{MIAOW="p$quot()r$quot()r"}% |
| Test | %Test% |
| Test{"X"} | %Test{"X"}% |
Expand All @@ -172,6 +175,7 @@ INPUT
$topicObject->text($input);
my $result = $topicObject->expandMacros($input);
my $expected = <<'EXPECTED';
| C | |
| gloop | gloop |
| mong | mong |
| %DEFAULT% tong | %DEFAULT% tong |
Expand Down
7 changes: 7 additions & 0 deletions core/data/System/EditingShorthand.txt
Expand Up @@ -784,6 +784,13 @@ required
---++!! offset was 1, so offset is now 0
</td>
</tr>
<tr>
<td>
=#<nop>{ ... comment ... }<nop>#=
</td><td>
*Comments:* %BR%
Comments will be removed from content before the topic is displayed.
</td>
</table>
<!-- %JQREQUIRE{"chili"}% -->

Expand Down
4 changes: 2 additions & 2 deletions core/data/System/ExampleTopicTemplate.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1452261257" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1487619523" format="1.1" version="1"}%
(just an example illustrating how to create a new topic based on a specific template topic. TemplateTopics has more)

-- %TMPL:WIKIUSERNAME% - %TMPL:DATE%
-- %CREATE:WIKIUSERNAME% - %CREATE:DATE%
4 changes: 2 additions & 2 deletions core/data/System/FAQTemplate.txt
@@ -1,6 +1,6 @@
%META:TOPICINFO{author="ProjectContributor" date="1452261257" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1487619523" format="1.1" version="1"}%
%META:TOPICPARENT{name="FrequentlyAskedQuestions"}%
The answer is...

-- %TMPL:WIKIUSERNAME% - %TMPL:DATE% <br />
-- %CREATE:WIKIUSERNAME% - %CREATE:DATE% <br />
%META:FORM{name="FAQForm"}%
3 changes: 3 additions & 0 deletions core/data/System/Macros.txt
Expand Up @@ -515,6 +515,9 @@ This gives:
header+="|"
format+="|"
}%
---++ Comments

You can add comments anywhere in macros (and outside them) using the standard =#<nop>{...}<nop>#= comment delimiters. Comments are removed *before* any macros are processed, so you can't use macros to generate comments. Any macros inside comments will be ignored.

%STOPINCLUDE%

Expand Down
52 changes: 39 additions & 13 deletions core/data/System/SkinTemplates.txt
Expand Up @@ -45,14 +45,15 @@ Template directives look a lot like standard [[macros]].
* =%<nop>TMPL:END%= ends a block definition.
* =%<nop>TMPL:PREV%=: returns the previous definition of the block being defined.
* =%<nop>TMPL:P{"name"}%= includes a previously defined block.
* =%<nop>{...}%= is a comment. Whitespace either side of the comment
* =#<nop>{...}#= is a comment. Whitespace either side of the comment
(newlines, spaces, tabs etc) is treated as part of the comment, and
removed when the comment is removed.
removed when the comment is removed. An alternate syntax =%<nop>{...}%=
is also supported - see #Comments below for why.
You can use a block before _or_ after declaring it. If you define the same
block twice, only the second definition is used.

<div class="foswikiHelp">
%X% Most template directives work only for templates: they do not get processed in normal topic text. The one exception is =TMPL:P=, which is expanded in normal text (and also when a TopicTemplate is expanded).
%X% Most template directives work only for templates: they do not get processed in normal topic text. The one exception is =%TMPL:P=.
</div>

---+++ Parameters to blocks
Expand Down Expand Up @@ -95,15 +96,11 @@ then
</verbatim>
will expand to =x1000z=.


---++++ Naming
Any alphanumeric characters can be used in parameter names. =TMPL:P= parameters
override any other possible definition of the name, so you should not use
parameter names that might clash with [[Macros]].




---+++ Conditional expansion
---++++ Using context identifiers
Three parameter names, =context=, =then= and =else= are *reserved*.
Expand Down Expand Up @@ -162,9 +159,32 @@ and then =* Set SKIN=crumbless,pattern=
Remember: the template path contains the most specific template first.

---+++ Comments
Comments =%{...}%= are removed from the templates as soon as the file is
read, before any other template macros are evaluated. Whitespace either side
of the comment (newlines, spaces, tabs etc) is also removed.
Comments delimited by =#{...}#= are removed from the templates as soon as
the file is read, before any other template macros are evaluated.

An alternative comment type =#{...}#= will automatically absorb whitespace
either side of the comment (newlines, spaces, tabs etc). This type of comment
only works in templates.

The alternative comment type becomes really useful when we have skin templates defined in topics, because we can now use it to delimit content that should be _displayed when the topic is viewed normally_, but _removed when the templates are instantiated_.

or example, we might have templates in a topic like this:
<verbatim class="tml">
%TMPL:DEF{"example"}%
#{ This comment will always be removed }%
%{ This comment will be removed when the template is instantiated }%
Example
%TMPL:END%
</verbatim>

When we view the topic, we'll see:

%<nop>TMPL:DEF{"example"}%
#{ This comment will always be removed }%
%{ This comment will be removed when the template is instantiated }%
Example
%<nop>TMPL:END%
but all comments will be removed when the template is actually used.

#FindingTemplates
---++ Finding Skin Templates
Expand Down Expand Up @@ -199,15 +219,15 @@ The rules defined by the out-of-the-box setting of ={TemplatePath}= are:
7 =$web.$nameTemplate=
8 =%SYSTEMWEB%.$nameTemplate=
For example, let's say we are viewing a topic in web =%SANDBOXWEB%= and are searching for the template called =function=. The skin path is set to =custom,pattern=. The following locations will be considered in turn, until a template is found:
1 :skull: =templates/%SANDBOXWEB%/function.custom.tmpl= _(rule 1)_
1 :skull: =templates/%SANDBOXWEB%/function.pattern.tmpl= _(rule 1)_
1 =templates/%SANDBOXWEB%/function.custom.tmpl= _(rule 1)_ :skull:
1 =templates/%SANDBOXWEB%/function.pattern.tmpl= _(rule 1)_ :skull:
2 =templates/function.custom.tmpl= _(rule 2)_
2 =templates/function.pattern.tmpl= _(rule 2)_
3 =%SANDBOXWEB%.CustomSkinFunctionTemplate= _(rule 3)_
3 =%SANDBOXWEB%.PatternSkinFunctionTemplate= _(rule 3)_
4 =%SYSTEMWEB%.CustomSkinFunctionTemplate= _(rule 4)_
4 =%SYSTEMWEB%.PatternSkinFunctionTemplate= _(rule 4)_
5 :skull: =templates/%SANDBOXWEB%/function.tmpl= _(rule 5)_
5 =templates/%SANDBOXWEB%/function.tmpl= _(rule 5)_ :skull:
6 =templates/function.tmpl= _(rule 6)_
7 =%SANDBOXWEB%.FunctionTemplate= _(rule 7)_
8 =%SYSTEMWEB%.FunctionTemplate= _(rule 8)_
Expand Down Expand Up @@ -254,6 +274,12 @@ Note that topics containing templates are checked for VIEW access using the
normal [[AccessControl][Foswiki access controls]]. Any access control failure
is silently ignored, and the template path expansion continues.

---++ Predefined templates
Most predefined templates are stored in =.tmpl= files. There are also a
couple of standard topics that contain skin templates:
* WebCreateNewTopicTemplate - Page shown when you click on a %ICON{newtopic}% *Create New Topic* link. It provides a form requesting the necessary information to create a new, nonexistent topic.
* TopicDoesNotExistViewTemplate - Alert page shown when you try to view a nonexistent topic and usually used as a prompt to help you create this new topic. For this reason, the form of the WebCreateNewTopicTemplate is included and therefore shown, too.

---++ Developing new templates
---+++ Debugging
When writing new templates, it can sometimes it can be hard to work out
Expand Down

0 comments on commit 7f103a0

Please sign in to comment.