From 6808aa3056cb12b2a998630da71dd554d807ea0b Mon Sep 17 00:00:00 2001 From: Binary Date: Tue, 14 May 2013 19:23:31 +0700 Subject: [PATCH 1/4] simplify and fix the test --- tests/functions.27.yate | 66 ++++------------------------------------- 1 file changed, 6 insertions(+), 60 deletions(-) diff --git a/tests/functions.27.yate b/tests/functions.27.yate index 4c43464..904b3b6 100644 --- a/tests/functions.27.yate +++ b/tests/functions.27.yate @@ -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) { @@ -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 } " } } From b626ca000ca0b8367cf59517c110a8fa6daec1ce Mon Sep 17 00:00:00 2001 From: Sergey Dobrov Date: Sun, 12 Jul 2015 21:33:50 +0200 Subject: [PATCH 2/4] first try to use with IncrementalDOM --- lib/asts.js | 2 +- lib/grammar.js | 12 +++++++++ lib/runtime.js | 64 +++++++++++++++++++++-------------------------- templates/js.tmpl | 30 ++++++++++++++++++---- 4 files changed, 67 insertions(+), 41 deletions(-) diff --git a/lib/asts.js b/lib/asts.js index fdf5d4f..7648966 100644 --- a/lib/asts.js +++ b/lib/asts.js @@ -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'); diff --git a/lib/grammar.js b/lib/grammar.js index 56faeca..fd45e8d 100644 --- a/lib/grammar.js +++ b/lib/grammar.js @@ -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('>'); }; @@ -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('/>'); }; diff --git a/lib/runtime.js b/lib/runtime.js index 8f9da94..3bc5ed0 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -29,6 +29,30 @@ var RE_E_AMP = /&/g; var RE_E_LT = /</g; var RE_E_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 = 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 ''; } @@ -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) { diff --git a/templates/js.tmpl b/templates/js.tmpl index 27f7c01..ec72f99 100644 --- a/templates/js.tmpl +++ b/templates/js.tmpl @@ -517,7 +517,7 @@ cdata :listitem cdata :output - r%{ Rid } += %{ Value }; + yr.text(%{ Value }); // ----------------------------------------------------------------------------------------------------------------- // @@ -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%{ Attrs :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 @@ -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 @@ -681,7 +701,7 @@ value :output [ a.getType() === 'attr' ] value :output - r%{ Rid } += %{ Value }; + yr.text(%{ Value }); // --------------------------------------------------------------------------------------------------------------- // From 27852ec5a0f6e82a20f28e26662b3789525d62da Mon Sep 17 00:00:00 2001 From: Sergey Dobrov Date: Tue, 14 Jul 2015 11:04:56 +0200 Subject: [PATCH 3/4] fixed cdata and attrs on start tag --- templates/js.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/js.tmpl b/templates/js.tmpl index ec72f99..9188325 100644 --- a/templates/js.tmpl +++ b/templates/js.tmpl @@ -517,7 +517,7 @@ cdata :listitem cdata :output - yr.text(%{ Value }); + r%{ Rid } += %{ Value }; // ----------------------------------------------------------------------------------------------------------------- // @@ -531,7 +531,7 @@ xml_attr :void xml_attrs :start - , null%{ Attrs :void } + , null%{ . :void } xml_start :output From bbc5f443bbda1e77b12b1685f1f2fb4a53143dd0 Mon Sep 17 00:00:00 2001 From: Sergey Dobrov Date: Wed, 15 Jul 2015 18:27:14 +0200 Subject: [PATCH 4/4] make sure converting nodeset, not scalar --- lib/runtime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime.js b/lib/runtime.js index 3bc5ed0..b0d7fb3 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -41,7 +41,7 @@ yr.text = IDOM.text; var _currentTagName = undefined, _currentTagKey = undefined; yr.elementOpen = function(tagName, tagKey) { - if (tagKey) { + if (tagKey && tagKey.length) { tagKey = yr.nodeset2xml(tagKey); } if (arguments.length > 2) {