mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 11:00:08 +00:00 
			
		
		
		
	notes, docs, cleanup and some refactoring of macros....
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									028feec191
								
							
						
					
					
						commit
						27a5e500dc
					
				
							
								
								
									
										74
									
								
								pwiki2.js
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								pwiki2.js
									
									
									
									
									
								
							| @ -1351,7 +1351,10 @@ object.Constructor('Page', BasePage, { | |||||||
| 	// list of macros that will get raw text of their content...
 | 	// list of macros that will get raw text of their content...
 | ||||||
| 	QUOTING_MACROS: ['quote'], | 	QUOTING_MACROS: ['quote'], | ||||||
| 
 | 
 | ||||||
| 	//PAGE_NOT_FOUND: 'PAGE NOT FOUND',
 | 	// NOTE: comment this out to make the system fail when nothing is 
 | ||||||
|  | 	// 		resolved, not even the System/NotFound page...
 | ||||||
|  | 	// XXX should this get returned or should the system fail??
 | ||||||
|  | 	PAGE_NOT_FOUND: '404 PAGE NOT FOUND', | ||||||
| 
 | 
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// 	<filter>(<source>)
 | 	// 	<filter>(<source>)
 | ||||||
| @ -1382,6 +1385,7 @@ object.Constructor('Page', BasePage, { | |||||||
| 		markdown: Filter( | 		markdown: Filter( | ||||||
| 			{quote: 'quote-markdown'}, | 			{quote: 'quote-markdown'}, | ||||||
| 			function(source){ | 			function(source){ | ||||||
|  | 				// XXX
 | ||||||
| 				return source }), | 				return source }), | ||||||
| 		'quote-markdown': function(source){ | 		'quote-markdown': function(source){ | ||||||
| 			// XXX
 | 			// XXX
 | ||||||
| @ -1397,23 +1401,11 @@ object.Constructor('Page', BasePage, { | |||||||
| 	// 		-> <func>(<state>)
 | 	// 		-> <func>(<state>)
 | ||||||
| 	// 			-> ...
 | 	// 			-> ...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// XXX need a good way to get the first positional arg without 
 | 	// XXX ASYNC make these support async page getters...
 | ||||||
| 	// 		mixing it up with other args -- see src/name args below...
 |  | ||||||
| 	macros: { | 	macros: { | ||||||
| 		// XXX move to docs...
 | 		// 
 | ||||||
| 		test: function*(args, body, state){ | 		// 	<now/>
 | ||||||
| 			if(body){ | 		//
 | ||||||
| 				state.testBlock = (state.testBlock ?? 0) + 1 |  | ||||||
| 
 |  | ||||||
| 				yield '\n<test>\n\n' |  | ||||||
| 				yield* this.expand(body)  |  | ||||||
| 				yield '\n\n</test>\n' |  | ||||||
| 
 |  | ||||||
| 				--state.testBlock == 0 |  | ||||||
| 					&& (delete state.testBlock) |  | ||||||
| 			} else { |  | ||||||
| 				yield '<test/>' } }, |  | ||||||
| 
 |  | ||||||
| 		now: function(){ | 		now: function(){ | ||||||
| 			return ''+ Date.now() }, | 			return ''+ Date.now() }, | ||||||
| 		//
 | 		//
 | ||||||
| @ -1673,9 +1665,28 @@ object.Constructor('Page', BasePage, { | |||||||
| 					: function(state){ | 					: function(state){ | ||||||
| 						return state.slots[name] } }),  | 						return state.slots[name] } }),  | ||||||
| 
 | 
 | ||||||
| 		// XXX sorting not implemented yet....
 | 		// 	
 | ||||||
|  | 		// 	<macro src=<url>> .. </macro>
 | ||||||
|  | 		//
 | ||||||
|  | 		// 	<macro name=<name> src=<url> sort=<sort-spec>> .. </macro>
 | ||||||
|  | 		//
 | ||||||
|  | 		// 	<macro ...> ... </macro>
 | ||||||
|  | 		// 	<macro ... text=<text>/>
 | ||||||
|  | 		//
 | ||||||
|  | 		// 	<macro ... else=<text>> ... </macro>
 | ||||||
|  | 		// 	<macro ...>
 | ||||||
|  | 		// 		...
 | ||||||
|  | 		//
 | ||||||
|  | 		// 		<else>
 | ||||||
|  | 		// 			...
 | ||||||
|  | 		// 		</else>
 | ||||||
|  | 		// 	</macro>
 | ||||||
|  | 		//
 | ||||||
|  | 		// XXX ELSE_PRIO should else attr take priority over the <else> tag???
 | ||||||
|  | 		// 		...currently as with text=... the attr takes priority...
 | ||||||
|  | 		// XXX SORT sorting not implemented yet....
 | ||||||
| 		macro: Macro( | 		macro: Macro( | ||||||
| 			['name', 'src', 'sort', 'text'], | 			['name', 'src', 'sort', 'text', 'else'], | ||||||
| 			function(args, body, state){ | 			function(args, body, state){ | ||||||
| 				var that = this | 				var that = this | ||||||
| 				var name = args.name //?? args[0]
 | 				var name = args.name //?? args[0]
 | ||||||
| @ -1684,9 +1695,13 @@ object.Constructor('Page', BasePage, { | |||||||
| 					.split(/\s+/g) | 					.split(/\s+/g) | ||||||
| 					.filter(function(e){  | 					.filter(function(e){  | ||||||
| 						return e != '' }) | 						return e != '' }) | ||||||
|  | 				// NOTE: args.text will need parsing...
 | ||||||
| 				var text = args.text  | 				var text = args.text  | ||||||
| 					?? body  | 					?? body  | ||||||
| 					?? [] | 					?? [] | ||||||
|  | 				text = typeof(text) == 'string' ? | ||||||
|  | 					[...this.__parser__.group(this, text+'</macro>', 'macro')] | ||||||
|  | 					: text | ||||||
| 
 | 
 | ||||||
| 				if(name){ | 				if(name){ | ||||||
| 					// define new named macro...
 | 					// define new named macro...
 | ||||||
| @ -1700,15 +1715,23 @@ object.Constructor('Page', BasePage, { | |||||||
| 				if(src){ | 				if(src){ | ||||||
| 					var pages = this.get(src).each() | 					var pages = this.get(src).each() | ||||||
| 					// no matching pages -> get the else block...
 | 					// no matching pages -> get the else block...
 | ||||||
| 					if(pages.length == 0 && text){ | 					if(pages.length == 0  | ||||||
|  | 							&& (text || args['else'])){ | ||||||
|  | 						// XXX ELSE_PRIO
 | ||||||
| 						var else_block =  | 						var else_block =  | ||||||
| 							(text ?? []) | 							args['else'] ? | ||||||
|  | 								[{ | ||||||
|  | 									args: {}, | ||||||
|  | 									body: args['else'], | ||||||
|  | 								}]  | ||||||
|  | 								: (text ?? []) | ||||||
| 									.filter(function(e){  | 									.filter(function(e){  | ||||||
| 										return typeof(e) != 'string'  | 										return typeof(e) != 'string'  | ||||||
| 											&& e.name == 'else' }) | 											&& e.name == 'else' }) | ||||||
| 						if(else_block.length == 0){ | 						if(else_block.length == 0){ | ||||||
| 							return } | 							return } | ||||||
| 						// XXX do we take the first or the last (now) block???
 | 						// NOTE: when multiple <else> tags are present 
 | ||||||
|  | 						// 		the last one is used...
 | ||||||
| 						else_block = else_block.pop() | 						else_block = else_block.pop() | ||||||
| 						else_block =  | 						else_block =  | ||||||
| 							else_block.args.text  | 							else_block.args.text  | ||||||
| @ -1719,12 +1742,11 @@ object.Constructor('Page', BasePage, { | |||||||
| 
 | 
 | ||||||
| 					// sort pages...
 | 					// sort pages...
 | ||||||
| 					if(sort.length > 0){ | 					if(sort.length > 0){ | ||||||
| 						// XXX
 | 						// XXX SORT
 | ||||||
| 						throw new Error('macro sort: not implemented') | 						throw new Error('macro sort: not implemented') | ||||||
| 					} | 					} | ||||||
| 
 | 
 | ||||||
| 					// apply macro text...
 | 					// apply macro text...
 | ||||||
| 					// XXX not sure we should expand the whole thing directly here...
 |  | ||||||
| 					return pages | 					return pages | ||||||
| 						.map(function(page){ | 						.map(function(page){ | ||||||
| 							return [...that.__parser__.expand(page, text, state)] }) | 							return [...that.__parser__.expand(page, text, state)] }) | ||||||
| @ -1766,6 +1788,10 @@ object.Constructor('Page', BasePage, { | |||||||
| 							d.call(that) | 							d.call(that) | ||||||
| 							: d.text }) | 							: d.text }) | ||||||
| 					.join('\n') | 					.join('\n') | ||||||
|  | 			// no data...
 | ||||||
|  | 			// NOTE: if you hit this it means that nothing was resolved, 
 | ||||||
|  | 			// 		not even the System/NotFound page, i.e. something 
 | ||||||
|  | 			// 		went really wrong...
 | ||||||
| 			: data == null ? | 			: data == null ? | ||||||
| 				this.PAGE_NOT_FOUND | 				this.PAGE_NOT_FOUND | ||||||
|    			: data.text }, |    			: data.text }, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user