browserify-rails 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 907912f1aadcbeafc0c4d0a980f519e5c9ca1ba6
4
- data.tar.gz: 81dfa83d15625dcbc59c3991dbfd040025213702
3
+ metadata.gz: a2c2135417c9ff3fde1f33690d28a0e864063fac
4
+ data.tar.gz: 12f3ee03a61deba05417f0de2d7cf5dae7712500
5
5
  SHA512:
6
- metadata.gz: be64aec51ab18d1fa128560901a749caff2044419755e38e9eb9092a433e8f63d47fe65f07f514bd31a2f8a826efb48ebab91407ca0e3bddf4b06fa4f8702b32
7
- data.tar.gz: ecebfdc971e5617d74278a29dbdaf4d9cd761b5586d517a0cf5ad7faddcf9f79fa2b195ea3c3d4ed1f9fa9042033249cfd776df905f2bdba2980efd87ebc1dfb
6
+ metadata.gz: cb63140be9731fc9dba6ef7e59913d9304904f6db7b41593d136a07693c27a890b3f8b172a096ebcef777e4d3ebbd8ec949c3cd1cea9f6f51371ce633cdeebbd
7
+ data.tar.gz: 73687ed29616ca71095e2bbb15ded54b963ea078b1faac79e2adc4045a56ca50091e897e6be831d41d615ab67a1df2426d541580061554ea744cd29c0f585426
data/.gitignore CHANGED
@@ -24,3 +24,4 @@ test/dummy/db/schema.rb
24
24
  tmp
25
25
  test/dummy/app/assets/javascripts/*.js
26
26
  test/dummy/app/assets/javascripts/**/*.js
27
+ test/dummy/app/assets/javascripts/**/*.js.coffee
data/README.md CHANGED
@@ -16,7 +16,7 @@ It let's you mix and match `//= require` directives and `require()` calls for i
16
16
 
17
17
  Add this line to your application's Gemfile:
18
18
 
19
- gem "hsume2-browserify-rails", "~> 0.2.0", :require => "browserify-rails"
19
+ gem "browserify-rails", "~> 0.3"
20
20
 
21
21
  Create `package.json` in your Rails root:
22
22
 
@@ -48,11 +48,28 @@ var foo = require('./foo');
48
48
  console.log(foo(12));
49
49
  ```
50
50
 
51
- ## Coffeescript
51
+ ## CoffeeScript
52
52
 
53
- Coffeescript is handled seamlessly, if you name your files `*.js.coffee`. That
54
- way the coffeescript compiler will already have done it's work, when we are
55
- putting the javascript tools to work.
53
+ For CoffeeScript support, make sure to follow the standard rails
54
+ `.js.coffee` naming convention. You'll also need to do the following:
55
+
56
+ Add `coffeify` as a dependency within `package.json`:
57
+
58
+ ```js
59
+ {
60
+ // ...
61
+ "devDependencies" : {
62
+ // ...
63
+ "coffeeify": "~> 0.6"
64
+ }
65
+ }
66
+ ```
67
+
68
+ Add the following command line options within `application.rb`:
69
+
70
+ ```rb
71
+ config.browserify_rails.commandline_options = "-t coffeeify --extension=\".js.coffee\""
72
+ ```
56
73
 
57
74
  ## Configuration
58
75
 
@@ -23,5 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rails", "~> 3.2"
26
+ spec.add_development_dependency "coffee-rails"
26
27
  spec.add_development_dependency "mocha"
28
+ spec.add_development_dependency "pry"
27
29
  end
@@ -1,5 +1,4 @@
1
1
  require "open3"
2
- require "json"
3
2
 
4
3
  module BrowserifyRails
5
4
  class BrowserifyProcessor < Tilt::Template
@@ -9,7 +8,7 @@ module BrowserifyRails
9
8
  end
10
9
 
11
10
  def evaluate(context, locals, &block)
12
- if should_browserify? && commonjs_module?
11
+ if should_browserify?
13
12
  asset_dependencies(context.environment.paths).each do |path|
14
13
  context.depend_on(path)
15
14
  end
@@ -23,7 +22,12 @@ module BrowserifyRails
23
22
  private
24
23
 
25
24
  def should_browserify?
26
- Rails.application.config.browserify_rails.paths.any? do |path_spec|
25
+ in_path? && commonjs_module?
26
+ end
27
+
28
+ # Is this file in any of the configured paths?
29
+ def in_path?
30
+ config.paths.any? do |path_spec|
27
31
  path_spec === file
28
32
  end
29
33
  end
@@ -47,7 +51,7 @@ module BrowserifyRails
47
51
 
48
52
  # @return [<String>] Paths of files, that this file depends on
49
53
  def dependencies
50
- @dependencies ||= run_browserify("--list").lines.map(&:strip).select do |path|
54
+ @dependencies ||= run_browserify("#{options} --list").lines.map(&:strip).select do |path|
51
55
  # Filter the temp file, where browserify caches the input stream
52
56
  File.exists?(path)
53
57
  end
@@ -1,3 +1,3 @@
1
1
  module BrowserifyRails
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -1,13 +1,14 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  class BrowserifyTest < ActionController::IntegrationTest
4
-
5
4
  setup do
6
5
  Rails.application.assets.cache = nil
7
6
 
8
- FileUtils.cp(File.join(Rails.root, 'app/assets/javascripts/application.js.example'), File.join(Rails.root, 'app/assets/javascripts/application.js'))
9
- FileUtils.cp(File.join(Rails.root, 'app/assets/javascripts/foo.js.example'), File.join(Rails.root, 'app/assets/javascripts/foo.js'))
10
- FileUtils.cp(File.join(Rails.root, 'app/assets/javascripts/nested/index.js.example'), File.join(Rails.root, 'app/assets/javascripts/nested/index.js'))
7
+ FileUtils.cp(File.join(Rails.root, "app/assets/javascripts/application.js.example"), File.join(Rails.root, "app/assets/javascripts/application.js"))
8
+ FileUtils.cp(File.join(Rails.root, "app/assets/javascripts/foo.js.example"), File.join(Rails.root, "app/assets/javascripts/foo.js"))
9
+ FileUtils.cp(File.join(Rails.root, "app/assets/javascripts/nested/index.js.example"), File.join(Rails.root, "app/assets/javascripts/nested/index.js"))
10
+ FileUtils.cp(File.join(Rails.root, "app/assets/javascripts/mocha.js.coffee.example"), File.join(Rails.root, "app/assets/javascripts/mocha.js.coffee"))
11
+ FileUtils.cp(File.join(Rails.root, "app/assets/javascripts/coffee.js.coffee.example"), File.join(Rails.root, "app/assets/javascripts/coffee.js.coffee"))
11
12
  end
12
13
 
13
14
  test "asset pipeline should serve application.js" do
@@ -36,7 +37,7 @@ class BrowserifyTest < ActionController::IntegrationTest
36
37
  # Ensure that Sprockets can detect the change to the file modification time
37
38
  sleep 1
38
39
 
39
- File.open(File.join(Rails.root, 'app/assets/javascripts/foo.js'), 'w+') do |f|
40
+ File.open(File.join(Rails.root, "app/assets/javascripts/foo.js"), "w+") do |f|
40
41
  f.puts "require('./nested');"
41
42
  f.puts "module.exports = function (n) { return n * 12 }"
42
43
  end
@@ -58,7 +59,7 @@ class BrowserifyTest < ActionController::IntegrationTest
58
59
  # Ensure that Sprockets can detect the change to the file modification time
59
60
  sleep 1
60
61
 
61
- File.open(File.join(Rails.root, 'app/assets/javascripts/application.js'), 'w+') do |f|
62
+ File.open(File.join(Rails.root, "app/assets/javascripts/application.js"), "w+") do |f|
62
63
  f.puts "var foo = require('./foo');"
63
64
  f.puts "console.log(foo(11));"
64
65
  end
@@ -70,8 +71,22 @@ class BrowserifyTest < ActionController::IntegrationTest
70
71
  assert_equal expected_output, @response.body.strip
71
72
  end
72
73
 
74
+ test "browserifies coffee files after they have been compiled to JS" do
75
+ expected_output = fixture("mocha.js")
76
+
77
+ get "/assets/mocha.js"
78
+
79
+ assert_response :success
80
+ assert_equal expected_output, @response.body.strip
81
+ end
82
+
83
+ test "browserifies files with coffee requires" do
84
+ get "/assets/coffee.js"
85
+ assert_no_match /BrowserifyRails::BrowserifyError/, @response.body
86
+ end
87
+
73
88
  test "throws BrowserifyError if something went wrong while executing browserify" do
74
- File.open(File.join(Rails.root, 'app/assets/javascripts/application.js'), 'w+') do |f|
89
+ File.open(File.join(Rails.root, "app/assets/javascripts/application.js"), "w+") do |f|
75
90
  f.puts "var foo = require('./foo');"
76
91
  f.puts "var bar = require('./bar');"
77
92
  end
@@ -0,0 +1,4 @@
1
+ f = require("./foo")
2
+
3
+ hello = ->
4
+ alert("Hello browserify #{f 5}")
@@ -39,6 +39,8 @@ module Dummy
39
39
 
40
40
  # Enable the asset pipeline
41
41
  config.assets.enabled = true
42
+
43
+ # Add CoffeeScript support
44
+ config.browserify_rails.commandline_options = "-t coffeeify --extension=\".js.coffee\""
42
45
  end
43
46
  end
44
-
@@ -3,7 +3,8 @@
3
3
  "author": "Henry Hsu <hhsu@zendesk.com>",
4
4
  "description": "a dummy Rails application",
5
5
  "devDependencies" : {
6
- "browserify": "~> 4.1"
6
+ "browserify": "~> 4.1",
7
+ "coffeeify": "~> 0.6"
7
8
  },
8
9
  "license": "MIT",
9
10
  "engines": {
@@ -0,0 +1,20 @@
1
+ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ (function() {
3
+ var f, hello;
4
+
5
+ f = require("./foo");
6
+
7
+ hello = function() {
8
+ return alert("Hello browserify " + (f(5)));
9
+ };
10
+
11
+ }).call(this);
12
+
13
+ },{"./foo":2}],2:[function(require,module,exports){
14
+ require('./nested');
15
+ module.exports = function (n) { return n * 11 }
16
+
17
+ },{"./nested":3}],3:[function(require,module,exports){
18
+ module.exports.NESTED = true;
19
+
20
+ },{}]},{},[1])
@@ -15,6 +15,8 @@ FileUtils.rm_rf "#{File.dirname(__FILE__)}/dummy/tmp"
15
15
 
16
16
  ActiveSupport::TestCase.class_eval do
17
17
  def fixture(filename)
18
- File.open(File.join(File.dirname(__FILE__), "/fixtures/#{filename}")).read.strip
18
+ File.open(File.join(File.dirname(__FILE__), "fixtures", filename)) do |f|
19
+ f.read.strip
20
+ end
19
21
  end
20
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browserify-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Hsu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-28 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coffee-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: mocha
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: Browserify + Rails = CommonJS Heaven
84
112
  email:
85
113
  - hhsu@zendesk.com
@@ -104,7 +132,9 @@ files:
104
132
  - test/compilation_test.rb
105
133
  - test/dummy/Rakefile
106
134
  - test/dummy/app/assets/javascripts/application.js.example
135
+ - test/dummy/app/assets/javascripts/coffee.js.coffee.example
107
136
  - test/dummy/app/assets/javascripts/foo.js.example
137
+ - test/dummy/app/assets/javascripts/mocha.js.coffee.example
108
138
  - test/dummy/app/assets/javascripts/nested/index.js.example
109
139
  - test/dummy/app/assets/stylesheets/application.css
110
140
  - test/dummy/app/controllers/application_controller.rb
@@ -142,6 +172,7 @@ files:
142
172
  - test/fixtures/application.out.js
143
173
  - test/fixtures/empty_module.js
144
174
  - test/fixtures/foo.out.js
175
+ - test/fixtures/mocha.js
145
176
  - test/test_helper.rb
146
177
  homepage: ''
147
178
  licenses:
@@ -172,7 +203,9 @@ test_files:
172
203
  - test/compilation_test.rb
173
204
  - test/dummy/Rakefile
174
205
  - test/dummy/app/assets/javascripts/application.js.example
206
+ - test/dummy/app/assets/javascripts/coffee.js.coffee.example
175
207
  - test/dummy/app/assets/javascripts/foo.js.example
208
+ - test/dummy/app/assets/javascripts/mocha.js.coffee.example
176
209
  - test/dummy/app/assets/javascripts/nested/index.js.example
177
210
  - test/dummy/app/assets/stylesheets/application.css
178
211
  - test/dummy/app/controllers/application_controller.rb
@@ -210,4 +243,5 @@ test_files:
210
243
  - test/fixtures/application.out.js
211
244
  - test/fixtures/empty_module.js
212
245
  - test/fixtures/foo.out.js
246
+ - test/fixtures/mocha.js
213
247
  - test/test_helper.rb