middleman-livereload 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg/*
5
5
  .rvmrc
6
6
  .DS_Store
7
7
  .rbenv-version
8
+ .ruby-version
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
- git "git://github.com/middleman/middleman.git", :branch => "3.0-stable" do
3
+ git "git://github.com/middleman/middleman.git", :branch => "master" do
4
4
  # gem "middleman"
5
5
  gem "middleman-core"
6
6
  # gem "middleman-more"
data/README.md CHANGED
@@ -12,12 +12,39 @@ middleman init MY_PROJECT
12
12
  ```
13
13
 
14
14
  If you already have a Middleman project:
15
- Add `middleman-livereload` to your `Gemfile`, and open your `config.rb` and add:
15
+ Add `middleman-livereload` to your `Gemfile`
16
+ ```
17
+ gem "middleman-livereload", "~>3.0.1"
18
+ ```
16
19
 
20
+ Then open your `config.rb` and add:
17
21
  ```
18
22
  activate :livereload
19
23
  ```
20
24
 
25
+ # Configuration
26
+
27
+ The extension supports a number of options that can be given to the `activate` statement. E.g.:
28
+ ```
29
+ activate :livereload, :apply_js_live => false, :grace_period => 0.5
30
+ ```
31
+
32
+ ## :api_version
33
+
34
+ Livereload API version, default `'1.6'`.
35
+
36
+ ## :host and :port
37
+
38
+ Livereload's listener host/port, these options get passed to ::Rack::LiveReload middleware. Defaults:`'0.0.0.0'` and `'35729'`.
39
+
40
+ ## :apply_js_live and :apply_css_live
41
+
42
+ Whether live reload should attempt to reload javascript / css 'in-place', without complete reload of the page. Both default to `true`.
43
+
44
+ ## :grace_period
45
+
46
+ A delay middleman-livereload should wait before reacting on file change / deletion notification (sec). Default is 0.
47
+
21
48
  # Community
22
49
 
23
50
  The official community forum is available at:
@@ -34,4 +61,4 @@ The best way to get quick responses to your issues and swift fixes to your bugs
34
61
 
35
62
  # Donate
36
63
 
37
- [![Click here to lend your support to Middleman](https://www.pledgie.com/campaigns/15807.png)](http://www.pledgie.com/campaigns/15807)
64
+ [![Click here to lend your support to Middleman](https://www.pledgie.com/campaigns/15807.png)](http://www.pledgie.com/campaigns/15807)
@@ -2,6 +2,11 @@ require "middleman-core"
2
2
  require "middleman-livereload/version"
3
3
 
4
4
  ::Middleman::Extensions.register(:livereload) do
5
- require "middleman-livereload/extension"
6
- ::Middleman::LiveReload
7
- end
5
+ if defined?(::Middleman::Extension)
6
+ require "middleman-livereload/extension_3_1"
7
+ ::Middleman::LiveReloadExtension
8
+ else
9
+ require "middleman-livereload/extension_3_0"
10
+ ::Middleman::LiveReload
11
+ end
12
+ end
@@ -0,0 +1,59 @@
1
+ require 'rack/livereload'
2
+ require 'middleman-livereload/reactor'
3
+
4
+ module Middleman
5
+ module LiveReload
6
+ class << self
7
+ @@reactor = nil
8
+
9
+ def registered(app, options={})
10
+ options = {
11
+ :api_version => '1.6',
12
+ :host => '0.0.0.0',
13
+ :port => '35729',
14
+ :apply_js_live => true,
15
+ :apply_css_live => true,
16
+ :grace_period => 0
17
+ }.merge(options)
18
+
19
+ app.ready do
20
+ # Doesn't make sense in build
21
+ if environment != :build
22
+ if @@reactor
23
+ @@reactor.app = self
24
+ else
25
+ @@reactor = Reactor.new(options, self)
26
+ end
27
+
28
+ files.changed do |file|
29
+ next if ignore_manager.ignored?(file)
30
+
31
+ sleep options[:grace_period]
32
+ sitemap.ensure_resource_list_updated!
33
+
34
+ begin
35
+ file_url = sitemap.file_to_path(file)
36
+ file_resource = sitemap.find_resource_by_path(file_url)
37
+ reload_path = file_resource.destination_path
38
+ rescue
39
+ reload_path = "#{Dir.pwd}/#{file}"
40
+ end
41
+ @@reactor.reload_browser(reload_path)
42
+ end
43
+
44
+ files.deleted do |file|
45
+ next if ignore_manager.ignored?(file)
46
+
47
+ sleep options[:grace_period]
48
+ sitemap.ensure_resource_list_updated!
49
+ @@reactor.reload_browser("#{Dir.pwd}/#{file}")
50
+ end
51
+
52
+ use ::Rack::LiveReload, :port => options[:port].to_i, :host => options[:host]
53
+ end
54
+ end
55
+ end
56
+ alias :included :registered
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,63 @@
1
+ require 'rack/livereload'
2
+ require 'middleman-livereload/reactor'
3
+
4
+ module Middleman
5
+ class LiveReloadExtension < Extension
6
+ option :host, '0.0.0.0', 'Host to bind LiveReload API server to'
7
+ option :port, '35729', 'Port to bind the LiveReload API server to'
8
+ option :apply_js_live, true, 'Apply JS changes live, without reloading'
9
+ option :apply_css_live, true, 'Apply CSS changes live, without reloading'
10
+ option :grace_period, 0, 'Time (in seconds) to wait before reloading'
11
+
12
+ def initialize(app, options_hash={}, &block)
13
+ super
14
+
15
+ # Doesn't make sense in build
16
+ return if app.environment == :build
17
+
18
+ @reactor = nil
19
+
20
+ grace_period = options.grace_period
21
+ port = options.port.to_i
22
+ host = options.host
23
+ options_hash = options.to_h
24
+
25
+ app.ready do
26
+ if @reactor
27
+ @reactor.app = self
28
+ else
29
+ @reactor = ::Middleman::LiveReload::Reactor.new(options_hash, self)
30
+ end
31
+
32
+ files.changed do |file|
33
+ next if ignore_manager.ignored?(file)
34
+
35
+ sleep(grace_period) if grace_period > 0
36
+ sitemap.ensure_resource_list_updated!
37
+ puts "Changed! #{file}"
38
+
39
+ begin
40
+ file_url = sitemap.file_to_path(file)
41
+ file_resource = sitemap.find_resource_by_path(file_url)
42
+ reload_path = file_resource.destination_path
43
+ rescue
44
+ reload_path = "#{Dir.pwd}/#{file}"
45
+ end
46
+ @reactor.reload_browser(reload_path)
47
+ end
48
+
49
+ files.deleted do |file|
50
+ next if ignore_manager.ignored?(file)
51
+
52
+ sleep(grace_period) if grace_period > 0
53
+ sitemap.ensure_resource_list_updated!
54
+ puts "Deleted! #{file}"
55
+
56
+ @reactor.reload_browser("#{Dir.pwd}/#{file}")
57
+ end
58
+
59
+ use ::Rack::LiveReload, :port => port, :host => host
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,55 +1,11 @@
1
- require 'rack/livereload'
2
1
  require 'em-websocket'
3
2
  require 'multi_json'
4
3
 
5
4
  module Middleman
6
5
  module LiveReload
7
- class << self
8
- def registered(app, options={})
9
- options = {
10
- :api_version => '1.6',
11
- :host => '0.0.0.0',
12
- :port => '35729',
13
- :apply_js_live => true,
14
- :apply_css_live => true,
15
- :grace_period => 0
16
- }.merge(options)
17
-
18
- app.ready do
19
- # Doesn't make sense in build
20
- if environment != :build
21
- reactor = Reactor.new(options, self)
22
-
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
41
-
42
- use ::Rack::LiveReload, :port => options[:port].to_i, :host => options[:host]
43
- end
44
- end
45
- end
46
- alias :included :registered
47
- end
48
-
49
6
  class Reactor
50
7
  attr_reader :thread, :web_sockets, :app
51
- delegate :logger, :to => :app
52
-
8
+
53
9
  def initialize(options, app)
54
10
  @app = app
55
11
  @web_sockets = []
@@ -57,6 +13,14 @@ module Middleman
57
13
  @thread = start_threaded_reactor(options)
58
14
  end
59
15
 
16
+ def app= app
17
+ Thread.exclusive { @app = app }
18
+ end
19
+
20
+ def logger
21
+ Thread.exclusive { @app.logger }
22
+ end
23
+
60
24
  def stop
61
25
  thread.kill
62
26
  end
@@ -70,7 +34,7 @@ module Middleman
70
34
  :apply_js_live => @options[:apply_js_live],
71
35
  :apply_css_live => @options[:apply_css_live]
72
36
  }])
73
-
37
+
74
38
  @web_sockets.each { |ws| ws.send(data) }
75
39
  end
76
40
  end
@@ -82,7 +46,7 @@ module Middleman
82
46
  EventMachine.start_server(options[:host], options[:port], EventMachine::WebSocket::Connection, {}) do |ws|
83
47
  ws.onopen do
84
48
  begin
85
- ws.send "!!ver:#{options[:api_version]}"
49
+ ws.send "!!ver:1.6"
86
50
  @web_sockets << ws
87
51
  logger.debug "== LiveReload browser connected"
88
52
  rescue
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module LiveReload
3
- VERSION = "3.0.1"
3
+ VERSION = "3.1.0"
4
4
  end
5
5
  end
@@ -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.2"])
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-livereload
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,14 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-19 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 3.0.2
22
22
  type: :runtime
@@ -24,7 +24,7 @@ dependencies:
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.0.2
30
30
  - !ruby/object:Gem::Dependency
@@ -89,7 +89,9 @@ files:
89
89
  - features/.gitkeep
90
90
  - fixtures/.gitkeep
91
91
  - lib/middleman-livereload.rb
92
- - lib/middleman-livereload/extension.rb
92
+ - lib/middleman-livereload/extension_3_0.rb
93
+ - lib/middleman-livereload/extension_3_1.rb
94
+ - lib/middleman-livereload/reactor.rb
93
95
  - lib/middleman-livereload/version.rb
94
96
  - lib/middleman_extension.rb
95
97
  - middleman-livereload.gemspec
@@ -107,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
109
  version: '0'
108
110
  segments:
109
111
  - 0
110
- hash: -4276955731458512067
112
+ hash: -1556732277774144508
111
113
  required_rubygems_version: !ruby/object:Gem::Requirement
112
114
  none: false
113
115
  requirements:
@@ -116,10 +118,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  version: '0'
117
119
  segments:
118
120
  - 0
119
- hash: -4276955731458512067
121
+ hash: -1556732277774144508
120
122
  requirements: []
121
123
  rubyforge_project: middleman-livereload
122
- rubygems_version: 1.8.24
124
+ rubygems_version: 1.8.23
123
125
  signing_key:
124
126
  specification_version: 3
125
127
  summary: Adds LiveReload to Middleman