npm_assets 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -40,9 +40,9 @@ directive:
40
40
 
41
41
  ## Why not?
42
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).
43
+ This gem really doesn't deal with the issue of namespacing, so it may not work with some npms. In the future, I'd like to add a separate directive (npm_require maybe?) to bring in npms
44
+ and assign them to a namespace, but for now this gem will only help you with npm libraries than know how to deal with being in the browser (eg don't use exports if it's not present).
45
+ Also, it you still have to add a require directive for each file, it won't grab dependencies for you (yet).
47
46
 
48
- For an alternative solution, see nodeify.
47
+ For an alternative solution, see nodeify. If you're down with having all your javascript code follow commonjs
48
+ module semantics, it seems like a good bet.
@@ -0,0 +1,8 @@
1
+ module NpmAssets
2
+ class NpmRequireProcessor < Sprockets::DirectiveProcessor
3
+
4
+ def process_require_npm_directive(path)
5
+ process_require_directive(path)
6
+ end
7
+ end
8
+ end
@@ -1,6 +1,10 @@
1
1
  require 'rake'
2
2
  module NpmAssets
3
3
  class Rails < Rails::Railtie
4
+ initializer "npm_assets.add_npm_require_directive_processor" do |app|
5
+ app.assets.unregister_processor('application/javascript', Sprockets::DirectiveProcessor)
6
+ app.assets.register_processor "application/javascript", NpmAssets::NpmRequireProcessor
7
+ end
4
8
  initializer "npm_assets.add_asset_paths" do |app|
5
9
  FileList["#{app.root}/**/node_modules/*"].each do |dir|
6
10
  package = ActiveSupport::JSON.decode(File.read(File.join(dir, "package.json")))
@@ -8,5 +12,8 @@ module NpmAssets
8
12
  app.config.assets.paths << (match ? File.join(dir, match[0]) : dir)
9
13
  end
10
14
  end
15
+ rake_tasks do
16
+ load "tasks/npm_assets.rake"
17
+ end
11
18
  end
12
19
  end
@@ -1,3 +1,3 @@
1
1
  module NpmAssets
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/npm_assets.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "npm_assets/version"
2
+ require "npm_assets/npm_require_processor"
2
3
  require "npm_assets/rails"
3
4
 
4
5
 
@@ -0,0 +1,25 @@
1
+ namespace :npm_assets do
2
+
3
+ desc "go thru all the coffee files, look for require_npm and add dependencies to package.json"
4
+ task :build_package_json => :environment do
5
+ npms = []
6
+ FileList["app/assets/javascripts/**/*.coffee", "spec/javascripts/**/*.coffee"].each do |f|
7
+ File.new(f).each_line do |line|
8
+ match = line.match(/^#=\s+require_npm\s+([\w_-]*)/)
9
+ npms << match[1] if match
10
+ end
11
+ end
12
+ puts npms.inspect
13
+ pkg = ActiveSupport::JSON.decode(File.read("package.json"))
14
+ npms.each do |npm|
15
+ pkg["dependencies"][npm] = "*" unless pkg["dependencies"].keys.include?(npm)
16
+ end
17
+ File.open("package.json", "w") { |f| f.puts pkg.to_json }
18
+ end
19
+
20
+ desc "run npm install"
21
+ task :install => :build_package_json do
22
+ exec "npm install"
23
+ end
24
+ end
25
+
metadata CHANGED
@@ -1,87 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: npm_assets
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Chris Nelson
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-03 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-21 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
21
16
  name: rails
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2164567360 !ruby/object:Gem::Requirement
24
18
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 5
29
- segments:
30
- - 3
31
- - 1
32
- version: "3.1"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '3.1'
33
23
  type: :runtime
34
- version_requirements: *id001
24
+ prerelease: false
25
+ version_requirements: *2164567360
35
26
  description:
36
- email:
27
+ email:
37
28
  - chris@gaslightsoftware.com
38
29
  executables: []
39
-
40
30
  extensions: []
41
-
42
31
  extra_rdoc_files: []
43
-
44
- files:
32
+ files:
45
33
  - .gitignore
46
34
  - Gemfile
47
35
  - README.markdown
48
36
  - Rakefile
49
37
  - lib/npm_assets.rb
38
+ - lib/npm_assets/npm_require_processor.rb
50
39
  - lib/npm_assets/rails.rb
51
40
  - lib/npm_assets/version.rb
41
+ - lib/tasks/npm_assets.rake
52
42
  - npm_assets.gemspec
53
- homepage: ""
43
+ has_rdoc: true
44
+ homepage: ''
54
45
  licenses: []
55
-
56
46
  post_install_message:
57
47
  rdoc_options: []
58
-
59
- require_paths:
48
+ require_paths:
60
49
  - lib
61
- required_ruby_version: !ruby/object:Gem::Requirement
50
+ required_ruby_version: !ruby/object:Gem::Requirement
62
51
  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
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
57
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
79
62
  requirements: []
80
-
81
63
  rubyforge_project: npm_assets
82
- rubygems_version: 1.8.5
64
+ rubygems_version: 1.6.2
83
65
  signing_key:
84
66
  specification_version: 3
85
67
  summary: Adds your npm modules to your rails asset path
86
68
  test_files: []
87
-