JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / core / htmlparser / basicwriter.js
diff --git a/_source/core/htmlparser/basicwriter.js b/_source/core/htmlparser/basicwriter.js
new file mode 100644 (file)
index 0000000..ecb45f6
--- /dev/null
@@ -0,0 +1,140 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+CKEDITOR.htmlParser.basicWriter = CKEDITOR.tools.createClass(\r
+{\r
+       $ : function()\r
+       {\r
+               this._ =\r
+               {\r
+                       output : []\r
+               };\r
+       },\r
+\r
+       proto :\r
+       {\r
+               /**\r
+                * Writes the tag opening part for a opener tag.\r
+                * @param {String} tagName The element name for this tag.\r
+                * @param {Object} attributes The attributes defined for this tag. The\r
+                *              attributes could be used to inspect the tag.\r
+                * @example\r
+                * // Writes "<p".\r
+                * writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } );\r
+                */\r
+               openTag : function( tagName, attributes )\r
+               {\r
+                       this._.output.push( '<', tagName );\r
+               },\r
+\r
+               /**\r
+                * Writes the tag closing part for a opener tag.\r
+                * @param {String} tagName The element name for this tag.\r
+                * @param {Boolean} isSelfClose Indicates that this is a self-closing tag,\r
+                *              like "br" or "img".\r
+                * @example\r
+                * // Writes "&gt;".\r
+                * writer.openTagClose( 'p', false );\r
+                * @example\r
+                * // Writes " /&gt;".\r
+                * writer.openTagClose( 'br', true );\r
+                */\r
+               openTagClose : function( tagName, isSelfClose )\r
+               {\r
+                       if ( isSelfClose )\r
+                               this._.output.push( ' />' );\r
+                       else\r
+                               this._.output.push( '>' );\r
+               },\r
+\r
+               /**\r
+                * Writes an attribute. This function should be called after opening the\r
+                * tag with {@link #openTagClose}.\r
+                * @param {String} attName The attribute name.\r
+                * @param {String} attValue The attribute value.\r
+                * @example\r
+                * // Writes ' class="MyClass"'.\r
+                * writer.attribute( 'class', 'MyClass' );\r
+                */\r
+               attribute : function( attName, attValue )\r
+               {\r
+                       this._.output.push( ' ', attName, '="', attValue, '"' );\r
+               },\r
+\r
+               /**\r
+                * Writes a closer tag.\r
+                * @param {String} tagName The element name for this tag.\r
+                * @example\r
+                * // Writes "&lt;/p&gt;".\r
+                * writer.closeTag( 'p' );\r
+                */\r
+               closeTag : function( tagName )\r
+               {\r
+                       this._.output.push( '</', tagName, '>' );\r
+               },\r
+\r
+               /**\r
+                * Writes text.\r
+                * @param {String} text The text value\r
+                * @example\r
+                * // Writes "Hello Word".\r
+                * writer.text( 'Hello Word' );\r
+                */\r
+               text : function( text )\r
+               {\r
+                       this._.output.push( text );\r
+               },\r
+\r
+               /**\r
+                * Writes a comment.\r
+                * @param {String} comment The comment text.\r
+                * @example\r
+                * // Writes "&lt;!-- My comment --&gt;".\r
+                * writer.comment( ' My comment ' );\r
+                */\r
+               comment : function( comment )\r
+               {\r
+                       this._.output.push( '<!--', comment, '-->' );\r
+               },\r
+\r
+               /**\r
+                * Writes any kind of data to the ouput.\r
+                * @example\r
+                * writer.write( 'This is an &lt;b&gt;example&lt;/b&gt;.' );\r
+                */\r
+               write : function( data )\r
+               {\r
+                       this._.output.push( data );\r
+               },\r
+\r
+               /**\r
+                * Empties the current output buffer.\r
+                * @example\r
+                * writer.reset();\r
+                */\r
+               reset : function()\r
+               {\r
+                       this._.output = [];\r
+               },\r
+\r
+               /**\r
+                * Empties the current output buffer.\r
+                * @param {Boolean} reset Indicates that the {@link reset} function is to\r
+                *              be automatically called after retrieving the HTML.\r
+                * @returns {String} The HTML written to the writer so far.\r
+                * @example\r
+                * var html = writer.getHtml();\r
+                */\r
+               getHtml : function( reset )\r
+               {\r
+                       var html = this._.output.join( '' );\r
+\r
+                       if ( reset )\r
+                               this.reset();\r
+\r
+                       return html;\r
+               }\r
+       }\r
+});\r