joosy 1.2.0.alpha.17 → 1.2.0.alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/Gruntfile.coffee +2 -2
 - data/bower.json +1 -1
 - data/lib/joosy.js +26 -8
 - data/package.json +1 -1
 - data/spec/joosy/core/modules/container_spec.coffee +26 -1
 - data/src/joosy/core/modules/container.coffee +20 -7
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: d232c00d880bc16f1347e116474c34f5ee7c3b69
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: c4a4c4517e783adfd098f86f37c70053150d63e1
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7a3c770e88bd3ee3014e09eb34f27a2003cd2b82aa554b1cd65fe4f59d5b48725192f075160e72d46624ea3cb87b254cec53553e5bd1ec1643ce2d9c2f9544b9
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 8a78a3f51594c528eaa37e9a2058722b9ef6935a3cd18f085196181c58bbb94418ac49486cc1f61963e906a852d556c1137ce58a192ea1188dd649fafa87732b
         
     | 
    
        data/Gruntfile.coffee
    CHANGED
    
    | 
         @@ -62,12 +62,12 @@ module.exports = (grunt) -> 
     | 
|
| 
       62 
62 
     | 
    
         
             
                watch:
         
     | 
| 
       63 
63 
     | 
    
         
             
                  source:
         
     | 
| 
       64 
64 
     | 
    
         
             
                    files: [locations.source.path + '/**/*']
         
     | 
| 
       65 
     | 
    
         
            -
                    tasks: ['mince' 
     | 
| 
      
 65 
     | 
    
         
            +
                    tasks: ['mince']
         
     | 
| 
       66 
66 
     | 
    
         
             
                  specs:
         
     | 
| 
       67 
67 
     | 
    
         
             
                    options:
         
     | 
| 
       68 
68 
     | 
    
         
             
                      nospawn: true
         
     | 
| 
       69 
69 
     | 
    
         
             
                    files: [locations.specs.units.core, locations.specs.units.extensions, locations.specs.helpers]
         
     | 
| 
       70 
     | 
    
         
            -
                    tasks: ['coffee' 
     | 
| 
      
 70 
     | 
    
         
            +
                    tasks: ['coffee']
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                coffee:
         
     | 
| 
       73 
73 
     | 
    
         
             
                  specs:
         
     | 
    
        data/bower.json
    CHANGED
    
    
    
        data/lib/joosy.js
    CHANGED
    
    | 
         @@ -543,9 +543,7 @@ Joosy.Modules.Container = { 
     | 
|
| 
       543 
543 
     | 
    
         
             
              },
         
     | 
| 
       544 
544 
     | 
    
         
             
              refreshElements: function() {
         
     | 
| 
       545 
545 
     | 
    
         
             
                var _this = this;
         
     | 
| 
       546 
     | 
    
         
            -
                this. 
     | 
| 
       547 
     | 
    
         
            -
                  return _this['$' + key] = _this.$(value);
         
     | 
| 
       548 
     | 
    
         
            -
                });
         
     | 
| 
      
 546 
     | 
    
         
            +
                this.__assignElements(this, this.__collectElements());
         
     | 
| 
       549 
547 
     | 
    
         
             
                if (this.hasOwnProperty("__onRefreshes")) {
         
     | 
| 
       550 
548 
     | 
    
         
             
                  this.__onRefreshes.each(function(callback) {
         
     | 
| 
       551 
549 
     | 
    
         
             
                    return callback.apply(_this);
         
     | 
| 
         @@ -553,6 +551,18 @@ Joosy.Modules.Container = { 
     | 
|
| 
       553 
551 
     | 
    
         
             
                  return this.__onRefreshes = [];
         
     | 
| 
       554 
552 
     | 
    
         
             
                }
         
     | 
| 
       555 
553 
     | 
    
         
             
              },
         
     | 
| 
      
 554 
     | 
    
         
            +
              __assignElements: function(root, entries) {
         
     | 
| 
      
 555 
     | 
    
         
            +
                var _this = this;
         
     | 
| 
      
 556 
     | 
    
         
            +
                return Object.each(entries, function(key, value) {
         
     | 
| 
      
 557 
     | 
    
         
            +
                  if (Object.isObject(value)) {
         
     | 
| 
      
 558 
     | 
    
         
            +
                    return _this.__assignElements(root['$' + key] = {}, value);
         
     | 
| 
      
 559 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 560 
     | 
    
         
            +
                    value = _this.__extractSelector(value);
         
     | 
| 
      
 561 
     | 
    
         
            +
                    root['$' + key] = _this.$(value);
         
     | 
| 
      
 562 
     | 
    
         
            +
                    return root['$' + key].selector = value;
         
     | 
| 
      
 563 
     | 
    
         
            +
                  }
         
     | 
| 
      
 564 
     | 
    
         
            +
                });
         
     | 
| 
      
 565 
     | 
    
         
            +
              },
         
     | 
| 
       556 
566 
     | 
    
         
             
              reloadContainer: function(htmlCallback) {
         
     | 
| 
       557 
567 
     | 
    
         
             
                if (typeof this.__removeMetamorphs === "function") {
         
     | 
| 
       558 
568 
     | 
    
         
             
                  this.__removeMetamorphs();
         
     | 
| 
         @@ -584,11 +594,19 @@ Joosy.Modules.Container = { 
     | 
|
| 
       584 
594 
     | 
    
         
             
                return events;
         
     | 
| 
       585 
595 
     | 
    
         
             
              },
         
     | 
| 
       586 
596 
     | 
    
         
             
              __extractSelector: function(selector) {
         
     | 
| 
       587 
     | 
    
         
            -
                var  
     | 
| 
       588 
     | 
    
         
            -
                 
     | 
| 
       589 
     | 
    
         
            -
                   
     | 
| 
       590 
     | 
    
         
            -
             
     | 
| 
       591 
     | 
    
         
            -
             
     | 
| 
      
 597 
     | 
    
         
            +
                var _this = this;
         
     | 
| 
      
 598 
     | 
    
         
            +
                selector = selector.replace(/(\$[A-z0-9\.\$]+)/g, function(path) {
         
     | 
| 
      
 599 
     | 
    
         
            +
                  var keyword, part, target, _i, _len, _ref;
         
     | 
| 
      
 600 
     | 
    
         
            +
                  path = path.split('.');
         
     | 
| 
      
 601 
     | 
    
         
            +
                  keyword = path.pop();
         
     | 
| 
      
 602 
     | 
    
         
            +
                  target = _this;
         
     | 
| 
      
 603 
     | 
    
         
            +
                  for (_i = 0, _len = path.length; _i < _len; _i++) {
         
     | 
| 
      
 604 
     | 
    
         
            +
                    part = path[_i];
         
     | 
| 
      
 605 
     | 
    
         
            +
                    target = target != null ? target[part] : void 0;
         
     | 
| 
      
 606 
     | 
    
         
            +
                  }
         
     | 
| 
      
 607 
     | 
    
         
            +
                  return target != null ? (_ref = target[keyword]) != null ? _ref.selector : void 0 : void 0;
         
     | 
| 
      
 608 
     | 
    
         
            +
                });
         
     | 
| 
      
 609 
     | 
    
         
            +
                return selector.trim();
         
     | 
| 
       592 
610 
     | 
    
         
             
              },
         
     | 
| 
       593 
611 
     | 
    
         
             
              __delegateEvents: function() {
         
     | 
| 
       594 
612 
     | 
    
         
             
                var events, module,
         
     | 
    
        data/package.json
    CHANGED
    
    
| 
         @@ -5,12 +5,18 @@ describe "Joosy.Modules.Container", -> 
     | 
|
| 
       5 
5 
     | 
    
         
             
                class @TestContainer extends Joosy.Module
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @include Joosy.Modules.Container
         
     | 
| 
       7 
7 
     | 
    
         
             
                  elements:
         
     | 
| 
      
 8 
     | 
    
         
            +
                    content:
         
     | 
| 
      
 9 
     | 
    
         
            +
                      post1: '#post1'
         
     | 
| 
      
 10 
     | 
    
         
            +
                      post2: '#post2'
         
     | 
| 
       8 
11 
     | 
    
         
             
                    footer: '.footer'
         
     | 
| 
       9 
12 
     | 
    
         
             
                  events:
         
     | 
| 
       10 
13 
     | 
    
         
             
                    'test': 'onContainerTest'
         
     | 
| 
       11 
14 
     | 
    
         
             
                  container: $('#application', @ground)
         
     | 
| 
       12 
15 
     | 
    
         
             
                @box = new @TestContainer()
         
     | 
| 
       13 
16 
     | 
    
         | 
| 
      
 17 
     | 
    
         
            +
              it "assigns nested elements", ->
         
     | 
| 
      
 18 
     | 
    
         
            +
                @box.refreshElements()
         
     | 
| 
      
 19 
     | 
    
         
            +
                expect(@box.$content.$post1.get 0).toBe $('#post1').get 0
         
     | 
| 
       14 
20 
     | 
    
         | 
| 
       15 
21 
     | 
    
         
             
              it "should have property named per declared element in container", ->
         
     | 
| 
       16 
22 
     | 
    
         
             
                @ground.prepend('<div class="footer" />')  # out of container
         
     | 
| 
         @@ -44,17 +50,35 @@ describe "Joosy.Modules.Container", -> 
     | 
|
| 
       44 
50 
     | 
    
         
             
                subBox = new SubContainerB()
         
     | 
| 
       45 
51 
     | 
    
         
             
                target = subBox.__collectElements()
         
     | 
| 
       46 
52 
     | 
    
         
             
                expect(target).toEqual Object.extended
         
     | 
| 
      
 53 
     | 
    
         
            +
                  content: 
         
     | 
| 
      
 54 
     | 
    
         
            +
                    post1: '#post1'
         
     | 
| 
      
 55 
     | 
    
         
            +
                    post2: '#post2'
         
     | 
| 
       47 
56 
     | 
    
         
             
                  first: 'overrided'
         
     | 
| 
       48 
57 
     | 
    
         
             
                  second: 'second'
         
     | 
| 
       49 
58 
     | 
    
         
             
                  third: 'third'
         
     | 
| 
       50 
59 
     | 
    
         
             
                  footer: '.footer'
         
     | 
| 
       51 
60 
     | 
    
         
             
                target = (new @TestContainer()).__collectElements()
         
     | 
| 
       52 
     | 
    
         
            -
                expect(target).toEqual Object.extended 
     | 
| 
      
 61 
     | 
    
         
            +
                expect(target).toEqual Object.extended
         
     | 
| 
      
 62 
     | 
    
         
            +
                  footer: '.footer'
         
     | 
| 
      
 63 
     | 
    
         
            +
                  content: 
         
     | 
| 
      
 64 
     | 
    
         
            +
                    post1: '#post1'
         
     | 
| 
      
 65 
     | 
    
         
            +
                    post2: '#post2'
         
     | 
| 
       53 
66 
     | 
    
         | 
| 
       54 
67 
     | 
    
         
             
              it "should resolve element selector", ->
         
     | 
| 
      
 68 
     | 
    
         
            +
                @box.refreshElements()
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
       55 
70 
     | 
    
         
             
                target = @box.__extractSelector '$footer'
         
     | 
| 
       56 
71 
     | 
    
         
             
                expect(target).toEqual '.footer'
         
     | 
| 
       57 
72 
     | 
    
         | 
| 
      
 73 
     | 
    
         
            +
                target = @box.__extractSelector '$content.$post1'
         
     | 
| 
      
 74 
     | 
    
         
            +
                expect(target).toEqual '#post1'
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                target = @box.__extractSelector '$footer tr'
         
     | 
| 
      
 77 
     | 
    
         
            +
                expect(target).toEqual '.footer tr'
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                target = @box.__extractSelector '$footer $content.$post1'
         
     | 
| 
      
 80 
     | 
    
         
            +
                expect(target).toEqual '.footer #post1'
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
       58 
82 
     | 
    
         
             
              it "should inherit event declarations", ->
         
     | 
| 
       59 
83 
     | 
    
         
             
                class SubContainerA extends @TestContainer
         
     | 
| 
       60 
84 
     | 
    
         
             
                  events:
         
     | 
| 
         @@ -75,6 +99,7 @@ describe "Joosy.Modules.Container", -> 
     | 
|
| 
       75 
99 
     | 
    
         
             
                expect(target).toEqual Object.extended('test': 'onContainerTest')
         
     | 
| 
       76 
100 
     | 
    
         | 
| 
       77 
101 
     | 
    
         
             
              it "should delegate events", ->
         
     | 
| 
      
 102 
     | 
    
         
            +
                @box.refreshElements()
         
     | 
| 
       78 
103 
     | 
    
         
             
                callback = 1.upto(3).map -> sinon.spy()
         
     | 
| 
       79 
104 
     | 
    
         
             
                @box.events = Object.extended(@box.events).merge
         
     | 
| 
       80 
105 
     | 
    
         
             
                  'test .post': callback[2]
         
     | 
| 
         @@ -27,14 +27,21 @@ Joosy.Modules.Container = 
     | 
|
| 
       27 
27 
     | 
    
         
             
              #     bar: '.bar'
         
     | 
| 
       28 
28 
     | 
    
         
             
              #
         
     | 
| 
       29 
29 
     | 
    
         
             
              refreshElements: ->
         
     | 
| 
       30 
     | 
    
         
            -
                @__collectElements() 
     | 
| 
       31 
     | 
    
         
            -
                  # TODO: Check for possible collisions?
         
     | 
| 
       32 
     | 
    
         
            -
                  @['$'+key] = @$(value)
         
     | 
| 
      
 30 
     | 
    
         
            +
                @__assignElements @, @__collectElements()
         
     | 
| 
       33 
31 
     | 
    
         | 
| 
       34 
32 
     | 
    
         
             
                if @hasOwnProperty "__onRefreshes"
         
     | 
| 
       35 
33 
     | 
    
         
             
                  @__onRefreshes.each (callback) => callback.apply @
         
     | 
| 
       36 
34 
     | 
    
         
             
                  @__onRefreshes = []
         
     | 
| 
       37 
35 
     | 
    
         | 
| 
      
 36 
     | 
    
         
            +
              __assignElements: (root, entries) ->
         
     | 
| 
      
 37 
     | 
    
         
            +
                Object.each entries, (key, value) =>
         
     | 
| 
      
 38 
     | 
    
         
            +
                  if Object.isObject(value)
         
     | 
| 
      
 39 
     | 
    
         
            +
                    @__assignElements root['$'+key]={}, value
         
     | 
| 
      
 40 
     | 
    
         
            +
                  else
         
     | 
| 
      
 41 
     | 
    
         
            +
                    value = @__extractSelector value
         
     | 
| 
      
 42 
     | 
    
         
            +
                    root['$'+key] = @$(value)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    root['$'+key].selector = value
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       38 
45 
     | 
    
         
             
              #
         
     | 
| 
       39 
46 
     | 
    
         
             
              # Clears old HTML links, set the new HTML from the callback and refreshes elements
         
     | 
| 
       40 
47 
     | 
    
         
             
              #
         
     | 
| 
         @@ -86,10 +93,16 @@ Joosy.Modules.Container = 
     | 
|
| 
       86 
93 
     | 
    
         
             
              # @param [String] selector            Selector to convert
         
     | 
| 
       87 
94 
     | 
    
         
             
              #
         
     | 
| 
       88 
95 
     | 
    
         
             
              __extractSelector: (selector) ->
         
     | 
| 
       89 
     | 
    
         
            -
                 
     | 
| 
       90 
     | 
    
         
            -
                   
     | 
| 
      
 96 
     | 
    
         
            +
                selector = selector.replace /(\$[A-z0-9\.\$]+)/g, (path) =>
         
     | 
| 
      
 97 
     | 
    
         
            +
                  path    = path.split('.')
         
     | 
| 
      
 98 
     | 
    
         
            +
                  keyword = path.pop()
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                  target = @
         
     | 
| 
      
 101 
     | 
    
         
            +
                  target = target?[part] for part in path
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  target?[keyword]?.selector
         
     | 
| 
       91 
104 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
                selector
         
     | 
| 
      
 105 
     | 
    
         
            +
                selector.trim()
         
     | 
| 
       93 
106 
     | 
    
         | 
| 
       94 
107 
     | 
    
         
             
              #
         
     | 
| 
       95 
108 
     | 
    
         
             
              # Bings events defined in 'events' to container
         
     | 
| 
         @@ -101,7 +114,7 @@ Joosy.Modules.Container = 
     | 
|
| 
       101 
114 
     | 
    
         
             
              #     'click $foo': -> #this will search for selector of foo element
         
     | 
| 
       102 
115 
     | 
    
         
             
              #
         
     | 
| 
       103 
116 
     | 
    
         
             
              __delegateEvents: ->
         
     | 
| 
       104 
     | 
    
         
            -
                module =  
     | 
| 
      
 117 
     | 
    
         
            +
                module = @
         
     | 
| 
       105 
118 
     | 
    
         
             
                events = @__collectEvents()
         
     | 
| 
       106 
119 
     | 
    
         | 
| 
       107 
120 
     | 
    
         
             
                events.each (key, method) =>
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: joosy
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.2.0.alpha. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.2.0.alpha.18
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Boris Staal
         
     | 
| 
         @@ -11,7 +11,7 @@ authors: 
     | 
|
| 
       11 
11 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       13 
13 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       14 
     | 
    
         
            -
            date: 2013-06- 
     | 
| 
      
 14 
     | 
    
         
            +
            date: 2013-06-30 00:00:00.000000000 Z
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies:
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       17 
17 
     | 
    
         
             
              name: sprockets
         
     |