emerson 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Emerson
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,4 +1,4 @@
1
- // Emerson.js 0.0.4
1
+ // Emerson.js 0.0.5
2
2
  //
3
3
  // (c) 2012 Corey Innis
4
4
  // Emerson may be freely distributed under the MIT license.
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // Defines the Emerson namespace (global).
4
4
 
5
- (function(){
5
+ (function() {
6
6
 
7
7
  // Initial Setup
8
8
  // --------------------------------------------------------------------------
@@ -21,7 +21,7 @@
21
21
  }
22
22
 
23
23
  // Current version of the library. Keep in sync with `package.json`.
24
- Emerson.VERSION = '0.0.4';
24
+ Emerson.VERSION = '0.0.5';
25
25
 
26
26
  // Reference the base lib (one of jQuery, Zepto or Ender) as $.
27
27
  var $ = Emerson.base = (root.jQuery || root.Zepto || root.ender);
@@ -36,6 +36,7 @@
36
36
  // * Given an object the current configuration will be extended with that.
37
37
  // * Given a "dot-notated" string a lookup will be performed.
38
38
  // * With no argument a copy of the current configuration will be returned.
39
+ // * Given a single argument as `true`, defaults will be restored.
39
40
  //
40
41
  Emerson.config = function config() {
41
42
  var arg = arguments[0];
@@ -45,6 +46,10 @@
45
46
  return _.clone(configuration);
46
47
  }
47
48
 
49
+ if(arg === true) {
50
+ configuration = defaults();
51
+ }
52
+
48
53
  if(typeof arg === 'string') {
49
54
  result = configuration;
50
55
 
@@ -57,10 +62,10 @@
57
62
  return undefined;
58
63
  }
59
64
 
60
- return _.clone(result);
65
+ return result;
61
66
  }
62
67
  else {
63
- _.extend(configuration, arg);
68
+ _.deepExtend(configuration, arg);
64
69
  }
65
70
  };
66
71
 
@@ -82,9 +87,72 @@
82
87
  };
83
88
 
84
89
 
90
+ // Underscore Extension
91
+ // --------------------------------------------------------------------------
92
+
93
+ // ### deepExtend
94
+ //
95
+ // * Author: Kurt Milam - http://xioup.com
96
+ // * https://gist.github.com/1868955
97
+ _.deepExtend = function(obj) {
98
+ var parentRE = /#{\s*?_\s*?}/,
99
+ slice = Array.prototype.slice,
100
+ hasOwnProperty = Object.prototype.hasOwnProperty;
101
+
102
+ _.each(slice.call(arguments, 1), function(source) {
103
+ for (var prop in source) {
104
+ if (hasOwnProperty.call(source, prop)) {
105
+ if (_.isUndefined(obj[prop])) {
106
+ obj[prop] = source[prop];
107
+ }
108
+ else if (_.isString(source[prop]) && parentRE.test(source[prop])) {
109
+ if (_.isString(obj[prop])) {
110
+ obj[prop] = source[prop].replace(parentRE, obj[prop]);
111
+ }
112
+ }
113
+ else if (_.isArray(obj[prop]) || _.isArray(source[prop])){
114
+ if (!_.isArray(obj[prop]) || !_.isArray(source[prop])){
115
+ throw 'Error: Trying to combine an array with a non-array (' + prop + ')';
116
+ } else {
117
+ obj[prop] = _.reject(_.deepExtend(obj[prop], source[prop]), function (item) { return _.isNull(item);});
118
+ }
119
+ }
120
+ else if (_.isObject(obj[prop]) || _.isObject(source[prop])){
121
+ if (!_.isObject(obj[prop]) || !_.isObject(source[prop])){
122
+ throw 'Error: Trying to combine an object with a non-object (' + prop + ')';
123
+ } else {
124
+ obj[prop] = _.deepExtend(obj[prop], source[prop]);
125
+ }
126
+ } else {
127
+ obj[prop] = source[prop];
128
+ }
129
+ }
130
+ }
131
+ });
132
+ return obj;
133
+ };
134
+
135
+
85
136
  // Internal Implementation
86
137
  // --------------------------------------------------------------------------
87
138
 
139
+ // ### defaults
140
+ // Default configuration.
141
+ // var defaults = {
142
+ // attrs : {
143
+ // view : 'view',
144
+ // traits : 'traits'
145
+ // }
146
+ // };
147
+ function defaults() {
148
+ return {
149
+ attrs : {
150
+ view : 'view',
151
+ traits : 'traits'
152
+ }
153
+ };
154
+ }
155
+
88
156
  // ### configuration
89
157
  // Stores library config, with defaults.
90
158
  //
@@ -101,10 +169,5 @@
101
169
  // }
102
170
  // });
103
171
  // Emerson.init();
104
- var configuration = {
105
- attrs : {
106
- view : 'view',
107
- traits : 'traits'
108
- }
109
- };
172
+ var configuration = _.deepExtend({}, defaults());
110
173
  }).call(this);
@@ -69,9 +69,9 @@
69
69
  // ### sink
70
70
  //
71
71
  // json: <response [action, data, path, view]>
72
- // html: <response> (string)
73
- // head: <response> single space string
72
+ // html: <response> (string) ... TODO
73
+ // head: <response> single space string ... TODO
74
74
  function sink(response, status) {
75
- $(response.view).view().sink();
75
+ $(response.view).sink();
76
76
  }
77
77
  })(Emerson);
@@ -29,17 +29,43 @@
29
29
  //
30
30
  // $(target).sink()
31
31
  //
32
+ // Given "replacement" content and for each "sink" (existing content):
33
+ //
34
+ // 1. fire "sink:before" with the sink as the target.
35
+ // 2. replace the sink with a "prepared" replacement.
36
+ // 3. fire "sink:after" with the replacement as the target.
32
37
  $.fn.sink = function() {
33
38
  _.each(this, function(e) {
34
39
  var elem = $(e);
35
40
  var key = elem.data('sink');
36
41
 
37
42
  if(key) {
38
- elem.replaceAll('[data-sink="' + key + '"]', 'body');
39
- elem.trigger('sink:after');
43
+ $('[data-sink="' + key + '"]').each(function() {
44
+ $(this)
45
+ .trigger('sink:before')
46
+ .replaceWith(prepare(elem));
47
+ });
48
+
49
+ $('[data-sink="' + key + '"]').trigger('sink:after');
40
50
  }
41
51
  });
42
52
 
43
53
  return this;
44
54
  };
55
+
56
+
57
+ // Internal Implementation
58
+ // --------------------------------------------------------------------------
59
+
60
+ // ### prepare
61
+ // Clone the replacement source and, if Emerson.view is defined, apply that.
62
+ function prepare(source) {
63
+ var result = source.clone();
64
+
65
+ if(Emerson.view) {
66
+ result.view();
67
+ }
68
+
69
+ return result;
70
+ }
45
71
  })(Emerson);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emerson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-12 00:00:00.000000000 Z
12
+ date: 2012-05-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: transcendent views
15
15
  email: