Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
WABuilder
Last updated at 5:16 am UTC on 15 September 2017
 WAObject subclass: #WABuilder
	instanceVariableNames: 'fullDocument rootBlock rootClass documentClass scriptGeneratorClass rendererClass codec actionUrl resourceUrl'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Seaside-Core-Rendering'



This is a convenience class which provides a result of a rendering operation as a string. It is expected to be used like this:

 WAHtmlCanvas builder render: [ :html |
	html anchor
		url: 'htttp://www.seaside.st';
		with: 'Seaside Homepage' ]

See WABuilderCanvasTest for more examples.



testBody
	| actual |
	actual := WAHtmlCanvas builder render: [ :html |
		html unorderedList: [
			html listItem: 'an item' ] ].
	self assert: actual = '<ul><li>an item</li></ul>'


testFullDocument
	| actual |
	actual := WAHtmlCanvas builder fullDocument: true; render: [ :html |
		html unorderedList: [
			html listItem: 'an item' ] ].
	self assert: actual = '<html><head><title></title></head><body onload="onLoad()"><ul><li>an item</li></ul><script type="text/javascript">function onLoad(){};</script></body></html>'


testFullDocumentWithBlock
	| actual |
	actual := WAHtmlCanvas builder fullDocument: true;
		rootBlock: [ :root |
			root title: 'title'.
			root stylesheet add: 'body{font-size:12px;}'.
			root javascript add: 'alert("loaded")' ];
		render: [ :html |
			html unorderedList: [
				html listItem: 'an item' ] ].
	self assert: actual =  '<html><head><title>title</title><style type="text/css">body{font-size:12px;}</style><script type="text/javascript">alert("loaded")</script></head><body onload="onLoad()"><ul><li>an item</li></ul><script type="text/javascript">function onLoad(){};</script></body></html>'