00001
00002 (function() {
00003 var XMLDTDAttList, create;
00004
00005 create = require('lodash/create');
00006
00007 module.exports = XMLDTDAttList = (function() {
00008 function XMLDTDAttList(parent, elementName, attributeName, attributeType, defaultValueType, defaultValue) {
00009 this.stringify = parent.stringify;
00010 if (elementName == null) {
00011 throw new Error("Missing DTD element name");
00012 }
00013 if (attributeName == null) {
00014 throw new Error("Missing DTD attribute name");
00015 }
00016 if (!attributeType) {
00017 throw new Error("Missing DTD attribute type");
00018 }
00019 if (!defaultValueType) {
00020 throw new Error("Missing DTD attribute default");
00021 }
00022 if (defaultValueType.indexOf('#') !== 0) {
00023 defaultValueType = '#' + defaultValueType;
00024 }
00025 if (!defaultValueType.match(/^(#REQUIRED|#IMPLIED|#FIXED|#DEFAULT)$/)) {
00026 throw new Error("Invalid default value type; expected: #REQUIRED, #IMPLIED, #FIXED or #DEFAULT");
00027 }
00028 if (defaultValue && !defaultValueType.match(/^(#FIXED|#DEFAULT)$/)) {
00029 throw new Error("Default value only applies to #FIXED or #DEFAULT");
00030 }
00031 this.elementName = this.stringify.eleName(elementName);
00032 this.attributeName = this.stringify.attName(attributeName);
00033 this.attributeType = this.stringify.dtdAttType(attributeType);
00034 this.defaultValue = this.stringify.dtdAttDefault(defaultValue);
00035 this.defaultValueType = defaultValueType;
00036 }
00037
00038 XMLDTDAttList.prototype.toString = function(options, level) {
00039 var indent, newline, offset, pretty, r, ref, ref1, ref2, space;
00040 pretty = (options != null ? options.pretty : void 0) || false;
00041 indent = (ref = options != null ? options.indent : void 0) != null ? ref : ' ';
00042 offset = (ref1 = options != null ? options.offset : void 0) != null ? ref1 : 0;
00043 newline = (ref2 = options != null ? options.newline : void 0) != null ? ref2 : '\n';
00044 level || (level = 0);
00045 space = new Array(level + offset + 1).join(indent);
00046 r = '';
00047 if (pretty) {
00048 r += space;
00049 }
00050 r += '<!ATTLIST ' + this.elementName + ' ' + this.attributeName + ' ' + this.attributeType;
00051 if (this.defaultValueType !== '#DEFAULT') {
00052 r += ' ' + this.defaultValueType;
00053 }
00054 if (this.defaultValue) {
00055 r += ' "' + this.defaultValue + '"';
00056 }
00057 r += '>';
00058 if (pretty) {
00059 r += newline;
00060 }
00061 return r;
00062 };
00063
00064 return XMLDTDAttList;
00065
00066 })();
00067
00068 }).call(this);