mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 19:10:08 +00:00 
			
		
		
		
	@quote(..) now a generator macro...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									a3fa8985ec
								
							
						
					
					
						commit
						0fcfe08ce2
					
				| @ -689,7 +689,7 @@ object.Constructor('Page', BasePage, { | |||||||
| 
 | 
 | ||||||
| 				var first = true | 				var first = true | ||||||
| 				for await (var page of this.get(src).each()){ | 				for await (var page of this.get(src).each()){ | ||||||
| 					if(!first){ | 					if(join && !first){ | ||||||
| 						yield join } | 						yield join } | ||||||
| 					first = false | 					first = false | ||||||
| 
 | 
 | ||||||
| @ -759,13 +759,10 @@ object.Constructor('Page', BasePage, { | |||||||
| 		// 		not expanded...
 | 		// 		not expanded...
 | ||||||
| 		// NOTE: the filter argument uses the same filters as @filter(..)
 | 		// NOTE: the filter argument uses the same filters as @filter(..)
 | ||||||
| 		//
 | 		//
 | ||||||
| 		// XXX GENERATOR make this a generator...
 |  | ||||||
| 		// XXX need to handle pattern paths (like include: join=...)
 |  | ||||||
| 		// XXX need a way to escape macros -- i.e. include </quote> in a quoted text...
 | 		// XXX need a way to escape macros -- i.e. include </quote> in a quoted text...
 | ||||||
| 		quote: Macro( | 		quote: Macro( | ||||||
| 			//['src', 'filter', 'text', 'join'],
 | 			['src', 'filter', 'text', 'join'], | ||||||
| 			['src', 'filter', 'text'], | 			async function*(args, body, state){ | ||||||
| 			async function(args, body, state){ |  | ||||||
| 				var src = args.src //|| args[0]
 | 				var src = args.src //|| args[0]
 | ||||||
| 				var base = this.get(this.path.split(/\*/).shift()) | 				var base = this.get(this.path.split(/\*/).shift()) | ||||||
| 				var text = args.text  | 				var text = args.text  | ||||||
| @ -775,17 +772,30 @@ object.Constructor('Page', BasePage, { | |||||||
| 				src = src ?  | 				src = src ?  | ||||||
| 					await base.parse(src, state) | 					await base.parse(src, state) | ||||||
| 					: src | 					: src | ||||||
| 				text = src ? |  | ||||||
| 						// source page...
 |  | ||||||
| 						await this.get(src).raw |  | ||||||
| 					: text instanceof Array ? |  | ||||||
| 						text.join('') |  | ||||||
| 					: text |  | ||||||
| 
 | 
 | ||||||
|  | 				var pages = src ? | ||||||
|  | 						this.get(src).each() | ||||||
|  | 					: text instanceof Array ? | ||||||
|  | 						[text.join('')] | ||||||
|  | 					: typeof(text) == 'string' ? | ||||||
|  | 						[text] | ||||||
|  | 					: text | ||||||
| 				// empty...
 | 				// empty...
 | ||||||
| 				if(!text){ | 				if(!pages){ | ||||||
| 					return } | 					return } | ||||||
| 
 | 
 | ||||||
|  | 				var join = args.join  | ||||||
|  | 					&& await base.parse(args.join, state) | ||||||
|  | 				var first = true | ||||||
|  | 				for await (var page of pages){ | ||||||
|  | 					if(join && !first){ | ||||||
|  | 						yield join } | ||||||
|  | 					first = false | ||||||
|  | 
 | ||||||
|  | 					text = typeof(page) == 'string' ? | ||||||
|  | 						page | ||||||
|  | 						: await page.raw | ||||||
|  | 
 | ||||||
| 					var filters =  | 					var filters =  | ||||||
| 						args.filter  | 						args.filter  | ||||||
| 							&& args.filter | 							&& args.filter | ||||||
| @ -800,6 +810,9 @@ object.Constructor('Page', BasePage, { | |||||||
| 					// 		to it doing the first stage of .filter(..) as late 
 | 					// 		to it doing the first stage of .filter(..) as late 
 | ||||||
| 					// 		as the second stage here will have no ill effect...
 | 					// 		as the second stage here will have no ill effect...
 | ||||||
| 					// NOTE: this uses the same filters as @filter(..)
 | 					// NOTE: this uses the same filters as @filter(..)
 | ||||||
|  | 					// NOTE: the function wrapper here isolates text in 
 | ||||||
|  | 					// 		a closure per function...
 | ||||||
|  | 					yield (function(text){ | ||||||
| 						return async function(state){ | 						return async function(state){ | ||||||
| 							// add global quote-filters...
 | 							// add global quote-filters...
 | ||||||
| 							filters = | 							filters = | ||||||
| @ -811,7 +824,7 @@ object.Constructor('Page', BasePage, { | |||||||
| 								await this.__parser__.callMacro( | 								await this.__parser__.callMacro( | ||||||
| 										this, 'filter', filters, text, state, false) | 										this, 'filter', filters, text, state, false) | ||||||
| 									.call(this, state) | 									.call(this, state) | ||||||
| 						: text } }), | 								: text } })(text) } }), | ||||||
| 		// very similar to @filter(..) but will affect @quote(..) filters...
 | 		// very similar to @filter(..) but will affect @quote(..) filters...
 | ||||||
| 		'quote-filter': function(args, body, state){ | 		'quote-filter': function(args, body, state){ | ||||||
| 			var filters = state.quote_filters =  | 			var filters = state.quote_filters =  | ||||||
| @ -1460,7 +1473,6 @@ module.System = { | |||||||
| 	test_list: function(){ | 	test_list: function(){ | ||||||
| 		return 'abcdef'.split('') }, | 		return 'abcdef'.split('') }, | ||||||
| 	test_slots: { | 	test_slots: { | ||||||
| 		/* XXX |  | ||||||
| 		text: object.doc` | 		text: object.doc` | ||||||
| 			Sequential: | 			Sequential: | ||||||
| 			<slot name="sequential">unfilled</slot> | 			<slot name="sequential">unfilled</slot> | ||||||
| @ -1483,7 +1495,17 @@ module.System = { | |||||||
| 			<slot name="slot-content"><content/> B</slot> | 			<slot name="slot-content"><content/> B</slot> | ||||||
| 			<slot name="slot-conten"><content/> C</slot> | 			<slot name="slot-conten"><content/> C</slot> | ||||||
| 			<br><br> | 			<br><br> | ||||||
| 		//*/
 | 			Nested content: A B C: | ||||||
|  | 			<slot name="nested-slot-content"> | ||||||
|  | 				A | ||||||
|  | 				<slot name="nested-slot-content"> | ||||||
|  | 					<content/> B | ||||||
|  | 					<slot name="nested-slot-content"> | ||||||
|  | 						<content/> C | ||||||
|  | 					</slot> | ||||||
|  | 				</slot> | ||||||
|  | 			</slot> ` }, | ||||||
|  | 	test_nested_slots: { | ||||||
| 		text: object.doc` | 		text: object.doc` | ||||||
| 			Nested content: A B C: | 			Nested content: A B C: | ||||||
| 			<slot name="nested-slot-content"> | 			<slot name="nested-slot-content"> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user