middleman-livereload 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- git "git://github.com/middleman/middleman.git" do
3
+ git "git://github.com/middleman/middleman.git", :branch => "3.0-stable" do
4
4
  # gem "middleman"
5
5
  gem "middleman-core"
6
6
  # gem "middleman-more"
@@ -18,12 +18,28 @@ module Middleman
18
18
  app.ready do
19
19
  # Doesn't make sense in build
20
20
  if environment != :build
21
- reactor = Reactor.new(options)
21
+ reactor = Reactor.new(options, self)
22
22
 
23
- files.changed { |file| reactor.reload_browser(file) }
24
- files.deleted { |file| reactor.reload_browser(file) }
23
+ files.changed do |file|
24
+ sitemap.ensure_resource_list_updated!
25
+
26
+ begin
27
+ file_url = sitemap.file_to_path(file)
28
+ file_resource = sitemap.find_resource_by_path(file_url)
29
+ reload_path = file_resource.destination_path
30
+ rescue
31
+ reload_path = "#{Dir.pwd}/#{file}"
32
+ end
33
+
34
+ reactor.reload_browser(reload_path)
35
+ end
36
+
37
+ files.deleted do |file|
38
+ sitemap.ensure_resource_list_updated!
39
+ reactor.reload_browser("#{Dir.pwd}/#{file}")
40
+ end
25
41
 
26
- use ::Rack::LiveReload
42
+ use ::Rack::LiveReload, :port => options[:port].to_i, :host => options[:host]
27
43
  end
28
44
  end
29
45
  end
@@ -31,9 +47,11 @@ module Middleman
31
47
  end
32
48
 
33
49
  class Reactor
34
- attr_reader :thread, :web_sockets
35
-
36
- def initialize(options)
50
+ attr_reader :thread, :web_sockets, :app
51
+ delegate :logger, :to => :app
52
+
53
+ def initialize(options, app)
54
+ @app = app
37
55
  @web_sockets = []
38
56
  @options = options
39
57
  @thread = start_threaded_reactor(options)
@@ -45,14 +63,14 @@ module Middleman
45
63
 
46
64
  def reload_browser(paths = [])
47
65
  paths = Array(paths)
48
- puts "Reloading browser: #{paths.join(' ')}"
66
+ logger.info "== LiveReloading path: #{paths.join(' ')}"
49
67
  paths.each do |path|
50
68
  data = MultiJson.encode(['refresh', {
51
- :path => "#{Dir.pwd}/#{path}",
69
+ :path => path,
52
70
  :apply_js_live => @options[:apply_js_live],
53
71
  :apply_css_live => @options[:apply_css_live]
54
72
  }])
55
- # UI.debug data
73
+
56
74
  @web_sockets.each { |ws| ws.send(data) }
57
75
  end
58
76
  end
@@ -60,13 +78,13 @@ module Middleman
60
78
  def start_threaded_reactor(options)
61
79
  Thread.new do
62
80
  EventMachine.run do
63
- puts "LiveReload #{options[:api_version]} is waiting for a browser to connect."
81
+ logger.info "== LiveReload is waiting for a browser to connect"
64
82
  EventMachine.start_server(options[:host], options[:port], EventMachine::WebSocket::Connection, {}) do |ws|
65
83
  ws.onopen do
66
84
  begin
67
85
  ws.send "!!ver:#{options[:api_version]}"
68
86
  @web_sockets << ws
69
- puts "Browser connected."
87
+ logger.debug "== LiveReload browser connected"
70
88
  rescue
71
89
  $stderr.puts $!
72
90
  $stderr.puts $!.backtrace
@@ -74,12 +92,12 @@ module Middleman
74
92
  end
75
93
 
76
94
  ws.onmessage do |msg|
77
- puts "Browser URL: #{msg}"
95
+ logger.debug "LiveReload Browser URL: #{msg}"
78
96
  end
79
97
 
80
98
  ws.onclose do
81
99
  @web_sockets.delete ws
82
- puts "Browser disconnected."
100
+ logger.debug "== LiveReload browser disconnected"
83
101
  end
84
102
  end
85
103
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module LiveReload
3
- VERSION = "3.0.0"
3
+ VERSION = "3.0.1"
4
4
  end
5
5
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Thomas Reynolds"]
10
10
  s.email = ["me@tdreyno.com"]
11
- s.homepage = "https://github.com/tdreyno/middleman-livereload"
11
+ s.homepage = "https://github.com/middleman/middleman-livereload"
12
12
  s.summary = %q{Adds LiveReload to Middleman}
13
13
  s.description = %q{Adds LiveReload to Middleman}
14
14
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency("middleman-core", ["~> 3.0.0"])
21
+ s.add_dependency("middleman-core", ["~> 3.0.2"])
22
22
  s.add_runtime_dependency('rack-livereload')
23
23
  s.add_runtime_dependency('em-websocket', ['>= 0.2.0'])
24
24
  s.add_runtime_dependency('multi_json', ['~> 1.0'])
metadata CHANGED
@@ -1,85 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: middleman-livereload
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 3
7
- - 0
8
- - 0
9
- version: 3.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Thomas Reynolds
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-08-09 00:00:00 -07:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :runtime
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- segments:
27
- - 3
28
- - 0
29
- - 0
30
- version: 3.0.0
12
+ date: 2012-12-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
31
15
  name: middleman-core
32
- requirement: *id001
33
- prerelease: false
34
- - !ruby/object:Gem::Dependency
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.2
35
22
  type: :runtime
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- version: "0"
43
- name: rack-livereload
44
- requirement: *id002
45
23
  prerelease: false
46
- - !ruby/object:Gem::Dependency
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: rack-livereload
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
47
38
  type: :runtime
48
- version_requirements: &id003 !ruby/object:Gem::Requirement
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
- - 2
55
- - 0
56
- version: 0.2.0
57
- name: em-websocket
58
- requirement: *id003
59
39
  prerelease: false
60
- - !ruby/object:Gem::Dependency
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: em-websocket
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.0
61
54
  type: :runtime
62
- version_requirements: &id004 !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ~>
65
- - !ruby/object:Gem::Version
66
- segments:
67
- - 1
68
- - 0
69
- version: "1.0"
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.0
62
+ - !ruby/object:Gem::Dependency
70
63
  name: multi_json
71
- requirement: *id004
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
70
+ type: :runtime
72
71
  prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.0'
73
78
  description: Adds LiveReload to Middleman
74
- email:
79
+ email:
75
80
  - me@tdreyno.com
76
81
  executables: []
77
-
78
82
  extensions: []
79
-
80
83
  extra_rdoc_files: []
81
-
82
- files:
84
+ files:
83
85
  - .gitignore
84
86
  - Gemfile
85
87
  - README.md
@@ -91,36 +93,37 @@ files:
91
93
  - lib/middleman-livereload/version.rb
92
94
  - lib/middleman_extension.rb
93
95
  - middleman-livereload.gemspec
94
- has_rdoc: true
95
- homepage: https://github.com/tdreyno/middleman-livereload
96
+ homepage: https://github.com/middleman/middleman-livereload
96
97
  licenses: []
97
-
98
98
  post_install_message:
99
99
  rdoc_options: []
100
-
101
- require_paths:
100
+ require_paths:
102
101
  - lib
103
- required_ruby_version: !ruby/object:Gem::Requirement
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- segments:
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
108
109
  - 0
109
- version: "0"
110
- required_rubygems_version: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- segments:
110
+ hash: -4276955731458512067
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ segments:
115
118
  - 0
116
- version: "0"
119
+ hash: -4276955731458512067
117
120
  requirements: []
118
-
119
121
  rubyforge_project: middleman-livereload
120
- rubygems_version: 1.3.6
122
+ rubygems_version: 1.8.24
121
123
  signing_key:
122
124
  specification_version: 3
123
125
  summary: Adds LiveReload to Middleman
124
- test_files:
126
+ test_files:
125
127
  - features/.gitkeep
126
128
  - fixtures/.gitkeep
129
+ has_rdoc: