mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +00:00 
			
		
		
		
	Rejig genesis widget to be easier to use
This commit is contained in:
		| @@ -43,14 +43,16 @@ GenesisWidget.prototype.execute = function() { | ||||
| 	var self = this; | ||||
| 	// Collect attributes | ||||
| 	this.genesisType = this.getAttribute("$type","element"); | ||||
| 	this.genesisTag = this.getAttribute("$tag","div"); | ||||
| 	this.genesisRemappable = this.getAttribute("$remappable","yes") === "yes"; | ||||
| 	this.genesisNames = this.getAttribute("$names",""); | ||||
| 	this.genesisValues = this.getAttribute("$values",""); | ||||
| 	// Construct parse tree | ||||
| 	var isElementWidget = this.genesisType.charAt(0) !== "$", | ||||
| 		nodeType = isElementWidget ? "element" : this.genesisType.substr(1), | ||||
| 		nodeTag = isElementWidget ? this.genesisType : undefined; | ||||
| 	var parseTreeNodes = [{ | ||||
| 		type: this.genesisType, | ||||
| 		tag: this.genesisTag, | ||||
| 		type: nodeType, | ||||
| 		tag: nodeTag, | ||||
| 		attributes: {}, | ||||
| 		orderedAttributes: [], | ||||
| 		children: this.parseTreeNode.children || [], | ||||
|   | ||||
| @@ -6,8 +6,8 @@ tags: [[$:/tags/wiki-test-spec]] | ||||
| title: Output | ||||
|  | ||||
| \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 | ||||
|  | ||||
|   | ||||
| @@ -6,8 +6,8 @@ tags: [[$:/tags/wiki-test-spec]] | ||||
| title: Output | ||||
|  | ||||
| \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 | ||||
|  | ||||
|   | ||||
| @@ -6,8 +6,8 @@ tags: [[$:/tags/wiki-test-spec]] | ||||
| title: Output | ||||
|  | ||||
| \whitespace trim | ||||
| <$genesis $tag="div">Mouse</$genesis> | ||||
| <$genesis $tag="div" class="tc-thing" label="Squeak">Mouse</$genesis> | ||||
| <$genesis $type="div">Mouse</$genesis> | ||||
| <$genesis $type="div" class="tc-thing" label="Squeak">Mouse</$genesis> | ||||
| + | ||||
| title: ExpectedResult | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,7 @@ title: Definition | ||||
|  | ||||
| \whitespace trim | ||||
| \widget $codeblock(code) | ||||
| <$genesis $type="codeblock" $remappable="no" code={{{ [<code>addprefix[£]addsuffix[@]] }}}/> | ||||
| <$genesis $type="$codeblock" $remappable="no" code={{{ [<code>addprefix[£]addsuffix[@]] }}}/> | ||||
| \end | ||||
| + | ||||
| title: Subject | ||||
|   | ||||
| @@ -24,7 +24,7 @@ title: TiddlerOne | ||||
| 		Whale | ||||
| 	</$slot> | ||||
| \end | ||||
| <$genesis $type="transclude" $remappable="no" $$tiddler="TiddlerZero"> | ||||
| <$genesis $type="$transclude" $remappable="no" $$tiddler="TiddlerZero"> | ||||
| 	Crocodile | ||||
| </$genesis> | ||||
| + | ||||
|   | ||||
| @@ -15,7 +15,7 @@ title: TiddlerOne | ||||
| <!-- Redefine the <$text> widget by defining a transcludable variable with that name --> | ||||
| \widget $text(text:'Jaguar') | ||||
| \whitespace trim | ||||
| <$genesis $type="text" $remappable="no" text=<<text>>/> | ||||
| <$genesis $type="$text" $remappable="no" text=<<text>>/> | ||||
| <$set name="$text" value=""> | ||||
| 	<$slot $name="ts-raw"> | ||||
| 		Whale | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| caption: genesis | ||||
| created: 20220502144738010 | ||||
| modified: 20220502144738010 | ||||
| created: 20220909102917736 | ||||
| modified: 20220909102917736 | ||||
| tags: Widgets | ||||
| title: GenesisWidget | ||||
| 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. | ||||
|  | ||||
| |!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`) | | ||||
| |$tag |The HTML tag to be used for "element" widgets | | ||||
| |$type |The type of widget or element to create (an initial `$` indicates a widget, otherwise an HTML element will be created) | | ||||
| |$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` | | ||||
| |//{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 | ||||
|  | ||||
| <$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>'/> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jeremy@jermolene.com
					jeremy@jermolene.com