emerson 0.0.2 → 0.0.3

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.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,14 +1,12 @@
1
- // Emerson.js 0.0.1
1
+ // Emerson.js 0.0.3
2
2
  //
3
3
  // (c) 2012 Corey Innis
4
4
  // Emerson may be freely distributed under the MIT license.
5
5
  // For all details and documentation:
6
6
  // http://coolerator.net
7
7
 
8
- //= require underscore
9
- //= require emerson/base
10
- //= require emerson/util
11
- //= require emerson/http
12
- //= require emerson/sink
13
- //= require emerson/view
14
- // @private
8
+ // = require emerson/base.js
9
+ // = require emerson/util.js
10
+ // = require emerson/http.js
11
+ // = require emerson/sink.js
12
+ // = require emerson/view.js
@@ -1,3 +1,7 @@
1
+ // Emerson Base
2
+ //
3
+ // Defines the Emerson namespace (global).
4
+
1
5
  (function(){
2
6
 
3
7
  // Initial Setup
@@ -17,7 +21,7 @@
17
21
  }
18
22
 
19
23
  // Current version of the library. Keep in sync with `package.json`.
20
- Emerson.VERSION = '0.0.1';
24
+ Emerson.VERSION = '0.0.3';
21
25
 
22
26
  // Reference the base lib (one of jQuery, Zepto or Ender) as $.
23
27
  var $ = Emerson.base = (root.jQuery || root.Zepto || root.ender);
@@ -25,9 +29,82 @@
25
29
 
26
30
  // Primary API
27
31
  // --------------------------------------------------------------------------
32
+
33
+ // ### .config
34
+ // Configures the library.
35
+ //
36
+ // * Given an object the current configuration will be extended with that.
37
+ // * Given a "dot-notated" string a lookup will be performed.
38
+ // * With no argument a copy of the current configuration will be returned.
39
+ //
40
+ Emerson.config = function config() {
41
+ var arg = arguments[0];
42
+ var result;
43
+
44
+ if(arg === undefined) {
45
+ return _.clone(configuration);
46
+ }
47
+
48
+ if(typeof arg === 'string') {
49
+ result = configuration;
50
+
51
+ try {
52
+ _.each(arg.split('.'), function(part) {
53
+ result = result[part];
54
+ });
55
+ }
56
+ catch(e) {
57
+ return undefined;
58
+ }
59
+
60
+ return _.clone(result);
61
+ }
62
+ else {
63
+ _.extend(configuration, arg);
64
+ }
65
+ };
66
+
67
+ // ### .init
68
+ // Initializes the desired Emerson modules.
69
+ //
70
+ // By default, will run `.init` for all modules. If passed specific module
71
+ // names, it will only initialize those.
28
72
  Emerson.init = function init() {
29
- _.each(['sink', 'util', 'view'], function(mod) {
73
+ var modules = ['http', 'sink', 'util', 'view'];
74
+
75
+ if(arguments.length) {
76
+ modules = arguments;
77
+ }
78
+
79
+ _.each(modules, function(mod) {
30
80
  Emerson[mod] && Emerson[mod].init();
31
81
  });
32
82
  };
83
+
84
+
85
+ // Internal Implementation
86
+ // --------------------------------------------------------------------------
87
+
88
+ // ### configuration
89
+ // Stores library config, with defaults.
90
+ //
91
+ // * `attrs` are mapped to `[data-attr]` for view/trait selectors.
92
+ //
93
+ // Previous (unpublished) versions of this library used `data-presents` to
94
+ // represent a view and `data-behavior` to represent traits. This is still
95
+ // supported by way of:
96
+ //
97
+ // Emerson.config({
98
+ // attrs : {
99
+ // view : 'presents',
100
+ // traits : 'behavior'
101
+ // }
102
+ // });
103
+ // Emerson.init();
104
+ var configuration = {
105
+ attrs : {
106
+ view : 'view',
107
+ traits : 'traits'
108
+ }
109
+ };
33
110
  }).call(this);
@@ -7,20 +7,11 @@
7
7
  // Emerson Extension
8
8
  // --------------------------------------------------------------------------
9
9
 
10
- // util
10
+ // ### Emerson.util module
11
+ // * `ns` is a reference to the namespace.
12
+ // * `init` is a hook for initializing the module.
11
13
  var util = ns.util = {
12
- // A reference to the namespace.
13
14
  ns : ns,
14
- init : function init() {},
15
-
16
- // ...
17
- augment : function augment(object, name, fn) {
18
- var original = object[name];
19
-
20
- object[name] = function() {
21
- var result = (original && original.apply(this, arguments)) || this;
22
- return fn.apply(result, arguments); // closure issue?
23
- }
24
- }
15
+ init : function init() {}
25
16
  };
26
17
  })(Emerson);
@@ -19,6 +19,7 @@
19
19
  _.extend(define, {
20
20
  ns : ns,
21
21
  init : function init() {
22
+ configure();
22
23
  $('body').view();
23
24
  }
24
25
  });
@@ -66,17 +67,17 @@
66
67
  _.each(this, function(e) {
67
68
  var keys = [];
68
69
  var element = $(e);
69
- var as_view = element.add(element.find('[data-view]')).filter('[data-view]');
70
- var as_trait = element.add(element.find('[data-traits]')).filter('[data-traits]');
70
+ var as_view = element.add(element.find(selectors.view)).filter(selectors.view);
71
+ var as_trait = element.add(element.find(selectors.traits)).filter(selectors.traits);
71
72
 
72
73
  _.each(as_view, function(html) {
73
74
  var element = $(html);
74
- attach.apply(element, [element.data('view')]);
75
+ attach.apply(element, [element.data(attrs.view)]);
75
76
  });
76
77
 
77
78
  _.each(as_trait, function(html) {
78
79
  var element = $(html);
79
- attach.apply(element, _.map(element.data('traits').split(/\s+/), function(key) {
80
+ attach.apply(element, _.map(element.data(attrs.traits).split(/\s+/), function(key) {
80
81
  return [':', key].join('');
81
82
  }));
82
83
  });
@@ -110,6 +111,14 @@
110
111
  // Internal Implementation
111
112
  // --------------------------------------------------------------------------
112
113
 
114
+ // Attr definitions.
115
+ // @private
116
+ var attrs = {};
117
+
118
+ // Selector definitions.
119
+ // @private
120
+ var selectors = {};
121
+
113
122
  // Storage place for the defined Views.
114
123
  // @private
115
124
  var library = {};
@@ -122,6 +131,17 @@
122
131
  // @private
123
132
  var _eid = 0;
124
133
 
134
+ // configure
135
+ // @private
136
+ function configure() {
137
+ var config = ns.config('attrs');
138
+
139
+ _.extend(attrs, config);
140
+ _.each(config, function(value, key) {
141
+ selectors[key] = '[data-' + value + ']';
142
+ });
143
+ }
144
+
125
145
  // ### eid
126
146
  // Retrieves a unique and persistent ID for the given DOM element.
127
147
  // @private
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: