Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/asts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ yate.asts.attrs_open._init = function(item) {
// но w_setTypes для xml_attr случает раньше этого.
this.p.Attrs.parent = this;
// FIXME: В правой части, похоже, можно что угодно написать. Нужна ли эта строчка вообще?
item.p.Attrs = null;
delete item.p.Attrs;
};

yate.asts.attrs_open._getType = no.value('xml');
Expand Down
12 changes: 12 additions & 0 deletions lib/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@ rules.xml_full = {
rules.xml_start = function(p, a) {
this.match('<');
p.Name = this.match('QNAME');
if (this.test('#')) {
this.match('#');
p.Key = this.match('inline_string');
} else {
p.Key = 'null';
}
p.Attrs = this.match('xml_attrs');
this.match('>');
};
Expand All @@ -659,6 +665,12 @@ rules.xml_start = function(p, a) {
rules.xml_empty = function(p, a) {
this.match('<');
p.Name = this.match('QNAME');
if (this.test('#')) {
this.match('#');
p.Key = this.match('inline_string');
} else {
p.Key = 'null';
}
p.Attrs = this.match('xml_attrs');
this.match('/>');
};
Expand Down
64 changes: 29 additions & 35 deletions lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ var RE_E_AMP = /&amp;/g;
var RE_E_LT = /&lt;/g;
var RE_E_GT = /&gt;/g;

if (typeof module !== 'undefined') {
var IDOM = {};
} else {
var IDOM = window.IncrementalDOM || {};
}
var _elementOpen = IDOM.elementOpen;
yr.elementVoid = IDOM.elementVoid;
yr.elementClose = IDOM.elementClose;
yr.text = IDOM.text;

var _currentTagName = undefined, _currentTagKey = undefined;
yr.elementOpen = function(tagName, tagKey) {
if (tagKey && tagKey.length) {
tagKey = yr.nodeset2xml(tagKey);
}
if (arguments.length > 2) {
arguments[1] = tagKey;
_elementOpen.apply(null, arguments);
} else {
_currentTagName = tagName;
_currentTagKey = tagKey;
}
}

yr.text2xml = function(s) {
if (s == null) { return ''; }

Expand Down Expand Up @@ -310,47 +334,17 @@ yr.closeAttrs = function closeAttrs(a) {
var name = a.s;

if (name) {
var r = '';
var attrs = a.a;

var args = [_currentTagName, _currentTagKey, null];

for (var attr in attrs) {
r += ' ' + attr + '="' + attrs[attr].quote() + '"';
args.push(attr);
args.push(attrs[attr].quote());
}
/*
for (var attr in attrs) {
if ( attrs.hasOwnProperty(attr) ) {
var v = attrs[attr];
if (v.quote) {
r += ' ' + attr + '="' + v.quote() + '"';
} else {
yr.log({
id: 'NO_QUOTE',
message: "Attr doesn't have quote() method",
data: {
key: attr,
value: v
}
});
}
} else {
yr.log({
id: 'BAD_PROTOTYPE',
message: 'Object prototype is corrupted',
data: {
key: attr,
value: v
}
});
}
}
*/
r += (yr.shortTags[name]) ? '/>' : '>';
_elementOpen.apply(undefined, args);
a.s = null;

return r;
}

return '';
};

yr.copyAttrs = function copyAttrs(to, from) {
Expand Down
28 changes: 24 additions & 4 deletions templates/js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,29 @@ xml_attr :open

'%{ Name }': new yr.scalarAttr(%{ Value })

xml_line :output
xml_attr :void

r%{ Rid } += %{ . :content };
, '%{ Name }', %{ Value }

xml_attrs :start

, null%{ . :void }

xml_start :output

yr.elementOpen('%{ Name }', %{ Key }%{ Attrs :start });

xml_empty :output

yr.elementVoid('%{ Name }', %{ Key }, null%{ Attrs :void });

xml_end :output

yr.elementClose('%{ Name }');

xml_text :output

yr.text(%{ Text });

xml_line :listitem

Expand Down Expand Up @@ -571,7 +591,7 @@ attr :output
a%{ Rid }.a[ %{ Name } ] = new yr.%{ AttrType }Attr(r%{ Value.Rid });

attrs_close :output
r%{ Rid } += closeAttrs(a%{ Rid });
closeAttrs(a%{ Rid });

attrs_open :output

Expand Down Expand Up @@ -681,7 +701,7 @@ value :output [ a.getType() === 'attr' ]

value :output

r%{ Rid } += %{ Value };
yr.text(%{ Value });


// --------------------------------------------------------------------------------------------------------------- //
Expand Down
66 changes: 6 additions & 60 deletions tests/functions.27.yate
Original file line number Diff line number Diff line change
@@ -1,73 +1,32 @@
/// {
/// description: 'sorts',
/// description: 'custom function in predicate',
/// data: {
/// nickname: "Binary",
/// my_presence: {
/// priority: 0,
/// status: 'Hey ho!',
/// show: 'dnd'
/// },
/// view: [{
/// pk: 'singleton',
/// collapsed_groups: []
/// }],
/// roster: {
/// items: [
/// {
/// ask: undefined,
/// groups: [1],
/// jid: undefined,
/// nick: 'z',
/// pk: 1,
/// presences: [],
/// subscription: 'none'
/// },
/// {
/// ask: undefined,
/// groups: [1],
/// jid: undefined,
/// nick: 'f',
/// pk: 2,
/// presences: [],
/// subscription: 'none'
/// },
/// {
/// ask: undefined,
/// groups: [1],
/// jid: undefined,
/// nick: 'a',
/// pk: 2,
/// presences: [],
/// subscription: 'none'
/// },
/// {
/// ask: undefined,
/// groups: [2],
/// jid: undefined,
/// nick: '2nd_group',
/// pk: 2,
/// presences: [],
/// subscription: 'none'
/// }
/// ],
/// groups: [
/// {
/// name: 'Undefined',
/// pk: 0,
/// special_group: 'undefined'
/// },
/// {
/// name: 'group b',
/// pk: 2
/// },
/// {
/// name: 'group a',
/// pk: 1
/// }
/// ]
/// }
/// },
/// result: 'group a:f '
/// },
/// result: 'f '
/// }

func get_contact_jid(nodeset contact) {
Expand All @@ -88,21 +47,8 @@ func get_contact_display(nodeset contact) {
}

match / {
apply .roster render_roster
}

match .roster render_roster {
for sort(.groups, .name) {
gpk = .pk
contacts = ..items[ .groups == gpk ]
if exists(contacts) {
"{ .name }:"
if !exists(...view.collapsed_groups[. == gpk]) {
filtered_contacts = contacts[get_contact_display(.) == "f"]
for filtered_contacts {
"{ .nick } "
}
}
}
filtered_contacts = .roster.items[get_contact_display(.) == "f"]
for filtered_contacts {
"{ .nick } "
}
}