[2000] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
---|
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | CKEDITOR.htmlParser.basicWriter = CKEDITOR.tools.createClass(
|
---|
| 7 | {
|
---|
| 8 | $ : function()
|
---|
| 9 | {
|
---|
| 10 | this._ =
|
---|
| 11 | {
|
---|
| 12 | output : []
|
---|
| 13 | };
|
---|
| 14 | },
|
---|
| 15 |
|
---|
| 16 | proto :
|
---|
| 17 | {
|
---|
| 18 | /**
|
---|
| 19 | * Writes the tag opening part for a opener tag.
|
---|
| 20 | * @param {String} tagName The element name for this tag.
|
---|
| 21 | * @param {Object} attributes The attributes defined for this tag. The
|
---|
| 22 | * attributes could be used to inspect the tag.
|
---|
| 23 | * @example
|
---|
| 24 | * // Writes "<p".
|
---|
| 25 | * writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } );
|
---|
| 26 | */
|
---|
| 27 | openTag : function( tagName, attributes )
|
---|
| 28 | {
|
---|
| 29 | this._.output.push( '<', tagName );
|
---|
| 30 | },
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | * Writes the tag closing part for a opener tag.
|
---|
| 34 | * @param {String} tagName The element name for this tag.
|
---|
| 35 | * @param {Boolean} isSelfClose Indicates that this is a self-closing tag,
|
---|
| 36 | * like "br" or "img".
|
---|
| 37 | * @example
|
---|
| 38 | * // Writes ">".
|
---|
| 39 | * writer.openTagClose( 'p', false );
|
---|
| 40 | * @example
|
---|
| 41 | * // Writes " />".
|
---|
| 42 | * writer.openTagClose( 'br', true );
|
---|
| 43 | */
|
---|
| 44 | openTagClose : function( tagName, isSelfClose )
|
---|
| 45 | {
|
---|
| 46 | if ( isSelfClose )
|
---|
| 47 | this._.output.push( ' />' );
|
---|
| 48 | else
|
---|
| 49 | this._.output.push( '>' );
|
---|
| 50 | },
|
---|
| 51 |
|
---|
| 52 | /**
|
---|
| 53 | * Writes an attribute. This function should be called after opening the
|
---|
| 54 | * tag with {@link #openTagClose}.
|
---|
| 55 | * @param {String} attName The attribute name.
|
---|
| 56 | * @param {String} attValue The attribute value.
|
---|
| 57 | * @example
|
---|
| 58 | * // Writes ' class="MyClass"'.
|
---|
| 59 | * writer.attribute( 'class', 'MyClass' );
|
---|
| 60 | */
|
---|
| 61 | attribute : function( attName, attValue )
|
---|
| 62 | {
|
---|
| 63 | this._.output.push( ' ', attName, '="', attValue, '"' );
|
---|
| 64 | },
|
---|
| 65 |
|
---|
| 66 | /**
|
---|
| 67 | * Writes a closer tag.
|
---|
| 68 | * @param {String} tagName The element name for this tag.
|
---|
| 69 | * @example
|
---|
| 70 | * // Writes "</p>".
|
---|
| 71 | * writer.closeTag( 'p' );
|
---|
| 72 | */
|
---|
| 73 | closeTag : function( tagName )
|
---|
| 74 | {
|
---|
| 75 | this._.output.push( '</', tagName, '>' );
|
---|
| 76 | },
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
| 79 | * Writes text.
|
---|
| 80 | * @param {String} text The text value
|
---|
| 81 | * @example
|
---|
| 82 | * // Writes "Hello Word".
|
---|
| 83 | * writer.text( 'Hello Word' );
|
---|
| 84 | */
|
---|
| 85 | text : function( text )
|
---|
| 86 | {
|
---|
| 87 | this._.output.push( text );
|
---|
| 88 | },
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * Writes a comment.
|
---|
| 92 | * @param {String} comment The comment text.
|
---|
| 93 | * @example
|
---|
| 94 | * // Writes "<!-- My comment -->".
|
---|
| 95 | * writer.comment( ' My comment ' );
|
---|
| 96 | */
|
---|
| 97 | comment : function( comment )
|
---|
| 98 | {
|
---|
| 99 | this._.output.push( '<!--', comment, '-->' );
|
---|
| 100 | },
|
---|
| 101 |
|
---|
| 102 | /**
|
---|
| 103 | * Writes any kind of data to the ouput.
|
---|
| 104 | * @example
|
---|
| 105 | * writer.write( 'This is an <b>example</b>.' );
|
---|
| 106 | */
|
---|
| 107 | write : function( data )
|
---|
| 108 | {
|
---|
| 109 | this._.output.push( data );
|
---|
| 110 | },
|
---|
| 111 |
|
---|
| 112 | /**
|
---|
| 113 | * Empties the current output buffer.
|
---|
| 114 | * @example
|
---|
| 115 | * writer.reset();
|
---|
| 116 | */
|
---|
| 117 | reset : function()
|
---|
| 118 | {
|
---|
| 119 | this._.output = [];
|
---|
| 120 | },
|
---|
| 121 |
|
---|
| 122 | /**
|
---|
| 123 | * Empties the current output buffer.
|
---|
| 124 | * @param {Boolean} reset Indicates that the {@link reset} function is to
|
---|
| 125 | * be automatically called after retrieving the HTML.
|
---|
| 126 | * @returns {String} The HTML written to the writer so far.
|
---|
| 127 | * @example
|
---|
| 128 | * var html = writer.getHtml();
|
---|
| 129 | */
|
---|
| 130 | getHtml : function( reset )
|
---|
| 131 | {
|
---|
| 132 | var html = this._.output.join( '' );
|
---|
| 133 |
|
---|
| 134 | if ( reset )
|
---|
| 135 | this.reset();
|
---|
| 136 |
|
---|
| 137 | return html;
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | });
|
---|