npm_assets 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.markdown +48 -0
- data/Rakefile +1 -0
- data/lib/npm_assets/rails.rb +12 -0
- data/lib/npm_assets/version.rb +3 -0
- data/lib/npm_assets.rb +4 -0
- data/npm_assets.gemspec +20 -0
- metadata +87 -0
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# npm_assets
|
2
|
+
|
3
|
+
A little gem to add your npm modules to the Rails asset pipeline
|
4
|
+
|
5
|
+
## Why?
|
6
|
+
|
7
|
+
The rails asset pipeline is excellent at packaging and serving javascript (and coffeescript).
|
8
|
+
But you still have to get these libraries into your app somehow. NPM is the standard in the
|
9
|
+
javascript world for distributing and packaging libraries (think rubygems). How bout we
|
10
|
+
just use that, rather than have to go make asset gems for each javascript library we
|
11
|
+
want to use?
|
12
|
+
|
13
|
+
## How?
|
14
|
+
|
15
|
+
You'll need to install node and npm first. Next, create a package.json file to
|
16
|
+
declare the npm libraries you need like so:
|
17
|
+
|
18
|
+
{
|
19
|
+
"name": "foo",
|
20
|
+
"version": "0.0.1",
|
21
|
+
"dependencies": {
|
22
|
+
"coffeekup": "",
|
23
|
+
"backbone": ""
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
Then,
|
28
|
+
|
29
|
+
$ npm install
|
30
|
+
|
31
|
+
This will grab the dependencies and pop em in a node_modules directory. This gem
|
32
|
+
will then come along and add the appropriate directories from within
|
33
|
+
each module to the asset path
|
34
|
+
|
35
|
+
In your app, to actually bring in the codez, it's just a normal require
|
36
|
+
directive:
|
37
|
+
|
38
|
+
//= require underscore
|
39
|
+
//= require backbone
|
40
|
+
|
41
|
+
## Why not?
|
42
|
+
|
43
|
+
This gem really doesn't deal with the issue of namespacing, so it may not work with some npms.
|
44
|
+
In the future, I'd like to add a separate directive (npm_require maybe?) to bring in npms
|
45
|
+
and assign them to a namespace, but for now this gem will only help you with npm libraries than
|
46
|
+
no how to deal with being in the browser (eg don't use exports if it's not present).
|
47
|
+
|
48
|
+
For an alternative solution, see nodeify.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rake'
|
2
|
+
module NpmAssets
|
3
|
+
class Rails < Rails::Railtie
|
4
|
+
initializer "npm_assets.add_asset_paths" do |app|
|
5
|
+
FileList["#{app.root}/**/node_modules/*"].each do |dir|
|
6
|
+
package = ActiveSupport::JSON.decode(File.read(File.join(dir, "package.json")))
|
7
|
+
match = package["main"].match(/.*\//)
|
8
|
+
app.config.assets.paths << (match ? File.join(dir, match[0]) : dir)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/npm_assets.rb
ADDED
data/npm_assets.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "npm_assets/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "npm_assets"
|
7
|
+
s.version = NpmAssets::VERSION
|
8
|
+
s.authors = ["Chris Nelson"]
|
9
|
+
s.email = ["chris@gaslightsoftware.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Adds your npm modules to your rails asset path}
|
12
|
+
|
13
|
+
s.rubyforge_project = "npm_assets"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.add_dependency "rails", ">= 3.1"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: npm_assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Nelson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-03 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 5
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 1
|
32
|
+
version: "3.1"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description:
|
36
|
+
email:
|
37
|
+
- chris@gaslightsoftware.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- README.markdown
|
48
|
+
- Rakefile
|
49
|
+
- lib/npm_assets.rb
|
50
|
+
- lib/npm_assets/rails.rb
|
51
|
+
- lib/npm_assets/version.rb
|
52
|
+
- npm_assets.gemspec
|
53
|
+
homepage: ""
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project: npm_assets
|
82
|
+
rubygems_version: 1.8.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Adds your npm modules to your rails asset path
|
86
|
+
test_files: []
|
87
|
+
|