nodeify 0.0.6 → 0.0.7
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/README.markdown +42 -5
- data/lib/nodeify/java_script.rb +5 -7
- data/lib/nodeify/version.rb +1 -1
- metadata +12 -12
data/README.markdown
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
# nodeify
|
2
2
|
|
3
|
-
Bring CLI testing and npm modules to your JavaScript.
|
3
|
+
Bring CLI testing and npm modules to your Rails JavaScript.
|
4
|
+
|
5
|
+
What it does:
|
6
|
+
|
7
|
+
* Allows you to use CommonJS require() statements in your javascript.
|
8
|
+
* Allows you to place code in separate files (modules) for organization and re-use purposes.
|
9
|
+
* Allows you to include Node.js packages in your client-side JavaScript.
|
10
|
+
|
11
|
+
Why this is cool:
|
12
|
+
|
13
|
+
* Code organization!
|
14
|
+
* Test your JavaScript from the command-line using the myriad testing libraries available from npm, such as [buster.js](http://busterjs.org), [vows.js](http://vowsjs.org), [tap](http://github.com/isaacs/node-tap), and, if you have to, [jasmine-node](http://github.com/mhevery/jasmine-node/).
|
15
|
+
* Use the ultimate "rubygems" of the JavaScript world - npm - and stop waiting for someone to package your favorite JS library in a gem or some other lesser-known package format.
|
16
|
+
|
17
|
+
What this all means:
|
18
|
+
|
19
|
+
You'll have to wrap your head around the CommonJS/npm module system. It's quite a bit different than rubygems, but is a very clean module system.
|
4
20
|
|
5
21
|
## Requirements
|
6
22
|
|
@@ -30,15 +46,36 @@ As with any Rails JS with the asset pipeline, put your app-specific JavaScripts
|
|
30
46
|
|
31
47
|
### require()
|
32
48
|
|
33
|
-
Under the standard Rails asset pipeline regime, the
|
49
|
+
Under the standard Rails asset pipeline regime, the Sprockets gem is used to manage JavaScript file loading/dependencies through the `//= require xxx` syntax. With Nodeify, your javascripts fit into the standard CommonJS modules framework. You can use `var MyLib = require('./xxx')` statements that are relative to your `app/assets/javascripts` directory. You can also use require() to load Node.js npm modules (see below).
|
50
|
+
|
51
|
+
Note that you cannot require anything outside of app/assets/javascripts. This is OK because anything that would go into lib/assets or vendor/assets should probably be its own npm module, anyway. At the very least you can dump extra libraries into app/assets/javascripts/lib and require them with `var foo = require('lib/foo');`.
|
34
52
|
|
35
53
|
#### Understanding require()
|
36
54
|
|
37
|
-
The CommonJS require() works a bit differently than Ruby's require or the sprockets //= require. CommonJS isolates modules (any code grouped into a file) into its own environment. Variables defined local to the module will only be available in that module.
|
55
|
+
The CommonJS require() works a bit differently than Ruby's require or the sprockets //= require. CommonJS isolates modules (any code grouped into a file) into its own environment. Variables defined local to the module will only be available in that module. Here are a couple of quick examples:
|
56
|
+
|
57
|
+
// in app/assets/javascripts/lib/misc.js
|
58
|
+
exports.cool = function() {
|
59
|
+
console.log('exports are cool');
|
60
|
+
};
|
61
|
+
|
62
|
+
// in app/assets/javascripts/my-class.js
|
63
|
+
var MyClass = function() { };
|
64
|
+
MyClass.prototype.cool = function() {
|
65
|
+
console.log('prototypes are cool');
|
66
|
+
};
|
67
|
+
module.exports = MyClass; // note that it's module.exports
|
68
|
+
|
69
|
+
// in app/assets/javascripts/application.js
|
70
|
+
var misc = require('./lib/misc'),
|
71
|
+
MyClass = require('./my-class'),
|
72
|
+
_ = require('underscore'); // this is an npm module
|
38
73
|
|
39
|
-
|
74
|
+
misc.cool();
|
75
|
+
var klass = new MyClass();
|
76
|
+
klass.cool();
|
77
|
+
_.each([1,2], function(i) { console.log(i); });
|
40
78
|
|
41
|
-
In the meantime, google CommonJS modules.
|
42
79
|
|
43
80
|
### Node modules
|
44
81
|
|
data/lib/nodeify/java_script.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
require 'tilt'
|
2
|
-
require 'sandbox'
|
3
1
|
require 'sprockets'
|
2
|
+
require 'fileutils'
|
4
3
|
|
5
4
|
module Nodeify
|
6
5
|
class JavaScript < Sprockets::DirectiveProcessor
|
7
6
|
def evaluate(context, options, &blk)
|
8
7
|
super
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
9
|
+
file_path = file + '.tmp'
|
10
|
+
File.open(file_path, 'w') { |f| f.puts @result }
|
11
|
+
@result = `node -e "var browserify = require('browserify'), _ = process.stdout.write(browserify({ entry: '#{file_path}', require: { http: 'http-browserify' } }).bundle());"`
|
12
|
+
FileUtils.rm_f file_path
|
15
13
|
|
16
14
|
@result
|
17
15
|
end
|
data/lib/nodeify/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nodeify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-28 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153565600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153565600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sandbox
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153564020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153564020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: tilt
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153562640 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2153562640
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &2153557660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2153557660
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &2153554300 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2153554300
|
69
69
|
description: ''
|
70
70
|
email:
|
71
71
|
- dkastner+nodeify@gmail.com
|