rack-livejs 0.1.1 → 0.2.0

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.
@@ -1,14 +1,18 @@
1
+ require 'rack'
2
+
1
3
  module Rack
2
4
  class Livejs
3
5
 
4
6
  attr_reader :app
5
7
 
6
8
  def initialize(app, options = {})
7
- @app, @options = app, options
9
+ @app = Rack::URLMap.new(
10
+ bundled_livejs_prefix => Rack::File.new(bundled_livejs_dir),
11
+ '/' => app
12
+ )
8
13
  end
9
14
 
10
15
  def call(env)
11
- return livejs_response if env["PATH_INFO"] == livejs_path
12
16
  status, headers, body = @app.call(env)
13
17
  if headers["Content-Type"] == "text/html"
14
18
  new_html = inject_livejs(read_body(body))
@@ -20,10 +24,6 @@ module Rack
20
24
 
21
25
  private
22
26
 
23
- def livejs_path
24
- "/_rack_livejs_/live.js"
25
- end
26
-
27
27
  def read_body(body)
28
28
  "".tap do |buffer|
29
29
  body.each { |chunk| buffer << chunk }
@@ -31,19 +31,19 @@ module Rack
31
31
  end
32
32
 
33
33
  def inject_livejs(html)
34
- html.sub(%r{(<head( [^>]*)?>)}i) { $1 + %{<script src="#{livejs_path}"/>} }
34
+ html.sub(%r{(<head( [^>]*)?>)}i) { $1 + %{<script src="#{bundled_livejs_path}"/>} }
35
+ end
36
+
37
+ def bundled_livejs_prefix
38
+ "/_rack_livejs_"
35
39
  end
36
40
 
37
- def livejs_javascript
38
- @@livejs_javascript ||= ::File.read(::File.expand_path("../../../vendor/livejs/live.js", __FILE__))
41
+ def bundled_livejs_dir
42
+ ::File.expand_path("../../../vendor/livejs", __FILE__)
39
43
  end
40
44
 
41
- def livejs_response
42
- [
43
- 200,
44
- { 'Content-Type' => "application/javascript", 'Content-Length' => livejs_javascript.size.to_s },
45
- [ livejs_javascript ]
46
- ]
45
+ def bundled_livejs_path
46
+ bundled_livejs_prefix + "/live.js"
47
47
  end
48
48
 
49
49
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Livejs
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "rack"
21
22
  spec.add_development_dependency "bundler", "~> 1.3"
22
23
 
23
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-livejs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,6 +11,22 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: bundler
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -65,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
81
  version: '0'
66
82
  segments:
67
83
  - 0
68
- hash: 2181008550174536603
84
+ hash: -3427976022966837224
69
85
  required_rubygems_version: !ruby/object:Gem::Requirement
70
86
  none: false
71
87
  requirements:
@@ -74,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
90
  version: '0'
75
91
  segments:
76
92
  - 0
77
- hash: 2181008550174536603
93
+ hash: -3427976022966837224
78
94
  requirements: []
79
95
  rubyforge_project:
80
96
  rubygems_version: 1.8.23