3 var XMLDTDAttList, create;
5 create = require(
'lodash/create');
7 module.exports = XMLDTDAttList = (
function() {
8 function XMLDTDAttList(parent, elementName, attributeName, attributeType, defaultValueType, defaultValue) {
9 this.stringify = parent.stringify;
10 if (elementName == null) {
11 throw new Error(
"Missing DTD element name");
13 if (attributeName == null) {
14 throw new Error(
"Missing DTD attribute name");
17 throw new Error(
"Missing DTD attribute type");
19 if (!defaultValueType) {
20 throw new Error(
"Missing DTD attribute default");
22 if (defaultValueType.indexOf(
'#') !== 0) {
23 defaultValueType =
'#' + defaultValueType;
25 if (!defaultValueType.match(/^(#REQUIRED|#IMPLIED|#FIXED|#DEFAULT)$/)) {
26 throw new Error(
"Invalid default value type; expected: #REQUIRED, #IMPLIED, #FIXED or #DEFAULT");
28 if (defaultValue && !defaultValueType.match(/^(#FIXED|#DEFAULT)$/)) {
29 throw new Error(
"Default value only applies to #FIXED or #DEFAULT");
31 this.elementName = this.stringify.eleName(elementName);
32 this.attributeName = this.stringify.attName(attributeName);
33 this.attributeType = this.stringify.dtdAttType(attributeType);
34 this.defaultValue = this.stringify.dtdAttDefault(defaultValue);
35 this.defaultValueType = defaultValueType;
38 XMLDTDAttList.prototype.toString =
function(options, level) {
39 var indent, newline, offset, pretty, r, ref, ref1, ref2, space;
40 pretty = (options != null ? options.pretty :
void 0) ||
false;
41 indent = (ref = options != null ? options.indent :
void 0) != null ? ref :
' ';
42 offset = (ref1 = options != null ? options.offset :
void 0) != null ? ref1 : 0;
43 newline = (ref2 = options != null ? options.newline :
void 0) != null ? ref2 :
'\n';
45 space =
new Array(level + offset + 1).join(indent);
50 r +=
'<!ATTLIST ' + this.elementName +
' ' + this.attributeName +
' ' + this.attributeType;
51 if (this.defaultValueType !==
'#DEFAULT') {
52 r +=
' ' + this.defaultValueType;
54 if (this.defaultValue) {
55 r +=
' "' + this.defaultValue +
'"';