mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-12 10:20:26 +00:00
Rejig genesis widget to be easier to use
This commit is contained in:
parent
e3697e29bb
commit
82b22523aa
@ -43,14 +43,16 @@ GenesisWidget.prototype.execute = function() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
// Collect attributes
|
// Collect attributes
|
||||||
this.genesisType = this.getAttribute("$type","element");
|
this.genesisType = this.getAttribute("$type","element");
|
||||||
this.genesisTag = this.getAttribute("$tag","div");
|
|
||||||
this.genesisRemappable = this.getAttribute("$remappable","yes") === "yes";
|
this.genesisRemappable = this.getAttribute("$remappable","yes") === "yes";
|
||||||
this.genesisNames = this.getAttribute("$names","");
|
this.genesisNames = this.getAttribute("$names","");
|
||||||
this.genesisValues = this.getAttribute("$values","");
|
this.genesisValues = this.getAttribute("$values","");
|
||||||
// Construct parse tree
|
// Construct parse tree
|
||||||
|
var isElementWidget = this.genesisType.charAt(0) !== "$",
|
||||||
|
nodeType = isElementWidget ? "element" : this.genesisType.substr(1),
|
||||||
|
nodeTag = isElementWidget ? this.genesisType : undefined;
|
||||||
var parseTreeNodes = [{
|
var parseTreeNodes = [{
|
||||||
type: this.genesisType,
|
type: nodeType,
|
||||||
tag: this.genesisTag,
|
tag: nodeTag,
|
||||||
attributes: {},
|
attributes: {},
|
||||||
orderedAttributes: [],
|
orderedAttributes: [],
|
||||||
children: this.parseTreeNode.children || [],
|
children: this.parseTreeNode.children || [],
|
||||||
|
@ -6,8 +6,8 @@ tags: [[$:/tags/wiki-test-spec]]
|
|||||||
title: Output
|
title: Output
|
||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$genesis $type="let" myvar="Kitten">(<$text text=<<myvar>>/>)</$genesis>
|
<$genesis $type="$let" myvar="Kitten">(<$text text=<<myvar>>/>)</$genesis>
|
||||||
<$genesis $type="let" $$myvar="Kitten">(<$text text=<<$myvar>>/>)</$genesis>
|
<$genesis $type="$let" $$myvar="Kitten">(<$text text=<<$myvar>>/>)</$genesis>
|
||||||
+
|
+
|
||||||
title: ExpectedResult
|
title: ExpectedResult
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ tags: [[$:/tags/wiki-test-spec]]
|
|||||||
title: Output
|
title: Output
|
||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$genesis $type="let" $names="myvar other" $values="Kitten Donkey" myvar={{{ Shark }}}>(<$text text=<<myvar>>/>|<$text text=<<other>>/>)</$genesis>
|
<$genesis $type="$let" $names="myvar other" $values="Kitten Donkey" myvar={{{ Shark }}}>(<$text text=<<myvar>>/>|<$text text=<<other>>/>)</$genesis>
|
||||||
<$genesis $type="let" $names="$myvar $other" $values="Kitten Donkey" $$myvar="Shark">(<$text text=<<$myvar>>/>|<$text text=<<$other>>/>)</$genesis>
|
<$genesis $type="$let" $names="$myvar $other" $values="Kitten Donkey" $$myvar="Shark">(<$text text=<<$myvar>>/>|<$text text=<<$other>>/>)</$genesis>
|
||||||
+
|
+
|
||||||
title: ExpectedResult
|
title: ExpectedResult
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ tags: [[$:/tags/wiki-test-spec]]
|
|||||||
title: Output
|
title: Output
|
||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$genesis $tag="div">Mouse</$genesis>
|
<$genesis $type="div">Mouse</$genesis>
|
||||||
<$genesis $tag="div" class="tc-thing" label="Squeak">Mouse</$genesis>
|
<$genesis $type="div" class="tc-thing" label="Squeak">Mouse</$genesis>
|
||||||
+
|
+
|
||||||
title: ExpectedResult
|
title: ExpectedResult
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ title: Definition
|
|||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
\widget $codeblock(code)
|
\widget $codeblock(code)
|
||||||
<$genesis $type="codeblock" $remappable="no" code={{{ [<code>addprefix[£]addsuffix[@]] }}}/>
|
<$genesis $type="$codeblock" $remappable="no" code={{{ [<code>addprefix[£]addsuffix[@]] }}}/>
|
||||||
\end
|
\end
|
||||||
+
|
+
|
||||||
title: Subject
|
title: Subject
|
||||||
|
@ -24,7 +24,7 @@ title: TiddlerOne
|
|||||||
Whale
|
Whale
|
||||||
</$slot>
|
</$slot>
|
||||||
\end
|
\end
|
||||||
<$genesis $type="transclude" $remappable="no" $$tiddler="TiddlerZero">
|
<$genesis $type="$transclude" $remappable="no" $$tiddler="TiddlerZero">
|
||||||
Crocodile
|
Crocodile
|
||||||
</$genesis>
|
</$genesis>
|
||||||
+
|
+
|
||||||
|
@ -15,7 +15,7 @@ title: TiddlerOne
|
|||||||
<!-- Redefine the <$text> widget by defining a transcludable variable with that name -->
|
<!-- Redefine the <$text> widget by defining a transcludable variable with that name -->
|
||||||
\widget $text(text:'Jaguar')
|
\widget $text(text:'Jaguar')
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$genesis $type="text" $remappable="no" text=<<text>>/>
|
<$genesis $type="$text" $remappable="no" text=<<text>>/>
|
||||||
<$set name="$text" value="">
|
<$set name="$text" value="">
|
||||||
<$slot $name="ts-raw">
|
<$slot $name="ts-raw">
|
||||||
Whale
|
Whale
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
caption: genesis
|
caption: genesis
|
||||||
created: 20220502144738010
|
created: 20220909102917736
|
||||||
modified: 20220502144738010
|
modified: 20220909102917736
|
||||||
tags: Widgets
|
tags: Widgets
|
||||||
title: GenesisWidget
|
title: GenesisWidget
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -14,8 +14,7 @@ type: text/vnd.tiddlywiki
|
|||||||
The content of the `<$genesis>` widget is used as the content of the dynamically created widget.
|
The content of the `<$genesis>` widget is used as the content of the dynamically created widget.
|
||||||
|
|
||||||
|!Attribute |!Description |
|
|!Attribute |!Description |
|
||||||
|$type |The type of widget to create (note that the first `$` must not be included, so the `<$text>` widget would be created by passing `text`) |
|
|$type |The type of widget or element to create (an initial `$` indicates a widget, otherwise an HTML element will be created) |
|
||||||
|$tag |The HTML tag to be used for "element" widgets |
|
|
||||||
|$names |An optional filter evaluating to the names of a list of attributes to be applied to the widget |
|
|$names |An optional filter evaluating to the names of a list of attributes to be applied to the widget |
|
||||||
|$values |An optional filter evaluating to the values corresponding to the list of names specified in `$names` |
|
|$values |An optional filter evaluating to the values corresponding to the list of names specified in `$names` |
|
||||||
|//{other attributes starting with $}// |Other attributes starting with a single dollar sign are reserved for future use |
|
|//{other attributes starting with $}// |Other attributes starting with a single dollar sign are reserved for future use |
|
||||||
@ -27,4 +26,4 @@ Note that attributes explicitly specified take precedence over attributes with t
|
|||||||
! Examples
|
! Examples
|
||||||
|
|
||||||
<$macrocall $name='wikitext-example-without-html'
|
<$macrocall $name='wikitext-example-without-html'
|
||||||
src='<$genesis $tag="div" class="tc-thing" label="Squeak">Mouse</$genesis>'/>
|
src='<$genesis $type="div" class="tc-thing" label="Squeak">Mouse</$genesis>'/>
|
||||||
|
Loading…
Reference in New Issue
Block a user