Initial support for switching page templates (#4979)

* Add support for switching page templates

* Revert "Add support for switching page templates"

This reverts commit dbf7682d47.

* Adopt Jeremy's approach to page template switching instead

* Fix default value of recursion marker

* Fixed issue with conditional check
This commit is contained in:
saqimtiaz
2020-11-07 09:51:01 +00:00
committed by GitHub
parent 2b31c7a509
commit 5aa4e4cb68
4 changed files with 18 additions and 4 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ exports.synchronous = true;
// Default story and history lists // Default story and history lists
var PAGE_TITLE_TITLE = "$:/core/wiki/title"; var PAGE_TITLE_TITLE = "$:/core/wiki/title";
var PAGE_STYLESHEET_TITLE = "$:/core/ui/PageStylesheet"; var PAGE_STYLESHEET_TITLE = "$:/core/ui/PageStylesheet";
var PAGE_TEMPLATE_TITLE = "$:/core/ui/PageTemplate"; var PAGE_TEMPLATE_TITLE = "$:/core/ui/RootTemplate";
// Time (in ms) that we defer refreshing changes to draft tiddlers // Time (in ms) that we defer refreshing changes to draft tiddlers
var DRAFT_TIDDLER_TIMEOUT_TITLE = "$:/config/Drafts/TypingTimeout"; var DRAFT_TIDDLER_TIMEOUT_TITLE = "$:/config/Drafts/TypingTimeout";
@@ -52,7 +52,7 @@ exports.startup = function() {
})); }));
// Display the $:/core/ui/PageTemplate tiddler to kick off the display // Display the $:/core/ui/PageTemplate tiddler to kick off the display
$tw.perf.report("mainRender",function() { $tw.perf.report("mainRender",function() {
$tw.pageWidgetNode = $tw.wiki.makeTranscludeWidget(PAGE_TEMPLATE_TITLE,{document: document, parentWidget: $tw.rootWidget}); $tw.pageWidgetNode = $tw.wiki.makeTranscludeWidget(PAGE_TEMPLATE_TITLE,{document: document, parentWidget: $tw.rootWidget, recursionMarker: "no"});
$tw.pageContainer = document.createElement("div"); $tw.pageContainer = document.createElement("div");
$tw.utils.addClass($tw.pageContainer,"tc-page-container-wrapper"); $tw.utils.addClass($tw.pageContainer,"tc-page-container-wrapper");
document.body.insertBefore($tw.pageContainer,document.body.firstChild); document.body.insertBefore($tw.pageContainer,document.body.firstChild);
+4 -1
View File
@@ -43,6 +43,7 @@ TranscludeWidget.prototype.execute = function() {
this.transcludeField = this.getAttribute("field"); this.transcludeField = this.getAttribute("field");
this.transcludeIndex = this.getAttribute("index"); this.transcludeIndex = this.getAttribute("index");
this.transcludeMode = this.getAttribute("mode"); this.transcludeMode = this.getAttribute("mode");
this.recursionMarker = this.getAttribute("recursionMarker","yes");
// Parse the text reference // Parse the text reference
var parseAsInline = !this.parseTreeNode.isBlock; var parseAsInline = !this.parseTreeNode.isBlock;
if(this.transcludeMode === "inline") { if(this.transcludeMode === "inline") {
@@ -61,7 +62,9 @@ TranscludeWidget.prototype.execute = function() {
parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children; parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children;
// Set context variables for recursion detection // Set context variables for recursion detection
var recursionMarker = this.makeRecursionMarker(); var recursionMarker = this.makeRecursionMarker();
this.setVariable("transclusion",recursionMarker); if(this.recursionMarker === "yes") {
this.setVariable("transclusion",recursionMarker);
}
// Check for recursion // Check for recursion
if(parser) { if(parser) {
if(this.parentWidget && this.parentWidget.hasVariable("transclusion",recursionMarker)) { if(this.parentWidget && this.parentWidget.hasVariable("transclusion",recursionMarker)) {
+9 -1
View File
@@ -1004,6 +1004,7 @@ title: target tiddler title
options: as for wiki.makeWidget() plus: options: as for wiki.makeWidget() plus:
options.field: optional field to transclude (defaults to "text") options.field: optional field to transclude (defaults to "text")
options.mode: transclusion mode "inline" or "block" options.mode: transclusion mode "inline" or "block"
options.recursionMarker : optional flag to set a recursion marker, defaults to "yes"
options.children: optional array of children for the transclude widget options.children: optional array of children for the transclude widget
options.importVariables: optional importvariables filter string for macros to be included options.importVariables: optional importvariables filter string for macros to be included
options.importPageMacros: optional boolean; if true, equivalent to passing "[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]" to options.importVariables options.importPageMacros: optional boolean; if true, equivalent to passing "[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]" to options.importVariables
@@ -1027,10 +1028,17 @@ exports.makeTranscludeWidget = function(title,options) {
parseTreeTransclude = { parseTreeTransclude = {
type: "transclude", type: "transclude",
attributes: { attributes: {
recursionMarker: {
name: "recursionMarker",
type: "string",
value: options.recursionMarker || "yes"
},
tiddler: { tiddler: {
name: "tiddler", name: "tiddler",
type: "string", type: "string",
value: title}}, value: title
}
},
isBlock: !options.parseAsInline}; isBlock: !options.parseAsInline};
if(options.importVariables || options.importPageMacros) { if(options.importVariables || options.importPageMacros) {
if(options.importVariables) { if(options.importVariables) {
+3
View File
@@ -0,0 +1,3 @@
title: $:/core/ui/RootTemplate
<$transclude tiddler={{{ [{$:/layout}has[text]] ~[[$:/core/ui/PageTemplate]] }}} mode="inline"/>