@@ -12,12 +12,14 @@ const FramePatternMatcher = {}
12
12
*/
13
13
FramePatternMatcher . testRules = function ( rules , frame , onmatch ) {
14
14
var matched_rules = [ ] ;
15
- for ( var i = 0 ; i < rules . length ; i ++ ) {
16
- var match = ( ! rules [ i ] . pattern || this . patternMatchesFrame ( rules [ i ] . pattern , frame ) ) ;
17
- if ( match ) {
18
- matched_rules . push ( rules [ i ] ) ;
19
- if ( onmatch && typeof onmatch == "function" ) {
20
- onmatch ( frame , rules [ i ] ) ;
15
+ if ( rules && rules . length ) {
16
+ for ( var i = 0 ; i < rules . length ; i ++ ) {
17
+ var match = ( ! rules [ i ] . rule . pattern || FramePatternMatcher . patternMatchesFrame ( rules [ i ] . rule . pattern , frame ) ) ;
18
+ if ( match ) {
19
+ matched_rules . push ( rules [ i ] ) ;
20
+ if ( onmatch && typeof onmatch == "function" ) {
21
+ onmatch ( frame , rules [ i ] ) ;
22
+ }
21
23
}
22
24
}
23
25
}
@@ -66,7 +68,7 @@ FramePattern = function(pattern){
66
68
}
67
69
68
70
FramePattern . prototype . setPattern = function ( pattern ) {
69
- this . renderer = ( pattern . renderer ? pattern . renderer : false ) ;
71
+ this . scope = ( pattern . scope ? pattern . scope : false ) ;
70
72
this . label = ( pattern . label ? pattern . label : false ) ;
71
73
this . frame_type = ( pattern . frame_type ? pattern . frame_type : false ) ;
72
74
this . subject = ( pattern . subject ? pattern . subject : false ) ;
@@ -89,7 +91,7 @@ FramePattern.prototype.setPattern = function(pattern){
89
91
FramePattern . prototype . checkFrame = function ( frame ) {
90
92
var rtype = this . getRendererType ( frame ) ;
91
93
if ( ! rtype ) return false ;
92
- if ( this . renderer && ( this . renderer != rtype ) && ( this . renderer != "*" ) ) return false ;
94
+ if ( this . scope && ( this . scope != rtype ) && ( this . scope != "*" ) ) return false ;
93
95
if ( this . illegalRuleType ( rtype ) ) return false ;
94
96
if ( this . frame_type && ! this . checkFrameType ( rtype , frame ) ) return false ;
95
97
if ( this . label && ! this . checkLabel ( rtype , frame ) ) return false ;
@@ -300,71 +302,169 @@ FramePattern.prototype.getRendererType = function(frame){
300
302
}
301
303
302
304
function FrameRule ( ) {
303
- this . rule = { pattern : { } } ;
305
+ this . rule = { pattern : { } } ;
304
306
return this ;
305
307
}
306
308
307
- FrameRule . prototype . renderer = function ( ...rend ) {
308
- this . rule . pattern . renderer = rend ;
309
- return this ;
310
- }
311
309
312
- FrameRule . prototype . setRenderer = function ( rend ) {
313
- this . rule . renderer = rend ;
314
- return this ;
310
+ FrameRule . prototype . unpack = function ( arr , nonstring ) {
311
+ if ( nonstring ) var str = arr . join ( "," ) ;
312
+ var str = "'" + arr . join ( "','" ) + "'" ;
313
+ return str ;
315
314
}
316
315
317
- FrameRule . prototype . render = function ( func ) {
318
- this . rule . render = func ;
319
- return this ;
320
- }
321
-
322
- FrameRule . prototype . args = function ( json ) {
323
- this . rule . args = json ;
324
- return this ;
316
+ FrameRule . prototype . prettyPrint = function ( type ) {
317
+ //starts with obj. ...
318
+ if ( this . scope ( ) == "*" ) {
319
+ var str = "all()" ;
320
+ }
321
+ else {
322
+ var str = this . scope ( ) + "()" ;
323
+ }
324
+ if ( typeof this . frameType ( ) != "undefined" ) {
325
+ str += ".frame_type(" + this . unpack ( this . frameType ( ) ) + ")" ;
326
+ }
327
+ if ( typeof this . label ( ) != "undefined" ) {
328
+ str += ".label(" + this . unpack ( this . label ( ) ) + ")" ;
329
+ }
330
+ if ( typeof this . subject ( ) != "undefined" ) {
331
+ str += ".subject(" + this . unpack ( this . subject ( ) ) + ")" ;
332
+ }
333
+ if ( typeof this . subjectClass ( ) != "undefined" ) {
334
+ str += ".subjectClass(" + this . unpack ( this . subjectClass ( ) ) + ")" ;
335
+ }
336
+ if ( typeof this . property ( ) != "undefined" ) {
337
+ str += ".property(" + this . unpack ( this . property ( ) ) + ")" ;
338
+ }
339
+ if ( typeof this . range ( ) != "undefined" ) {
340
+ str += ".range(" + this . unpack ( this . range ( ) ) + ")" ;
341
+ }
342
+ if ( typeof this . value ( ) != "undefined" ) {
343
+ str += ".value(" + this . unpack ( this . value ( ) ) + ")" ;
344
+ }
345
+ if ( typeof this . children ( ) != "undefined" && this . children . length > 0 ) {
346
+ str += ".children(\n" ;
347
+ var kids = this . children ( ) ;
348
+ for ( var i = 0 ; i < kids . length ; i ++ ) {
349
+ str += kids . prettyPrint ( ) + "\n" ;
350
+ }
351
+ str += ")" ;
352
+ }
353
+ if ( typeof this . parent ( ) != "undefined" ) {
354
+ str += ".parent(" + this . parent . prettyPrint ( ) + ")" ;
355
+ }
356
+ if ( typeof this . depth ( ) != "undefined" ) {
357
+ str += ".depth('" + this . depth ( ) + "')" ;
358
+ }
359
+ if ( typeof this . index ( ) != "undefined" ) {
360
+ str += ".index(" + this . unpack ( this . index ( ) , true ) + ")" ;
361
+ }
362
+ if ( typeof this . status ( ) != "undefined" ) {
363
+ str += ".status(" + this . unpack ( this . status ( ) ) + ")" ;
364
+ }
365
+ if ( typeof this . renderer ( ) != "undefined" ) {
366
+ str += ".renderer('" + this . renderer ( ) + "')" ;
367
+ }
368
+ if ( typeof this . render ( ) != "undefined" ) {
369
+ str += ".render(" + this . render ( ) + ")" ;
370
+ }
371
+ if ( typeof this . compare ( ) != "undefined" ) {
372
+ str += ".compare(" + this . compare ( ) + ")" ;
373
+ }
374
+ if ( typeof this . mode ( ) != "undefined" ) {
375
+ str += ".mode('" + this . mode ( ) + "')" ;
376
+ }
377
+ if ( typeof this . collapse ( ) != "undefined" ) {
378
+ str += ".collapse(" + this . collapse ( ) + ")" ;
379
+ }
380
+ if ( typeof this . hidden ( ) != "undefined" ) {
381
+ str += ".hidden(" + this . hidden ( ) + ")" ;
382
+ }
383
+ if ( typeof this . view ( ) != "undefined" ) {
384
+ str += ".view('" + this . view ( ) + "')" ;
385
+ }
386
+ if ( typeof this . showDisabledButtons ( ) != "undefined" ) {
387
+ str += ".showDisabledButtons(" + this . showDisabledButtons ( ) + ")" ;
388
+ }
389
+ if ( typeof this . header ( ) != "undefined" ) {
390
+ str += ".header(" + this . header ( ) + ")" ;
391
+ }
392
+ if ( typeof this . features ( ) != "undefined" ) {
393
+ str += ".features(" + this . unpack ( this . features ( ) ) + ")" ;
394
+ }
395
+ if ( typeof this . headerFeatures ( ) != "undefined" ) {
396
+ str += ".headerFeatures(" + this . unpack ( this . headerFeatures ( ) ) + ")" ;
397
+ }
398
+ if ( typeof this . showEmpty ( ) != "undefined" ) {
399
+ str += ".showEmpty(" + this . show_empty ( ) + ")" ;
400
+ }
401
+ if ( typeof this . dataviewer ( ) != "undefined" ) {
402
+ str += ".dataviewer('" + this . dataviewer ( ) + "')" ;
403
+ }
404
+ if ( typeof this . args ( ) != "undefined" ) {
405
+ str += ".args(" + JSON . stringify ( this . args ( ) ) + ")" ;
406
+ }
407
+ if ( typeof this . featureRenderers ( ) != "undefined" ) {
408
+ str += ".featureRenderers({" ;
409
+ for ( var f in this . featureRenderers ( ) ) {
410
+ str += JSON . stringify ( f ) + ":" + this . rule . feature_renderers [ f ] + "," ;
411
+ }
412
+ str = str . substring ( 0 , str . length - 1 ) ;
413
+ str += "})" ;
414
+ }
415
+ return str ;
325
416
}
326
417
327
- FrameRule . prototype . compare = function ( func ) {
328
- this . rule . compare = func ;
418
+ FrameRule . prototype . scope = function ( scope ) {
419
+ if ( typeof scope == "undefined" ) return this . rule . pattern . scope ;
420
+ this . rule . pattern . scope = scope ;
329
421
return this ;
330
422
}
331
423
332
- FrameRule . prototype . frame_type = function ( ...frametype ) {
424
+ FrameRule . prototype . frameType = function ( ...frametype ) {
425
+ if ( typeof frametype == "undefined" || frametype . length == 0 ) return this . rule . pattern . frametype ;
333
426
this . rule . pattern . frametype = frame_type ;
334
427
return this ;
335
428
}
336
429
337
430
FrameRule . prototype . label = function ( ...label ) {
431
+ if ( typeof label == "undefined" || label . length == 0 ) return this . rule . pattern . label ;
338
432
this . rule . pattern . label = label ;
339
433
return this ;
340
434
}
341
435
342
436
FrameRule . prototype . subject = function ( ...subject ) {
437
+ if ( typeof subject == "undefined" || subject . length == 0 ) return this . rule . pattern . subject ;
343
438
this . rule . pattern . subject = subject ;
344
439
return this ;
345
440
}
346
441
347
442
FrameRule . prototype . subjectClass = function ( ...subjectClass ) {
443
+ if ( typeof subjectClass == "undefined" || subjectClass . length == 0 ) return this . rule . pattern . subjectClass ;
348
444
this . rule . pattern . subjectClass = subjectClass ;
349
445
return this ;
350
446
}
351
447
352
448
FrameRule . prototype . property = function ( ...property ) {
449
+ if ( typeof property == "undefined" || property . length == 0 ) return this . rule . pattern . property ;
353
450
this . rule . pattern . property = property ;
354
451
return this ;
355
452
}
356
453
357
454
FrameRule . prototype . depth = function ( depth ) {
455
+ if ( typeof depth == "undefined" ) return this . rule . pattern . depth ;
358
456
this . rule . pattern . depth = depth ;
359
457
return this ;
360
458
}
361
459
362
460
FrameRule . prototype . range = function ( ...range ) {
461
+ if ( typeof range == "undefined" || range . length == 0 ) return this . rule . pattern . range ;
363
462
this . rule . pattern . range = range ;
364
463
return this ;
365
464
}
366
465
367
466
FrameRule . prototype . value = function ( ...value ) {
467
+ if ( typeof value == "undefined" || value . length == 0 ) return this . rule . pattern . value ;
368
468
this . rule . pattern . value = value ;
369
469
return this ;
370
470
}
@@ -378,11 +478,13 @@ FrameRule.prototype.json = function(){
378
478
}
379
479
380
480
FrameRule . prototype . parent = function ( parent ) {
481
+ if ( typeof parent == "undefined" ) return this . rule . pattern . parent ;
381
482
this . rule . pattern . parent = parent . pattern ( ) ;
382
483
return this ;
383
484
}
384
485
385
486
FrameRule . prototype . children = function ( ...children ) {
487
+ if ( typeof children == "undefined" ) return this . rule . pattern . children ;
386
488
if ( typeof this . rule . pattern . children == "undefined" ) {
387
489
this . rule . pattern . children = [ ] ;
388
490
}
@@ -393,14 +495,108 @@ FrameRule.prototype.children = function(...children){
393
495
}
394
496
395
497
FrameRule . prototype . index = function ( ...index ) {
498
+ if ( typeof index == "undefined" || index . length == 0 ) return this . rule . pattern . index ;
396
499
this . rule . pattern . index = index ;
397
500
return this ;
398
501
}
399
502
400
503
FrameRule . prototype . status = function ( ...status ) {
504
+ if ( typeof status == "undefined" || status . length == 0 ) return this . rule . pattern . status ;
401
505
this . rule . pattern . status = status ;
402
506
return this ;
403
507
}
404
508
509
+ FrameRule . prototype . renderer = function ( rend ) {
510
+ if ( ! rend ) return this . rule . renderer ;
511
+ this . rule . renderer = rend ;
512
+ return this ;
513
+ }
514
+
515
+ FrameRule . prototype . render = function ( func ) {
516
+ if ( func ) {
517
+ this . rule . render = func ;
518
+ return this ;
519
+ }
520
+ return func ;
521
+ }
522
+
523
+ FrameRule . prototype . args = function ( json ) {
524
+ if ( ! json ) return this . rule . args ;
525
+ this . rule . args = json ;
526
+ return this ;
527
+ }
528
+
529
+ FrameRule . prototype . compare = function ( func ) {
530
+ if ( ! func ) return this . rule . compare ;
531
+ this . rule . compare = func ;
532
+ return this ;
533
+ }
534
+
535
+ FrameRule . prototype . mode = function ( m ) {
536
+ if ( ! m ) return this . rule . mode ;
537
+ this . rule . mode = m ;
538
+ return this ;
539
+ }
540
+
541
+ FrameRule . prototype . collapse = function ( m ) {
542
+ if ( ! m ) return this . rule . collapse ;
543
+ this . rule . collapse = m ;
544
+ return this ;
545
+ }
546
+
547
+
548
+ FrameRule . prototype . hidden = function ( m ) {
549
+ if ( ! m ) return this . rule . hidden ;
550
+ this . rule . hidden = m ;
551
+ return this ;
552
+ }
553
+
554
+ FrameRule . prototype . view = function ( m ) {
555
+ if ( ! m ) return this . rule . view ;
556
+ this . rule . view = m ;
557
+ return this ;
558
+ }
559
+
560
+ FrameRule . prototype . showDisabledButtons = function ( m ) {
561
+ if ( ! m ) return this . rule . show_disabled_buttons ;
562
+ this . rule . show_disabled_buttons = m ;
563
+ return this ;
564
+ }
565
+
566
+ FrameRule . prototype . features = function ( ...m ) {
567
+ if ( typeof m == "undefined" || m . length == 0 ) return this . rule . features ;
568
+ this . rule . features = m ;
569
+ return this ;
570
+ }
571
+
572
+ FrameRule . prototype . headerFeatures = function ( ...m ) {
573
+ if ( typeof m == "undefined" || m . length == 0 ) return this . rule . header_features ;
574
+ this . rule . header_features = m ;
575
+ return this ;
576
+ }
577
+
578
+ FrameRule . prototype . header = function ( m ) {
579
+ if ( ! m ) return this . rule . header ;
580
+ this . rule . header = m ;
581
+ return this ;
582
+ }
583
+
584
+ FrameRule . prototype . featureRenderers = function ( m ) {
585
+ if ( ! m ) return this . rule . feature_renderers ;
586
+ this . rule . feature_renderers = m ;
587
+ return this ;
588
+ }
589
+
590
+ FrameRule . prototype . showEmpty = function ( m ) {
591
+ if ( ! m ) return this . rule . show_empty ;
592
+ this . rule . show_empty = m ;
593
+ return this ;
594
+ }
595
+
596
+ FrameRule . prototype . dataviewer = function ( m ) {
597
+ if ( ! m ) return this . rule . dataviewer ;
598
+ this . rule . dataviewer = m ;
599
+ return this ;
600
+ }
405
601
406
- module . exports = { FramePatternMatcher, FrameRule} ;
602
+ module . exports = { FramePatternMatcher, FramePattern , FrameRule } ;
0 commit comments