modulejs-rails 1.5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e0e5bb749994c8a1d21de5e0f1d5d98c6671dfd
4
+ data.tar.gz: d71d082bc7962ee6f17b794a1ce4956361cf2819
5
+ SHA512:
6
+ metadata.gz: bc1d431f32b6261cfbc37ba79807e046504397fcf8a0765a2b2eec0998f93059daf9a2d506092d4d0f696063950d630bb19634a88a6401d2942d042e7a91a186
7
+ data.tar.gz: 60011a834c36d08f720b8a26e9280c95767811bdd4c45cefae67a0aeb2d321063af1ff4816827caeb0541f6db8a0290561e7ecc33e0a516ae41511fe6a771cff
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in modulejs-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ales Vilchytski
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.
@@ -0,0 +1,41 @@
1
+ # modulejs for Ruby on Rails 4 Assets Pipeline
2
+
3
+ Lightweight JavaScript module system (http://larsjung.de/modulejs/).
4
+ Inspired by article: https://www.reinteractive.net/posts/172-a-better-way-to-modularise-your-js-in-rails
5
+
6
+ When you want to use modules in JavaScript you should solve next problems:
7
+
8
+ 1. Load scripts with dependencies, usually in big concatenated JavaScript file
9
+ 2. Execute scripts and dependencies in proper order
10
+
11
+ Rails solves problem 1 by Assets Pipeline, modulejs solves problem 2.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'modulejs-rails'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle install
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install modulejs-rails
28
+
29
+ ## Usage
30
+
31
+ Require in Assets Pipeline manifest
32
+
33
+ //= require 'modulejs'
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/ales-vilchytski/modulejs-rails/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ require "modulejs/rails"
2
+
3
+ module Modulejs
4
+ module Rails
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'modulejs/rails/engine'
2
+ require 'modulejs/rails/version'
3
+
4
+ module Modulejs
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Modulejs
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Modulejs
2
+ module Rails
3
+ VERSION = "1.5.0.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ require 'lib/modulejs/rails/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "modulejs-rails"
6
+ spec.version = Modulejs::Rails::VERSION
7
+ spec.authors = ["Ales Vilchytski"]
8
+ spec.email = ["vilchytski.ales@yandex.by"]
9
+ spec.summary = %q{Lightweight JavaScript module system for Ruby on Rails 4}
10
+ spec.description = %q{JS module system for Ruby on Rails 4 Assets Pipeline that solves scripts order issues}
11
+ spec.homepage = "https://github.com/ales-vilchytski/modulejs-rails"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_dependency 'railties', '>= 4.0'
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.7"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ end
@@ -0,0 +1,41 @@
1
+ # modulejs
2
+
3
+ [![license][license-img]][github] [![web][web-img]][web] [![github][github-img]][github] [![bower][bower-img]][github]
4
+ [![build status][travis-img]][travis]
5
+
6
+ Lightweight JavaScript module system.
7
+
8
+
9
+ ## License
10
+ The MIT License (MIT)
11
+
12
+ Copyright (c) 2014 Lars Jung (http://larsjung.de)
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in
22
+ all copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
+ THE SOFTWARE.
31
+
32
+
33
+ [web]: http://larsjung.de/modulejs/
34
+ [github]: https://github.com/lrsjng/modulejs
35
+ [travis]: https://travis-ci.org/lrsjng/modulejs
36
+
37
+ [license-img]: http://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square
38
+ [web-img]: http://img.shields.io/badge/web-larsjung.de/modulejs-a0a060.svg?style=flat-square
39
+ [github-img]: http://img.shields.io/badge/github-lrsjng/modulejs-a0a060.svg?style=flat-square
40
+ [bower-img]: http://img.shields.io/badge/bower-lrsjng/modulejs-a0a060.svg?style=flat-square
41
+ [travis-img]: http://img.shields.io/travis/lrsjng/modulejs.svg?style=flat-square
@@ -0,0 +1,283 @@
1
+ /* modulejs 1.5.0 - http://larsjung.de/modulejs/ */
2
+ (function (factory) {
3
+
4
+ this.modulejs = factory();
5
+
6
+ }(function () {
7
+ 'use strict';
8
+
9
+ // # Util
10
+
11
+ // References.
12
+ var objectPrototype = Object.prototype;
13
+ var arrayForEach = Array.prototype.forEach;
14
+
15
+ // Returns a function that returns `true` if `arg` is of the correct `type`, otherwise `false`.
16
+ function createIsTypeFn(type) {
17
+
18
+ return function (arg) {
19
+
20
+ return objectPrototype.toString.call(arg) === '[object ' + type + ']';
21
+ };
22
+ }
23
+
24
+ // ## isString
25
+ // Returns `true` if argument is a string, otherwise `false`.
26
+ var isString = createIsTypeFn('String');
27
+
28
+ // ## isFunction
29
+ // Returns `true` if argument is a function, otherwise `false`.
30
+ var isFunction = createIsTypeFn('Function');
31
+
32
+ // ## isArray
33
+ // Returns `true` if argument is an array, otherwise `false`.
34
+ var isArray = Array.isArray || createIsTypeFn('Array');
35
+
36
+ // ## isObject
37
+ // Returns `true` if argument is an object, otherwise `false`.
38
+ function isObject(arg) {
39
+
40
+ return arg === new Object(arg);
41
+ }
42
+
43
+ // ## has
44
+ // Short cut for `hasOwnProperty`.
45
+ function has(arg, id) {
46
+
47
+ return objectPrototype.hasOwnProperty.call(arg, id);
48
+ }
49
+
50
+ // ## each
51
+ // Iterates over all elements af an array or all own keys of an object.
52
+ function each(obj, iterator, context) {
53
+
54
+ if (arrayForEach && obj.forEach === arrayForEach) {
55
+ obj.forEach(iterator, context);
56
+ } else if (obj.length === +obj.length) {
57
+ for (var i = 0, l = obj.length; i < l; i += 1) {
58
+ iterator.call(context, obj[i], i, obj);
59
+ }
60
+ } else {
61
+ for (var key in obj) {
62
+ if (has(obj, key)) {
63
+ iterator.call(context, obj[key], key, obj);
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ // ## contains
70
+ // Returns `true` if array contains element, otherwise `false`.
71
+ function contains(array, element) {
72
+
73
+ for (var i = 0, l = array.length; i < l; i += 1) {
74
+ if (array[i] === element) {
75
+ return true;
76
+ }
77
+ }
78
+ return false;
79
+ }
80
+
81
+ // ## uniq
82
+ // Returns an new array containing no duplicates. Preserves first occurence and order.
83
+ function uniq(array) {
84
+
85
+ var elements = {};
86
+ var result = [];
87
+
88
+ each(array, function (el) {
89
+
90
+ if (!has(elements, el)) {
91
+ result.push(el);
92
+ elements[el] = 1;
93
+ }
94
+ });
95
+
96
+ return result;
97
+ }
98
+
99
+ // ## err
100
+ // Throws an error if `condition` is `true`.
101
+ function err(condition, code, message) {
102
+
103
+ if (condition) {
104
+ var e = new Error('[modulejs-' + code + '] ' + message);
105
+ e.code = code;
106
+ throw e;
107
+ }
108
+ }
109
+
110
+
111
+
112
+ // # Private
113
+
114
+ // ## definitions
115
+ // Module definitions.
116
+ var definitions = {};
117
+
118
+ // ## instances
119
+ // Module instances.
120
+ var instances = {};
121
+
122
+ // ## resolve
123
+ // Resolves an `id` to an object, or if `onlyDepIds` is `true` only returns dependency-ids.
124
+ // `stack` is used internal to check for circular dependencies.
125
+ function resolve(id, onlyDepIds, stack) {
126
+
127
+ // check arguments
128
+ err(!isString(id), 31, 'id must be a string "' + id + '"');
129
+
130
+ // if a module is required that was already created return that object
131
+ if (!onlyDepIds && has(instances, id)) {
132
+ return instances[id];
133
+ }
134
+
135
+ // check if `id` is defined
136
+ var def = definitions[id];
137
+ err(!def, 32, 'id not defined "' + id + '"');
138
+
139
+ // copy resolve stack and add this `id`
140
+ stack = (stack || []).slice(0);
141
+ stack.push(id);
142
+
143
+ // if onlyDepIds this will hold the dependency-ids, otherwise it will hold the dependency-objects
144
+ var deps = [];
145
+
146
+ each(def.deps, function (depId) {
147
+
148
+ // check for circular dependencies
149
+ err(contains(stack, depId), 33, 'circular dependencies: ' + stack + ' & ' + depId);
150
+
151
+ if (onlyDepIds) {
152
+ deps = deps.concat(resolve(depId, onlyDepIds, stack));
153
+ deps.push(depId);
154
+ } else {
155
+ deps.push(resolve(depId, onlyDepIds, stack));
156
+ }
157
+ });
158
+
159
+ // if `onlyDepIds` return only dependency-ids in right order
160
+ if (onlyDepIds) {
161
+ return uniq(deps);
162
+ }
163
+
164
+ // create, memorize and return object
165
+ var obj = def.fn.apply(undefined, deps);
166
+ instances[id] = obj;
167
+ return obj;
168
+ }
169
+
170
+
171
+
172
+ // # Public
173
+
174
+ // ## define
175
+ // Defines a module for `id: String`, optional `deps: Array[String]`,
176
+ // `arg: Object/function`.
177
+ function define(id, deps, arg) {
178
+
179
+ // sort arguments
180
+ if (arg === undefined) {
181
+ arg = deps;
182
+ deps = [];
183
+ }
184
+ // check arguments
185
+ err(!isString(id), 11, 'id must be a string "' + id + '"');
186
+ err(definitions[id], 12, 'id already defined "' + id + '"');
187
+ err(!isArray(deps), 13, 'dependencies for "' + id + '" must be an array "' + deps + '"');
188
+ err(!isObject(arg) && !isFunction(arg), 14, 'arg for "' + id + '" must be object or function "' + arg + '"');
189
+
190
+ // accept definition
191
+ definitions[id] = {
192
+ id: id,
193
+ deps: deps,
194
+ fn: isFunction(arg) ? arg : function () { return arg; }
195
+ };
196
+ }
197
+
198
+ // ## require
199
+ // Returns an instance for `id`.
200
+ function require(id) {
201
+
202
+ return resolve(id);
203
+ }
204
+
205
+ // ## state
206
+ // Returns an object that holds infos about the current definitions and dependencies.
207
+ function state() {
208
+
209
+ var res = {};
210
+
211
+ each(definitions, function (def, id) {
212
+
213
+ res[id] = {
214
+
215
+ // direct dependencies
216
+ deps: def.deps.slice(0),
217
+
218
+ // transitive dependencies
219
+ reqs: resolve(id, true),
220
+
221
+ // already initiated/required
222
+ init: has(instances, id)
223
+ };
224
+ });
225
+
226
+ each(definitions, function (def, id) {
227
+
228
+ var inv = [];
229
+ each(definitions, function (def2, id2) {
230
+
231
+ if (contains(res[id2].reqs, id)) {
232
+ inv.push(id2);
233
+ }
234
+ });
235
+
236
+ // all inverse dependencies
237
+ res[id].reqd = inv;
238
+ });
239
+
240
+ return res;
241
+ }
242
+
243
+ // ## log
244
+ // Returns a string that displays module dependencies.
245
+ function log(inv) {
246
+
247
+ var out = '\n';
248
+
249
+ each(state(), function (st, id) {
250
+
251
+ var list = inv ? st.reqd : st.reqs;
252
+ out += (st.init ? '* ' : ' ') + id + ' -> [ ' + list.join(', ') + ' ]\n';
253
+ });
254
+
255
+ return out;
256
+ }
257
+
258
+
259
+
260
+ // # Publish
261
+
262
+ return {
263
+ define: define,
264
+ require: require,
265
+ state: state,
266
+ log: log,
267
+ _private: {
268
+ isString: isString,
269
+ isFunction: isFunction,
270
+ isArray: isArray,
271
+ isObject: isObject,
272
+ has: has,
273
+ each: each,
274
+ contains: contains,
275
+ uniq: uniq,
276
+ err: err,
277
+ definitions: definitions,
278
+ instances: instances,
279
+ resolve: resolve
280
+ }
281
+ };
282
+
283
+ }));
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: modulejs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ales Vilchytski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '4.0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.7'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: '10.0'
53
+ prerelease: false
54
+ type: :development
55
+ description: JS module system for Ruby on Rails 4 Assets Pipeline that solves scripts order issues
56
+ email:
57
+ - vilchytski.ales@yandex.by
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/modulejs-rails.rb
68
+ - lib/modulejs/rails.rb
69
+ - lib/modulejs/rails/engine.rb
70
+ - lib/modulejs/rails/version.rb
71
+ - modulejs-rails.gemspec
72
+ - vendor/assets/javascripts/README-1.5.0.md
73
+ - vendor/assets/javascripts/modulejs.js
74
+ homepage: https://github.com/ales-vilchytski/modulejs-rails
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.1.9
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Lightweight JavaScript module system for Ruby on Rails 4
98
+ test_files: []