Skip to content

Commit

Permalink
Add "cascade" filter run prefix and use it to control view templates (#…
Browse files Browse the repository at this point in the history
…6168)

* Initial Commit

* Set currentTiddler and ..currentTiddler for filter evaulation

* Precompile the filters for performance

* Add explicit test for empty result when no filter passes

* Use the cascade filter run prefix to choose the view template body template

* Use the cascade mechanism to choose between the edit and view templates

* Simplify cascade filter

Thanks @saqimtiaz

* Add control panel UI for inspecting the template cascades

* Refactor import listing and plugin listing as alternate body templates

As suggested by @pmario

* Refer to $:/core/ui/{View|Edit}Template via their associated config tiddlers

* Fix typo in previous commit

* Add demo of custom story tiddler template

* Tweak control panel wording

* Standardise "Story Tiddler Template" nomenclature

* Add a cascade for the editor template body

* Add a cascade for the view template title

* Avoid unwanted whitespace

* Add a cascade for dynamically choosing tiddler icons
  • Loading branch information
Jermolene committed Nov 15, 2021
1 parent 9caba54 commit a350a76
Show file tree
Hide file tree
Showing 44 changed files with 394 additions and 107 deletions.
13 changes: 13 additions & 0 deletions core/language/en-GB/ControlPanel.multids
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ Basics/Tiddlers/Prompt: Number of tiddlers
Basics/Title/Prompt: Title of this ~TiddlyWiki
Basics/Username/Prompt: Username for signing edits
Basics/Version/Prompt: ~TiddlyWiki version
Cascades/Caption: Cascades
Cascades/Hint: These global rules are used to dynamically choose certain templates. The result of the cascade is the result of the first filter in the sequence that returns a result
Cascades/TagPrompt: Filters tagged <$macrocall $name="tag" tag=<<currentTiddler>>/>
EditorTypes/Caption: Editor Types
EditorTypes/Editor/Caption: Editor
EditorTypes/Hint: These tiddlers determine which editor is used to edit specific tiddler types.
EditorTypes/Type/Caption: Type
EditTemplateBody/Caption: Edit Template Body
EditTemplateBody/Hint: This rule cascade is used by the default edit template to dynamically choose the template for editing the body of a tiddler.
Info/Caption: Info
Info/Hint: Information about this TiddlyWiki
KeyboardShortcuts/Add/Prompt: Type shortcut here
Expand Down Expand Up @@ -191,6 +196,8 @@ Settings/TitleLinks/Yes/Description: Display tiddler titles as links
Settings/MissingLinks/Caption: Wiki Links
Settings/MissingLinks/Hint: Choose whether to link to tiddlers that do not exist yet
Settings/MissingLinks/Description: Enable links to missing tiddlers
StoryTiddler/Caption: Story Tiddler
StoryTiddler/Hint: This rule cascade is used to dynamically choose the template for displaying a tiddler in the story river.
StoryView/Caption: Story View
StoryView/Prompt: Current view:
Stylesheets/Caption: Stylesheets
Expand All @@ -201,6 +208,8 @@ Theme/Caption: Theme
Theme/Prompt: Current theme:
TiddlerFields/Caption: Tiddler Fields
TiddlerFields/Hint: This is the full set of TiddlerFields in use in this wiki (including system tiddlers but excluding shadow tiddlers).
TiddlerIcon/Caption: Tiddler Icon
TiddlerIcon/Hint: This rules cascade is used to dynamically choose the icon for a tiddler.
Toolbars/Caption: Toolbars
Toolbars/EditToolbar/Caption: Edit Toolbar
Toolbars/EditToolbar/Hint: Choose which buttons are displayed for tiddlers in edit mode. Drag and drop to change the ordering
Expand All @@ -212,3 +221,7 @@ Toolbars/EditorToolbar/Hint: Choose which buttons are displayed in the editor to
Toolbars/ViewToolbar/Caption: View Toolbar
Toolbars/ViewToolbar/Hint: Choose which buttons are displayed for tiddlers in view mode. Drag and drop to change the ordering
Tools/Download/Full/Caption: Download full wiki
ViewTemplateBody/Caption: View Template Body
ViewTemplateBody/Hint: This rule cascade is used by the default view template to dynamically choose the template for displaying the body of a tiddler.
ViewTemplateTitle/Caption: View Template Title
ViewTemplateTitle/Hint: This rule cascade is used by the default view template to dynamically choose the template for displaying the title of a tiddler.
51 changes: 51 additions & 0 deletions core/modules/filterrunprefixes/cascade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*\
title: $:/core/modules/filterrunprefixes/cascade.js
type: application/javascript
module-type: filterrunprefix
\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Export our filter prefix function
*/
exports.cascade = function(operationSubFunction,options) {
return function(results,source,widget) {
if(results.length !== 0) {
var filterList = operationSubFunction(source,widget),
filterFnList = [];
var inputResults = results.toArray();
results.clear();
$tw.utils.each(inputResults,function(title) {
var result = ""; // If no filter matches, we return an empty string
$tw.utils.each(filterList,function(filter,index) {
if(!filterFnList[index]) {
filterFnList[index] = options.wiki.compileFilter(filter);
}
var output = filterFnList[index](options.wiki.makeTiddlerIterator([title]),{
getVariable: function(name) {
switch(name) {
case "currentTiddler":
return "" + title;
case "..currentTiddler":
return widget.getVariable("currentTiddler");
default:
return widget.getVariable(name);
}
}
});
if(output.length !== 0) {
result = output[0];
return false;
}
});
results.push(result);
});
}
}
};

})();
9 changes: 9 additions & 0 deletions core/ui/ControlPanel/Cascades.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: $:/core/ui/ControlPanel/Cascades
tags: $:/tags/ControlPanel/Advanced
caption: {{$:/language/ControlPanel/Cascades/Caption}}

{{$:/language/ControlPanel/Cascades/Hint}}

<div class="tc-control-panel">
<$macrocall $name="tabs" tabsList="[all[shadows+tiddlers]tag[$:/tags/ControlPanel/Cascades]!has[draft.of]]" default="$:/core/ui/ControlPanel/StoryTiddler"/>
</div>
9 changes: 9 additions & 0 deletions core/ui/ControlPanel/Cascades/EditTemplateBody.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: $:/core/ui/ControlPanel/EditTemplateBody
tags: $:/tags/ControlPanel/Cascade
caption: {{$:/language/ControlPanel/EditTemplateBody/Caption}}

\define lingo-base() $:/language/ControlPanel/EditTemplateBody/

<<lingo Hint>>

{{$:/tags/EditTemplateBodyFilter||$:/snippets/ListTaggedCascade}}
9 changes: 9 additions & 0 deletions core/ui/ControlPanel/Cascades/StoryTiddler.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: $:/core/ui/ControlPanel/StoryTiddler
tags: $:/tags/ControlPanel/Cascades
caption: {{$:/language/ControlPanel/StoryTiddler/Caption}}

\define lingo-base() $:/language/ControlPanel/StoryTiddler/

<<lingo Hint>>

{{$:/tags/StoryTiddlerTemplateFilter||$:/snippets/ListTaggedCascade}}
9 changes: 9 additions & 0 deletions core/ui/ControlPanel/Cascades/TiddlerIcon.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: $:/core/ui/ControlPanel/TiddlerIcon
tags: $:/tags/ControlPanel/Cascades
caption: {{$:/language/ControlPanel/TiddlerIcon/Caption}}

\define lingo-base() $:/language/ControlPanel/TiddlerIcon/

<<lingo Hint>>

{{$:/tags/TiddlerIconFilter||$:/snippets/ListTaggedCascade}}
9 changes: 9 additions & 0 deletions core/ui/ControlPanel/Cascades/ViewTemplateBody.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: $:/core/ui/ControlPanel/ViewTemplateBody
tags: $:/tags/ControlPanel/Cascades
caption: {{$:/language/ControlPanel/ViewTemplateBody/Caption}}

\define lingo-base() $:/language/ControlPanel/ViewTemplateBody/

<<lingo Hint>>

{{$:/tags/ViewTemplateBodyFilter||$:/snippets/ListTaggedCascade}}
9 changes: 9 additions & 0 deletions core/ui/ControlPanel/Cascades/ViewTemplateTitle.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: $:/core/ui/ControlPanel/ViewTemplateTitle
tags: $:/tags/ControlPanel/Cascades
caption: {{$:/language/ControlPanel/ViewTemplateTitle/Caption}}

\define lingo-base() $:/language/ControlPanel/ViewTemplateTitle/

<<lingo Hint>>

{{$:/tags/ViewTemplateTitleFilter||$:/snippets/ListTaggedCascade}}
54 changes: 1 addition & 53 deletions core/ui/EditTemplate/body.tid
Original file line number Diff line number Diff line change
@@ -1,56 +1,4 @@
title: $:/core/ui/EditTemplate/body
tags: $:/tags/EditTemplate

\define lingo-base() $:/language/EditTemplate/Body/
\define config-visibility-title()
$:/config/EditorToolbarButtons/Visibility/$(currentTiddler)$
\end

\define importFileActions()
<$action-popup $state=<<importState>> $coords="(0,0,0,0)" $floating="yes"/>
\end

<$list filter="[all[current]has[_canonical_uri]]">

<div class="tc-message-box">

<<lingo External/Hint>>

<a href={{!!_canonical_uri}}><$text text={{!!_canonical_uri}}/></a>

<$edit-text field="_canonical_uri" class="tc-edit-fields" tabindex={{$:/config/EditTabIndex}} cancelPopups="yes"></$edit-text>

</div>

</$list>

<$set name="edit-preview-state" value={{{ [{$:/config/ShowEditPreview/PerTiddler}!match[yes]then[$:/state/showeditpreview]] :else[<qualify "$:/state/showeditpreview">] }}}>
<$list filter="[all[current]!has[_canonical_uri]]">
<$vars importTitle=<<qualify $:/ImportImage>> importState=<<qualify $:/state/ImportImage>> >
<$dropzone importTitle=<<importTitle>> autoOpenOnImport="no" contentTypesFilter={{$:/config/Editor/ImportContentTypesFilter}} class="tc-dropzone-editor" enable={{{ [{$:/config/DragAndDrop/Enable}match[no]] :else[subfilter{$:/config/Editor/EnableImportFilter}then[yes]else[no]] }}} filesOnly="yes" actions=<<importFileActions>> ><$reveal stateTitle=<<edit-preview-state>> type="match" text="yes">
<div class="tc-tiddler-preview">

<$transclude tiddler="$:/core/ui/EditTemplate/body/editor" mode="inline"/>

<div class="tc-tiddler-preview-preview">

<$transclude tiddler={{$:/state/editpreviewtype}} mode="inline">

<$transclude tiddler="$:/core/ui/EditTemplate/body/preview/output" mode="inline"/>

</$transclude>

</div>

</div>
</$reveal>

<$reveal stateTitle=<<edit-preview-state>> type="nomatch" text="yes">

<$transclude tiddler="$:/core/ui/EditTemplate/body/editor" mode="inline"/>

</$reveal>
</$dropzone>
</$vars>
</$list>
</$set>
<$transclude tiddler={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/EditTemplateBodyFilter]get[text]] :and[!is[blank]else[$:/core/ui/EditTemplate/body/default]] }}} />
13 changes: 13 additions & 0 deletions core/ui/EditTemplate/body/canonical-uri.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: $:/core/ui/EditTemplate/body/canonical-uri

\define lingo-base() $:/language/EditTemplate/Body/

<div class="tc-message-box">

<<lingo External/Hint>>

<a href={{!!_canonical_uri}}><$text text={{!!_canonical_uri}}/></a>

<$edit-text field="_canonical_uri" class="tc-edit-fields" tabindex={{$:/config/EditTabIndex}} cancelPopups="yes"></$edit-text>

</div>
38 changes: 38 additions & 0 deletions core/ui/EditTemplate/body/default.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
title: $:/core/ui/EditTemplate/body/default

\define config-visibility-title()
$:/config/EditorToolbarButtons/Visibility/$(currentTiddler)$
\end

\define importFileActions()
<$action-popup $state=<<importState>> $coords="(0,0,0,0)" $floating="yes"/>
\end

<$set name="edit-preview-state" value={{{ [{$:/config/ShowEditPreview/PerTiddler}!match[yes]then[$:/state/showeditpreview]] :else[<qualify "$:/state/showeditpreview">] }}}>
<$vars importTitle=<<qualify $:/ImportImage>> importState=<<qualify $:/state/ImportImage>> >
<$dropzone importTitle=<<importTitle>> autoOpenOnImport="no" contentTypesFilter={{$:/config/Editor/ImportContentTypesFilter}} class="tc-dropzone-editor" enable={{{ [{$:/config/DragAndDrop/Enable}match[no]] :else[subfilter{$:/config/Editor/EnableImportFilter}then[yes]else[no]] }}} filesOnly="yes" actions=<<importFileActions>> ><$reveal stateTitle=<<edit-preview-state>> type="match" text="yes">
<div class="tc-tiddler-preview">

<$transclude tiddler="$:/core/ui/EditTemplate/body/editor" mode="inline"/>

<div class="tc-tiddler-preview-preview">

<$transclude tiddler={{$:/state/editpreviewtype}} mode="inline">

<$transclude tiddler="$:/core/ui/EditTemplate/body/preview/output" mode="inline"/>

</$transclude>

</div>

</div>
</$reveal>

<$reveal stateTitle=<<edit-preview-state>> type="nomatch" text="yes">

<$transclude tiddler="$:/core/ui/EditTemplate/body/editor" mode="inline"/>

</$reveal>
</$dropzone>
</$vars>
</$set>
14 changes: 14 additions & 0 deletions core/ui/ListTaggedCascade.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: $:/snippets/ListTaggedCascade

{{||$:/language/ControlPanel/Cascades/TagPrompt}}

<ol>
<$list filter="[all[shadows+tiddlers]tag<currentTiddler>]">
<li>
<div>
<$link><$text text=<<currentTiddler>>/></$link>
</div>
<$codeblock code={{!!text}}/>
</li>
</$list>
</ol>
2 changes: 1 addition & 1 deletion core/ui/PageTemplate/story.tid
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tags: $:/tags/PageTemplate

</section>

<$list filter="[list[$:/StoryList]]" history="$:/HistoryList" template={{$:/config/ui/ViewTemplate}} editTemplate={{$:/config/ui/EditTemplate}} storyview={{$:/view}} emptyMessage={{$:/config/EmptyStoryMessage}}/>
<$list filter="[list[$:/StoryList]]" history="$:/HistoryList" template="$:/core/ui/StoryTiddlerTemplate" storyview={{$:/view}} emptyMessage={{$:/config/EmptyStoryMessage}}/>

<section class="story-frontdrop">

Expand Down
3 changes: 3 additions & 0 deletions core/ui/StoryTiddlerTemplate.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title: $:/core/ui/StoryTiddlerTemplate

<$transclude tiddler={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/StoryTiddlerTemplateFilter]get[text]] :and[!is[blank]else{$:/config/ui/ViewTemplate}] }}} />
2 changes: 1 addition & 1 deletion core/ui/TagPickerTagTemplate.tid
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ title: $:/core/ui/TagPickerTagTemplate
<$set name="backgroundColor" value={{!!color}}>
<$wikify name="foregroundColor" text="""<$macrocall $name="contrastcolour" target={{!!color}} fallbackTarget=<<fallbackTarget>> colourA=<<colourA>> colourB=<<colourB>>/>""">
<span class="tc-tag-label tc-btn-invisible" style=<<tag-pill-styles>>>
<$transclude tiddler={{!!icon}}/><$view field="title" format="text"/>
{{||$:/core/ui/TiddlerIcon}}<$view field="title" format="text"/>
</span>
</$wikify>
</$set>
Expand Down
2 changes: 1 addition & 1 deletion core/ui/TagTemplate.tid
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: $:/core/ui/TagTemplate
\whitespace trim
<span class="tc-tag-list-item" data-tag-title=<<currentTiddler>>>
<$set name="transclusion" value=<<currentTiddler>>>
<$macrocall $name="tag-pill-body" tag=<<currentTiddler>> icon={{!!icon}} colour={{!!color}} palette={{$:/palette}} element-tag="""$button""" element-attributes="""popup=<<qualify "$:/state/popup/tag">> dragFilter='[all[current]tagging[]]' tag='span'"""/>
<$macrocall $name="tag-pill-body" tag=<<currentTiddler>> colour={{!!color}} palette={{$:/palette}} element-tag="""$button""" element-attributes="""popup=<<qualify "$:/state/popup/tag">> dragFilter='[all[current]tagging[]]' tag='span'"""/>
<$reveal state=<<qualify "$:/state/popup/tag">> type="popup" position="below" animate="yes" class="tc-drop-down">
<$set name="tv-show-missing-links" value="yes">
<$transclude tiddler="$:/core/ui/ListItemTemplate"/>
Expand Down
15 changes: 15 additions & 0 deletions core/ui/TiddlerIcon.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
title: $:/core/ui/TiddlerIcon

\whitespace trim
\define title-styles()
fill:$(foregroundColor)$;
\end
<$let tiddlerIcon={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerIconFilter]get[text]] }}}>
<$list filter="[<tiddlerIcon>!is[blank]]" variable="ignore">
<$let foregroundColor={{!!color}}>
<span class=<<iconSpanClass>> style=<<title-styles>>>
<$transclude tiddler=<<tiddlerIcon>>/>
</span>
</$let>
</$list>
</$let>
10 changes: 1 addition & 9 deletions core/ui/ViewTemplate/body.tid
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ tags: $:/tags/ViewTemplate

<$reveal tag="div" class="tc-tiddler-body" type="nomatch" stateTitle=<<folded-state>> text="hide" retain="yes" animate="yes">

<$list filter="[all[current]!has[plugin-type]!field:hide-body[yes]]">

<$transclude>

<$transclude tiddler="$:/language/MissingTiddler/Hint"/>

</$transclude>

</$list>
<$transclude tiddler={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/ViewTemplateBodyFilter]get[text]] :and[!is[blank]else[$:/core/ui/ViewTemplate/body/default]] }}} />

</$reveal>
3 changes: 3 additions & 0 deletions core/ui/ViewTemplate/body/blank.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title: $:/core/ui/ViewTemplate/body/blank

<!-- Intentionally blank -->
3 changes: 3 additions & 0 deletions core/ui/ViewTemplate/body/code.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title: $:/core/ui/ViewTemplate/body/code

<$codeblock code={{{ [<currentTiddler>get[text]] }}} language={{{ [<currentTiddler>get[type]else[text/vnd.tiddlywiki]] }}}/>
7 changes: 7 additions & 0 deletions core/ui/ViewTemplate/body/default.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: $:/core/ui/ViewTemplate/body/default

<$transclude>

<$transclude tiddler="$:/language/MissingTiddler/Hint"/>

</$transclude>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
title: $:/core/ui/ViewTemplate/import
tags: $:/tags/ViewTemplate
title: $:/core/ui/ViewTemplate/body/import

\define lingo-base() $:/language/Import/

Expand Down
10 changes: 10 additions & 0 deletions core/ui/ViewTemplate/body/plugin.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: $:/core/ui/ViewTemplate/body/plugin

<div class="tc-tiddler-plugin-info">
<$let plugin-type={{!!plugin-type}}
default-popup-state="yes"
qualified-state=<<qualify "$:/state/plugin-info">>
>
{{||$:/core/ui/Components/plugin-info}}
</$let>
</div>
15 changes: 0 additions & 15 deletions core/ui/ViewTemplate/plugin.tid

This file was deleted.

0 comments on commit a350a76

Please sign in to comment.