emerson 0.0.1

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.
data/.gemset.template ADDED
@@ -0,0 +1 @@
1
+ RVM_GEMSET="ruby-1.9.3@emerson"
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .gemset
20
+ .rspec
21
+ .rvmrc
22
+ .import/
data/.rspec.template ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc.template ADDED
@@ -0,0 +1,11 @@
1
+ source .gemset
2
+ export USE_BUNDLER=force
3
+
4
+ rvm use --create --install $RVM_GEMSET
5
+
6
+ if [[ -s "./bootstrap.gems" ]]; then
7
+ if ! rvm gemset import bootstrap.gems > /dev/null 2>&1; then
8
+ echo "ERROR: Unable to bootstrap the gems" >&2
9
+ fi
10
+ fi
11
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in emerson.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Corey Innis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Emerson
2
+
3
+ transcendent views. (WIP)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'emerson'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install emerson
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bootstrap.gems ADDED
@@ -0,0 +1 @@
1
+ bundler -v 1.1.3
data/emerson.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/emerson/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Corey Innis"]
6
+ gem.email = ["corey@coolerator.net"]
7
+ gem.description = %q{transcendent views}
8
+ gem.summary = %q{emerson believes in the inherent good in...}
9
+ gem.homepage = "https://github.com/coreyti/emerson"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "emerson"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Emerson::VERSION
17
+ end
data/lib/emerson.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "emerson/version"
2
+ require "emerson/rails"
3
+
4
+ module Emerson
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails'
2
+
3
+ module Emerson
4
+ module Rails
5
+ autoload :Engine, 'emerson/rails'
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Emerson
2
+ module Rails
3
+ class Engine < ::Rails::Engine ; end
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Emerson
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ // Emerson.js 0.0.1
2
+ //
3
+ // (c) 2012 Corey Innis
4
+ // Emerson may be freely distributed under the MIT license.
5
+ // For all details and documentation:
6
+ // http://coolerator.net
7
+
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
13
+ // @private
@@ -0,0 +1,33 @@
1
+ (function(){
2
+
3
+ // Initial Setup
4
+ // --------------------------------------------------------------------------
5
+
6
+ // Save a reference to the global object...
7
+ // `window` in the browser, `global` on the server.
8
+ var root = this;
9
+
10
+ // The top-level namespace. All public Emerson classes and modules will
11
+ // be attached to this. Exported for both CommonJS and the browser.
12
+ var Emerson;
13
+ if (typeof exports !== 'undefined') {
14
+ Emerson = exports;
15
+ } else {
16
+ Emerson = root.Emerson = {};
17
+ }
18
+
19
+ // Current version of the library. Keep in sync with `package.json`.
20
+ Emerson.VERSION = '0.0.1';
21
+
22
+ // Reference the base lib (one of jQuery, Zepto or Ender) as $.
23
+ var $ = Emerson.base = (root.jQuery || root.Zepto || root.ender);
24
+
25
+
26
+ // Primary API
27
+ // --------------------------------------------------------------------------
28
+ Emerson.init = function init() {
29
+ _.each(['sink', 'util', 'view'], function(mod) {
30
+ Emerson[mod] && Emerson[mod].init();
31
+ });
32
+ };
33
+ }).call(this);
@@ -0,0 +1,77 @@
1
+ // Emerson HTTP
2
+ //
3
+ // Adds...
4
+
5
+ (function(ns) {
6
+
7
+ // Emerson Extension
8
+ // --------------------------------------------------------------------------
9
+
10
+ // ### Emerson.http module
11
+ // ...
12
+ //
13
+ // **Important Note:**
14
+ // > For now, `Emerson.http` depends on the Rails `jquery_ujs` extension.
15
+ var define = ns.http = function() {};
16
+
17
+ // ### Module API
18
+ // * `ns` is a reference to the namespace.
19
+ // * `init` is a hook for initializing the module.
20
+ _.extend(define, {
21
+ ns : ns,
22
+ init : function init() {
23
+ if($.rails === undefined) {
24
+ throw("$.rails must be defined");
25
+ }
26
+
27
+ return (ns.sink) ? enable() : disable();
28
+ }
29
+ });
30
+
31
+
32
+ // "Base" Libary Extension
33
+ // --------------------------------------------------------------------------
34
+
35
+ // Make a local copy of Emerson.base. e.g., one of jQuery, Zepto or Ender.
36
+ var $ = ns.base;
37
+
38
+
39
+ // Event Handling
40
+ // --------------------------------------------------------------------------
41
+
42
+
43
+ // ### enable
44
+ // Attach event global listeners.
45
+ function enable() {
46
+ $(document)
47
+ .on('ajax:error', handleError)
48
+ .on('ajax:success', handleSuccess);
49
+ }
50
+
51
+ // ### enable
52
+ // Detach event global listeners.
53
+ function disable() {
54
+ $(document)
55
+ .off('ajax:error', handleError)
56
+ .off('ajax:success', handleSuccess);
57
+ }
58
+
59
+ // ### handleError
60
+ function handleError(e, xhr, status, error) {
61
+ sink(JSON.parse(xhr.responseText), status);
62
+ }
63
+
64
+ // ### handleSuccess
65
+ function handleSuccess(e, response, status, xhr) {
66
+ sink(response, status);
67
+ }
68
+
69
+ // ### sink
70
+ //
71
+ // json: <response [action, data, path, view]>
72
+ // html: <response> (string)
73
+ // head: <response> single space string
74
+ function sink(response, status) {
75
+ $(response.view).view().sink();
76
+ }
77
+ })(Emerson);
@@ -0,0 +1,93 @@
1
+ // Emerson Sink
2
+ //
3
+ // Adds...
4
+
5
+ (function(ns) {
6
+
7
+ // Emerson Extension
8
+ // --------------------------------------------------------------------------
9
+
10
+ // ### Emerson.sink module
11
+ var define = ns.sink = function(view) {};
12
+
13
+ // ### Module API
14
+ // * `ns` is a reference to the namespace.
15
+ // * `init` is a hook for initializing the module.
16
+ _.extend(define, {
17
+ ns : ns,
18
+ init : function init() {
19
+ _before.list = [];
20
+ _after.list = [];
21
+ },
22
+ before : function before(callback) {
23
+ if(callback) {
24
+ _before(callback);
25
+ }
26
+ },
27
+ after : function after(callback) {
28
+ if(callback) {
29
+ _after(callback);
30
+ }
31
+ }
32
+ });
33
+
34
+
35
+ // "Base" Libary Extension
36
+ // --------------------------------------------------------------------------
37
+
38
+ // Make a local copy of Emerson.base. e.g., one of jQuery, Zepto or Ender.
39
+ var $ = ns.base;
40
+
41
+ // ### $.fn.sink
42
+ //
43
+ // $(target).sink()
44
+ //
45
+ $.fn.sink = function() {
46
+ _.each(this, function(e) {
47
+ var elem = $(e);
48
+ var key = elem.data('sink');
49
+
50
+ if(key) {
51
+ _before.apply(elem);
52
+ elem.replaceAll('[data-sink="' + key + '"]', 'body');
53
+ _after.apply(elem);
54
+ }
55
+ });
56
+
57
+ return this;
58
+ };
59
+
60
+
61
+ // Internal Implementation
62
+ // --------------------------------------------------------------------------
63
+
64
+ // ### 'before' callbacks
65
+ var _before = function(callback) {
66
+ var view;
67
+ if(callback) {
68
+ _before.list.push(callback);
69
+ }
70
+ else {
71
+ view = this;
72
+ _.each(_before.list, function(fn) {
73
+ fn(view);
74
+ });
75
+ }
76
+ };
77
+ _.extend(_before, { list : [] });
78
+
79
+ // ### 'after' callbacks
80
+ var _after = function(callback) {
81
+ var view;
82
+ if(callback) {
83
+ _after.list.push(callback);
84
+ }
85
+ else {
86
+ view = this;
87
+ _.each(_after.list, function(fn) {
88
+ fn(view);
89
+ });
90
+ }
91
+ };
92
+ _.extend(_after, { list : [] });
93
+ })(Emerson);
@@ -0,0 +1,26 @@
1
+ // Emerson Util
2
+ //
3
+ // ...
4
+
5
+ (function(ns){
6
+
7
+ // Emerson Extension
8
+ // --------------------------------------------------------------------------
9
+
10
+ // util
11
+ var util = ns.util = {
12
+ // A reference to the namespace.
13
+ 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
+ }
25
+ };
26
+ })(Emerson);
@@ -0,0 +1,285 @@
1
+ // Emerson View
2
+ //
3
+ // A view...
4
+
5
+ (function(ns) {
6
+
7
+ // Emerson Extension
8
+ // --------------------------------------------------------------------------
9
+
10
+ // ### Emerson.view module
11
+ // Entry point for defining a new View.
12
+ var define = ns.view = function(name, setup) {
13
+ return (library[name] = construct(name, setup || {}));
14
+ };
15
+
16
+ // ### Module API
17
+ // * `ns` is a reference to the namespace.
18
+ // * `init` is a hook for initializing the module.
19
+ _.extend(define, {
20
+ ns : ns,
21
+ init : function init() {
22
+ $('body').view();
23
+ }
24
+ });
25
+
26
+
27
+ // "Base" Libary Extension
28
+ // --------------------------------------------------------------------------
29
+
30
+ // Make a local copy of Emerson.base. e.g., one of jQuery, Zepto or Ender.
31
+ var $ = ns.base;
32
+
33
+ // ### $.view
34
+ //
35
+ // $.view(key);
36
+ //
37
+ // Accessor for defined Views.
38
+ //
39
+ // Note that, while it is possible to manually execute View methods on an
40
+ // object like so:
41
+ //
42
+ // $.view(key).fn.method.apply(object, arguments);
43
+ //
44
+ // such usage is not recommended as it:
45
+ //
46
+ // 1. circumvents the intentional transience provided by the framework.
47
+ // 2. is likely to cause issues in that the called method will be working
48
+ // with a non-initialized/-decorated object which may not have the
49
+ // expected API.
50
+ //
51
+ $.view = function(key) {
52
+ return library[key];
53
+ };
54
+
55
+ // ### $.fn.view
56
+ //
57
+ // $(target).view()
58
+ //
59
+ // Initializes a transiently-decorated object. In the call to #initialized,
60
+ // and any additional methods called from there, `this` will be wrapped with
61
+ // the View definition. The returned object is stock: no longer decorated.
62
+ //
63
+ // This method will apply, both, "view" and "trait" behaviors. Additionally,
64
+ // it works on the surrounding DOM match, as well as nested matches.
65
+ $.fn.view = function() {
66
+ _.each(this, function(e) {
67
+ var keys = [];
68
+ 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]');
71
+
72
+ _.each(as_view, function(html) {
73
+ var element = $(html);
74
+ attach.apply(element, [element.data('view')]);
75
+ });
76
+
77
+ _.each(as_trait, function(html) {
78
+ var element = $(html);
79
+ attach.apply(element, _.map(element.data('traits').split(/\s+/), function(key) {
80
+ return [':', key].join('');
81
+ }));
82
+ });
83
+ });
84
+
85
+ return this;
86
+ };
87
+
88
+
89
+ // Internal Objects
90
+ // --------------------------------------------------------------------------
91
+
92
+ // ### View constructor.
93
+ //
94
+ // View instances are "subclasses" of the base lib object, decorated with our
95
+ // View.prototype and the provided definition.
96
+ function View() {}
97
+
98
+ // View instance setup definition.
99
+ _.extend(View, {
100
+ setup : {
101
+ initialize : function() {},
102
+ subscribe : {}
103
+ }
104
+ });
105
+
106
+ // View instance prototype definition.
107
+ _.extend(View.prototype, {});
108
+
109
+
110
+ // Internal Implementation
111
+ // --------------------------------------------------------------------------
112
+
113
+ // Storage place for the defined Views.
114
+ // @private
115
+ var library = {};
116
+
117
+ // Storage place for attachments made.
118
+ // @private
119
+ var attachments = {};
120
+
121
+ // emerson id, for tracking attachments.
122
+ // @private
123
+ var _eid = 0;
124
+
125
+ // ### eid
126
+ // Retrieves a unique and persistent ID for the given DOM element.
127
+ // @private
128
+ function eid(element) {
129
+ return element._emerson || (element._emerson = (_eid += 1));
130
+ }
131
+
132
+ // ### construct
133
+ // Construct a definition made up of:
134
+ //
135
+ // 1. The provided setup block.
136
+ // 2. A "subclass", extended with the View prototype.
137
+ function construct(name, setup) {
138
+ var sub = _.extend($sub(), {
139
+ constructor : View,
140
+ setup : _.extend({}, View.setup, setup)
141
+ });
142
+
143
+ _.extend(sub.fn, View.prototype);
144
+
145
+ return sub;
146
+ }
147
+
148
+ // ### attach
149
+ // Given a (complex) list of keys, search the library for applicable View and
150
+ // Trait definitions to apply to the object.
151
+ //
152
+ // Keeps track of which definitions have been applied, and does not re-apply.
153
+ //
154
+ // NOTE: `this`, in this call, should be a baselib-extended object containing
155
+ // a single element. e.g.,
156
+ //
157
+ // _.each($(selector), function(element) {
158
+ // attach.apply($(element), [key, [subkey]]);
159
+ // });
160
+ function attach() {
161
+ var self = this, def;
162
+ var id = eid(this[0]);
163
+
164
+ _.each(_.flatten(arguments), function(key) {
165
+ var set = (attachments[key] || (attachments[key] = []));
166
+ var built, init, events;
167
+
168
+ if(_.include(set, id)) {
169
+ return; // do not re-apply.
170
+ }
171
+
172
+ // Build an instance, attach event handlers, initialize and record.
173
+ if(def = library[key]) {
174
+ built = def(self, self.context);
175
+ init = def.setup.initialize;
176
+ events = def.setup.subscribe;
177
+
178
+ _.each(events, function(handler, key) {
179
+ bind(built, key, handler);
180
+ });
181
+
182
+ init.call(built);
183
+ set.push(id);
184
+ }
185
+ });
186
+
187
+ return this;
188
+ }
189
+
190
+ // ### bind
191
+ // Attach event handler(s).
192
+ //
193
+ // Emerson.view(key, {
194
+ // subscribe : {
195
+ // 'click' : handler, // simple
196
+ // 'click focus' : handler, // multiple event types
197
+ // 'selector' : { // specific child target
198
+ // 'click' : handler,
199
+ // 'focus' : handler
200
+ // },
201
+ // document : { // bind document, for events
202
+ // 'click' : handler // fired outside of the view
203
+ // }
204
+ // }
205
+ // });
206
+ //
207
+ // Note that, in the document-binding case, an event like `click` would be a
208
+ // bad idea. A more useful (and less costly) use case would be a form of
209
+ // pub/sub.
210
+ //
211
+ // For example, view "A" could trigger an event indicating that it has
212
+ // rendered a new instance, to which "B" (elsewhere) would listen in order
213
+ // to update, say, a count of instances of "A".
214
+ function bind(instance, key, handler, selector) {
215
+ if($.isPlainObject(handler)) {
216
+ _.each(handler, function(subhandler, subkey) {
217
+ bind(instance, subkey, subhandler, key);
218
+ });
219
+ }
220
+ else {
221
+ if(selector === 'document') {
222
+ $(document).on(key, function() {
223
+ return handler.apply(instance, arguments);
224
+ });
225
+ }
226
+ else {
227
+ instance.on(key, selector, function() {
228
+ return handler.apply(instance, arguments);
229
+ });
230
+ }
231
+ }
232
+ }
233
+
234
+ // ### $sub
235
+ // Basically a copy of jQuery.sub, but more generic and with changes to:
236
+ //
237
+ // 1. `Sub.extend`
238
+ // to ensure proper object context is maintained.
239
+ // 2. `Sub.fn.extend`
240
+ // to ensure proper object context is maintained.
241
+ function $sub() {
242
+ var root;
243
+
244
+ function Sub(selector, context) {
245
+ return new Sub.fn.init(selector, context);
246
+ }
247
+
248
+ _.extend(true, Sub, $);
249
+
250
+ Sub.fn = Sub.prototype = $();
251
+ Sub.fn.init = function init(selector, context) {
252
+ return $.fn.init.call(this, selector, context, root);
253
+ };
254
+
255
+ Sub.fn.constructor = Sub;
256
+ Sub.fn.init.prototype = Sub.fn;
257
+
258
+ Sub.fn.extend = function extend() {
259
+ this.constructor.extend.apply(this.constructor, arguments);
260
+ return this;
261
+ };
262
+
263
+ Sub.extend = function extend() {
264
+ var self = this;
265
+ var keep = {
266
+ constructor : this.fn.constructor,
267
+ init : this.fn.init
268
+ };
269
+
270
+ _.each(arguments, function(arg) {
271
+ if(arg.fn) {
272
+ $.extend(self.fn, arg.fn, keep);
273
+ }
274
+ else {
275
+ $.extend(self.fn, arg, keep);
276
+ }
277
+ });
278
+
279
+ return self;
280
+ };
281
+
282
+ root = Sub(document);
283
+ return Sub;
284
+ }
285
+ })(Emerson);
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emerson
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Corey Innis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: transcendent views
15
+ email:
16
+ - corey@coolerator.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gemset.template
22
+ - .gitignore
23
+ - .rspec.template
24
+ - .rvmrc.template
25
+ - Gemfile
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - bootstrap.gems
30
+ - emerson.gemspec
31
+ - lib/emerson.rb
32
+ - lib/emerson/rails.rb
33
+ - lib/emerson/rails/engine.rb
34
+ - lib/emerson/version.rb
35
+ - vendor/assets/javascripts/emerson.js
36
+ - vendor/assets/javascripts/emerson/base.js
37
+ - vendor/assets/javascripts/emerson/http.js
38
+ - vendor/assets/javascripts/emerson/sink.js
39
+ - vendor/assets/javascripts/emerson/util.js
40
+ - vendor/assets/javascripts/emerson/view.js
41
+ homepage: https://github.com/coreyti/emerson
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.11
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: emerson believes in the inherent good in...
65
+ test_files: []