includejs 1.0.0

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/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.log
2
+ .DS_Store
3
+ doc
4
+ tmp
5
+ pkg
6
+ *.gem
7
+ *.pid
8
+ coverage
9
+ coverage.data
10
+ build/*
11
+ *.pbxuser
12
+ *.mode1v3
13
+ .svn
14
+ profile
15
+ .console_history
16
+ .sass-cache/*
17
+ .rake_tasks~
18
+ *.log.lck
19
+ solr/
20
+ .jhw-cache
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in includejs.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ includejs (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.2.8)
10
+ childprocess (0.3.2)
11
+ ffi (~> 1.0.6)
12
+ coffee-script (2.2.0)
13
+ coffee-script-source
14
+ execjs
15
+ coffee-script-source (1.3.3)
16
+ diff-lcs (1.1.3)
17
+ execjs (1.4.0)
18
+ multi_json (~> 1.0)
19
+ ffi (1.0.11)
20
+ growl (1.0.3)
21
+ guard (1.2.0)
22
+ listen (>= 0.4.2)
23
+ thor (>= 0.14.6)
24
+ guard-coffeescript (0.5.6)
25
+ coffee-script (>= 2.2.0)
26
+ guard (>= 0.8.3)
27
+ guard-jasmine-headless-webkit (0.3.2)
28
+ guard (>= 0.4.0)
29
+ jasmine-headless-webkit (>= 0.7.0)
30
+ hike (1.2.1)
31
+ jasmine (1.2.0)
32
+ jasmine-core (>= 1.2.0)
33
+ rack (~> 1.0)
34
+ rspec (>= 1.3.1)
35
+ selenium-webdriver (>= 0.1.3)
36
+ jasmine-core (1.2.0)
37
+ jasmine-headless-webkit (0.8.4)
38
+ coffee-script
39
+ jasmine-core (~> 1.1)
40
+ multi_json
41
+ rainbow
42
+ sprockets (~> 2)
43
+ libwebsocket (0.1.3)
44
+ addressable
45
+ listen (0.4.6)
46
+ rb-fchange (~> 0.0.5)
47
+ rb-fsevent (~> 0.9.1)
48
+ rb-inotify (~> 0.8.8)
49
+ multi_json (1.3.5)
50
+ rack (1.4.1)
51
+ rainbow (1.1.4)
52
+ rake (0.9.2.2)
53
+ rb-fchange (0.0.5)
54
+ ffi
55
+ rb-fsevent (0.9.1)
56
+ rb-inotify (0.8.8)
57
+ ffi (>= 0.5.0)
58
+ rspec (2.10.0)
59
+ rspec-core (~> 2.10.0)
60
+ rspec-expectations (~> 2.10.0)
61
+ rspec-mocks (~> 2.10.0)
62
+ rspec-core (2.10.1)
63
+ rspec-expectations (2.10.0)
64
+ diff-lcs (~> 1.1.3)
65
+ rspec-mocks (2.10.1)
66
+ rubyzip (0.9.8)
67
+ selenium-webdriver (2.21.2)
68
+ childprocess (>= 0.2.5)
69
+ ffi (~> 1.0)
70
+ libwebsocket (~> 0.1.3)
71
+ multi_json (~> 1.0)
72
+ rubyzip
73
+ sprockets (2.4.3)
74
+ hike (~> 1.2)
75
+ multi_json (~> 1.0)
76
+ rack (~> 1.0)
77
+ tilt (~> 1.1, != 1.3.0)
78
+ thor (0.15.3)
79
+ tilt (1.3.3)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ growl
86
+ guard
87
+ guard-coffeescript
88
+ guard-jasmine-headless-webkit
89
+ includejs!
90
+ jasmine
91
+ jasmine-headless-webkit
92
+ rake
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'coffeescript', input: 'src', output: "vendor/assets/javascripts", bare: false
5
+
6
+ spec_location = "spec/javascripts/%s_spec"
7
+ guard 'jasmine-headless-webkit' do
8
+ watch(%r{^src/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
9
+ watch(%r{^vendor/assets/javascripts/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
10
+ watch(%r{^spec/javascripts/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) }
11
+ end
12
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mark Bates
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,91 @@
1
+ # Includejs
2
+
3
+ Allows you to inject functions and variables from other JavaScript objects into your current object. This is similar to the functionality provided by `_.extend` in the [Underscore.js](http://documentcloud.github.com/underscore/#extend) library, the difference being that Includejs will binded the functions to the current object.
4
+
5
+ ## Installation
6
+
7
+ ### Ruby/Rails
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'includejs'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install includejs
20
+
21
+ ### Rails
22
+
23
+ Require `includejs` in your asset pipeline and you're ready to go.
24
+
25
+ ### Non-Rails
26
+
27
+ To use this outside of a Rails application simply copy the `vendor/assets/javascripts/includejs.js` file and add it to your application. That's it.
28
+
29
+ ## Usage
30
+
31
+ ### CoffeeScript Example:
32
+
33
+ ``` coffeescript
34
+ BazModule =
35
+ sayHi: ->
36
+ "Hello #{@name}!"
37
+ # If there is an 'included' function it will
38
+ # be called when the module is included.
39
+ included: (klass) ->
40
+ klass.baz = "Baz!!"
41
+
42
+ class Foo
43
+ constructor: ->
44
+ include(@, BazModule)
45
+
46
+ foo = new Foo()
47
+ foo.sayHi() # => "Hello undefined!"
48
+
49
+ foo.name = "Mark"
50
+ foo.sayHi() # => "Hello Mark!"
51
+ ```
52
+
53
+ ### JavaScript Example:
54
+
55
+ ``` javascript
56
+ var BazModule, foo;
57
+
58
+ BazModule = {
59
+ sayHi: function() {
60
+ return "Hello " + this.name + "!";
61
+ },
62
+ // If there is an 'included' function it will
63
+ // be called when the module is included.
64
+ included: function(klass) {
65
+ klass.baz = "Baz!!";
66
+ }
67
+ };
68
+
69
+ foo = {}
70
+ include(foo, BazModule);
71
+
72
+ foo.sayHi(); // => "Hello undefined!"
73
+
74
+ foo.name = "Mark";
75
+
76
+ foo.sayHi(); // => "Hello Mark!"
77
+ ```
78
+
79
+ ## Testing
80
+
81
+ 1. Run `bundle install`.
82
+ 2. Run `guard` or alternatively `rake`.
83
+ 3. **Write your tests. No pull request will be accepted without tests.**
84
+
85
+ ## Contributing
86
+
87
+ 1. Fork it
88
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
89
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
90
+ 4. Push to the branch (`git push origin my-new-feature`)
91
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ begin
5
+ require 'jasmine'
6
+ load 'jasmine/tasks/jasmine.rake'
7
+ rescue LoadError
8
+ task :jasmine do
9
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
10
+ end
11
+ end
12
+
13
+ task :default do
14
+ system "jasmine-headless-webkit -c"
15
+ end
data/includejs.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/includejs/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Mark Bates"]
6
+ gem.email = ["mark@markbates.com"]
7
+ gem.description = %q{Adds the ability to include Modules into JavaScript objects}
8
+ gem.summary = %q{Adds the ability to include Modules into JavaScript objects}
9
+ gem.homepage = "https://github.com/markbates/includejs"
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 = "includejs"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Includejs::VERSION
17
+
18
+ gem.add_development_dependency("rake")
19
+ gem.add_development_dependency("growl")
20
+ gem.add_development_dependency("guard")
21
+ gem.add_development_dependency("guard-coffeescript")
22
+ gem.add_development_dependency("guard-jasmine-headless-webkit")
23
+ gem.add_development_dependency("jasmine")
24
+ gem.add_development_dependency("jasmine-headless-webkit")
25
+ end
@@ -0,0 +1,6 @@
1
+ if defined? Rails
2
+ module Includejs
3
+ class Engine < Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Includejs
2
+ VERSION = "1.0.0"
3
+ end
data/lib/includejs.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'includejs/engine'
2
+ require "includejs/version"
File without changes
@@ -0,0 +1,68 @@
1
+ describe "include", ->
2
+
3
+ HelloModule =
4
+ sayHi: ->
5
+ "Hello!"
6
+
7
+ ByeModule =
8
+ sayBye: ->
9
+ "Bye!"
10
+
11
+ BazModule =
12
+ sayHi: ->
13
+ "Hello #{@name}!"
14
+ included: (klass) ->
15
+ klass.baz = "Baz!!"
16
+
17
+ it "includes functions from the module into a class", ->
18
+ class Foo
19
+ constructor: ->
20
+ include(@, HelloModule)
21
+
22
+ foo = new Foo()
23
+ expect(foo.sayHi()).toEqual("Hello!")
24
+
25
+ it "includes multiple modules", ->
26
+ class Foo
27
+ constructor: ->
28
+ include(@, HelloModule, ByeModule)
29
+
30
+ foo = new Foo()
31
+ expect(foo.sayHi()).toEqual("Hello!")
32
+ expect(foo.sayBye()).toEqual("Bye!")
33
+
34
+ it "calls the 'included' function if available", ->
35
+ class Foo
36
+ constructor: ->
37
+ include(@, BazModule)
38
+
39
+ foo = new Foo()
40
+ expect(foo.baz).toEqual("Baz!!")
41
+
42
+ it "binds the functions to the class", ->
43
+ class Foo
44
+ constructor: ->
45
+ include(@, BazModule)
46
+
47
+ foo = new Foo()
48
+ expect(foo.sayHi()).toEqual("Hello undefined!")
49
+
50
+ foo.name = "Mark"
51
+ expect(foo.sayHi()).toEqual("Hello Mark!")
52
+
53
+ x = (fn) -> fn()
54
+
55
+ expect(x(foo.sayHi)).toEqual("Hello Mark!")
56
+
57
+ it "works with plain objects as well", ->
58
+ foo = {}
59
+ include(foo, BazModule)
60
+
61
+ expect(foo.sayHi()).toEqual("Hello undefined!")
62
+
63
+ foo.name = "Mark"
64
+ expect(foo.sayHi()).toEqual("Hello Mark!")
65
+
66
+ x = (fn) -> fn()
67
+
68
+ expect(x(foo.sayHi)).toEqual("Hello Mark!")
@@ -0,0 +1,13 @@
1
+ src_files:
2
+ - "**/*.coffee"
3
+
4
+ helpers:
5
+ - "helpers/**/*.coffee"
6
+
7
+ spec_files:
8
+ - /**/*_spec.coffee
9
+ - /**/*_spec.js
10
+
11
+ src_dir: "src"
12
+
13
+ spec_dir: spec/javascripts
@@ -0,0 +1,18 @@
1
+ ###
2
+ Includejs
3
+
4
+ https://github.com/markbates/includejs
5
+ ###
6
+ @include = (klass, modules...) =>
7
+ __binder = (fn, me) ->
8
+ return ->
9
+ return fn.apply(me, arguments)
10
+
11
+ for mod in modules
12
+
13
+ if mod.included?
14
+ mod.included(klass)
15
+
16
+ for key, value of mod
17
+ unless key in ["included", "include"]
18
+ klass[key] = __binder(value, klass)
@@ -0,0 +1,44 @@
1
+
2
+ /*
3
+ Includejs
4
+
5
+ https://github.com/markbates/includejs
6
+ */
7
+
8
+
9
+ (function() {
10
+ var _this = this,
11
+ __slice = [].slice;
12
+
13
+ this.include = function() {
14
+ var key, klass, mod, modules, value, __binder, _i, _len, _results;
15
+ klass = arguments[0], modules = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
16
+ __binder = function(fn, me) {
17
+ return function() {
18
+ return fn.apply(me, arguments);
19
+ };
20
+ };
21
+ _results = [];
22
+ for (_i = 0, _len = modules.length; _i < _len; _i++) {
23
+ mod = modules[_i];
24
+ if (mod.included != null) {
25
+ mod.included(klass);
26
+ }
27
+ _results.push((function() {
28
+ var _results1;
29
+ _results1 = [];
30
+ for (key in mod) {
31
+ value = mod[key];
32
+ if (key !== "included" && key !== "include") {
33
+ _results1.push(klass[key] = __binder(value, klass));
34
+ } else {
35
+ _results1.push(void 0);
36
+ }
37
+ }
38
+ return _results1;
39
+ })());
40
+ }
41
+ return _results;
42
+ };
43
+
44
+ }).call(this);
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: includejs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Bates
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70170748893700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70170748893700
25
+ - !ruby/object:Gem::Dependency
26
+ name: growl
27
+ requirement: &70170748892260 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70170748892260
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard
38
+ requirement: &70170748891440 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70170748891440
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-coffeescript
49
+ requirement: &70170748888760 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70170748888760
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard-jasmine-headless-webkit
60
+ requirement: &70170748902560 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70170748902560
69
+ - !ruby/object:Gem::Dependency
70
+ name: jasmine
71
+ requirement: &70170748899440 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70170748899440
80
+ - !ruby/object:Gem::Dependency
81
+ name: jasmine-headless-webkit
82
+ requirement: &70170748896620 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70170748896620
91
+ description: Adds the ability to include Modules into JavaScript objects
92
+ email:
93
+ - mark@markbates.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - .gitignore
99
+ - Gemfile
100
+ - Gemfile.lock
101
+ - Guardfile
102
+ - LICENSE
103
+ - README.md
104
+ - Rakefile
105
+ - includejs.gemspec
106
+ - lib/includejs.rb
107
+ - lib/includejs/engine.rb
108
+ - lib/includejs/version.rb
109
+ - spec/javascripts/helpers/spec_helper.coffee
110
+ - spec/javascripts/includejs_spec.coffee
111
+ - spec/javascripts/support/jasmine.yml
112
+ - src/includejs.js.coffee
113
+ - vendor/assets/javascripts/includejs.js
114
+ homepage: https://github.com/markbates/includejs
115
+ licenses: []
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.10
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Adds the ability to include Modules into JavaScript objects
138
+ test_files:
139
+ - spec/javascripts/helpers/spec_helper.coffee
140
+ - spec/javascripts/includejs_spec.coffee
141
+ - spec/javascripts/support/jasmine.yml