jbundle 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jbundle (0.1.1)
4
+ jbundle (0.1.2)
5
5
  closure-compiler
6
6
  rack
7
7
  thor
@@ -50,9 +50,13 @@ module JBundle
50
50
  end
51
51
 
52
52
  def build(name)
53
- found = config.bundles_and_files.detect {|f| f.original_name == name}
53
+ Builder.new(config).build_one find(name)
54
+ end
55
+
56
+ def find(name)
57
+ found = config.bundles_and_files.detect {|f| f.original_name == name || f.name == name}
54
58
  raise NoBundleError, "No bundle or file found with name #{name}" unless found
55
- Builder.new(config).build_one found
59
+ found
56
60
  end
57
61
 
58
62
  def config_from_file(file)
@@ -13,8 +13,12 @@ module JBundle
13
13
  @name, @dir = parse_name(name)
14
14
  end
15
15
 
16
+ def ext
17
+ @ext ||= ::File.extname(name)
18
+ end
19
+
16
20
  def buildable?
17
- BUILDABLE_FILES.include?(::File.extname(name))
21
+ BUILDABLE_FILES.include?(ext)
18
22
  end
19
23
 
20
24
  # This only makes sense for one-file objects
@@ -25,11 +25,10 @@ module JBundle
25
25
  method_option :port, :default => "5555", :aliases => "-p"
26
26
  method_option :jfile, :default => JBundle::JFILE, :aliases => "-j"
27
27
  def server
28
- require 'rack'
29
28
  JBundle.config_from_file(options[:jfile])
30
29
  say "Starting test server on http://localhost:#{options[:port]}. Available bundles:", :yellow
31
30
  JBundle.config.bundles_and_files.each do |f|
32
- say "- /#{f.original_name}", :green
31
+ say "- /#{f.original_name} ==> /#{f.name}", :green
33
32
  end
34
33
 
35
34
  handler = Rack::Handler.default
@@ -65,7 +64,7 @@ Done. Try it!
65
64
  Then package your work
66
65
 
67
66
  jsbundle
68
- )
67
+ )
69
68
 
70
69
  desc 'init', 'Create example JFile and test stubs'
71
70
  method_option :tests, :default => 'qunit', :aliases => '-t'
@@ -1,3 +1,4 @@
1
+ require 'rack'
1
2
  module JBundle
2
3
 
3
4
  class Server
@@ -13,7 +14,9 @@ module JBundle
13
14
  bundle_name = env['PATH_INFO'].sub('/', '')
14
15
  begin
15
16
  JBundle.config_from_file(@jfile)
16
- [200, {'Content-Type' => 'application/x-javascript'}, [JBundle.build(bundle_name).src]]
17
+ compiler = JBundle.build(bundle_name)
18
+ body = compiler.buildable? ? compiler.src : compiler.raw_src
19
+ [200, {'Content-Type' => ::Rack::Mime.mime_type(compiler.ext)}, [body]]
17
20
  rescue NoBundleError => boom
18
21
  p = bundle_name == '' ? '[bundle_name].js' : bundle_name
19
22
  [404, {'Content-Type' => 'text/plain'}, ["No bundle defined. Try defining /#{p} in your JFile"]]
@@ -1,3 +1,3 @@
1
1
  module JBundle
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -9,33 +9,53 @@ describe "JBundle::Server" do
9
9
  end
10
10
 
11
11
  describe '#call' do
12
- before do
13
- @response = @server.call({'PATH_INFO' => '/foo.js'})
14
- end
15
-
16
- it 'should be 404 if no JFile found' do
17
- s = JBundle::Server.new("doesn-not-exist")
18
- r = s.call({'PATH_INFO' => '/foo.js'})
19
- r[0].should == 404
20
- end
21
-
22
- it 'should be 200 OK' do
23
- @response[0].should == 200
24
- end
25
-
26
- it 'should be a javascript response' do
27
- @response[1]['Content-Type'].should == 'application/x-javascript'
28
- end
29
12
 
30
- it 'should return content for given bundle' do
31
- @response[2].should == [JBundle.build('foo.js').src]
13
+ describe 'with JavaScript bundle' do
14
+ before do
15
+ @response = @server.call({'PATH_INFO' => '/foo.js'})
16
+ end
17
+
18
+ it 'should be 404 if no JFile found' do
19
+ s = JBundle::Server.new("doesn-not-exist")
20
+ r = s.call({'PATH_INFO' => '/foo.js'})
21
+ r[0].should == 404
22
+ end
23
+
24
+ it 'should be 200 OK' do
25
+ @response[0].should == 200
26
+ end
27
+
28
+ it 'should be a javascript response' do
29
+ @response[1]['Content-Type'].should == 'application/javascript'
30
+ end
31
+
32
+ it 'should return content for given bundle' do
33
+ @response[2].should == [JBundle.build('foo.js').src]
34
+ end
35
+
36
+ it 'should be 404 when no bundle found' do
37
+ r = @server.call({'PATH_INFO' => '/nonexisting.js'})
38
+ r[0].should == 404
39
+ end
32
40
  end
33
41
 
34
- it 'should be 404 when no bundle found' do
35
- r = @server.call({'PATH_INFO' => '/nonexisting.js'})
36
- r[0].should == 404
42
+ describe 'with non-JS file' do
43
+
44
+ it 'should find and serve by original name' do
45
+ response = @server.call({'PATH_INFO' => '/nested/foo.txt'})
46
+ response[0].should == 200
47
+ response[1]['Content-Type'].should == 'text/plain'
48
+ response[2].should == ["This file is in a nested subdirectory\n"]
49
+ end
50
+
51
+ it 'should find and serve by distribution file name' do
52
+ response = @server.call({'PATH_INFO' => '/flat_foo.txt'})
53
+ response[0].should == 200
54
+ response[1]['Content-Type'].should == 'text/plain'
55
+ response[2].should == ["This file is in a nested subdirectory\n"]
56
+ end
57
+
37
58
  end
38
-
39
59
  end
40
60
 
41
61
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jbundle
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ismael Celis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-02 00:00:00 +01:00
13
+ date: 2011-06-19 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency