-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "cascade" filter run prefix and use it to control view templates (#…
…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
Showing
44 changed files
with
394 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] }}} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}] }}} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
title: $:/core/ui/ViewTemplate/body/blank | ||
|
||
<!-- Intentionally blank --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] }}}/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
3 changes: 1 addition & 2 deletions
3
core/ui/ViewTemplate/import.tid → core/ui/ViewTemplate/body/import.tid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.