middleman-livereload 0.2.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,23 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
- # Specify your gem's dependencies in middleman-livereload.gemspec
3
+ git "git://github.com/middleman/middleman.git" do
4
+ # gem "middleman"
5
+ gem "middleman-core"
6
+ # gem "middleman-more"
7
+ end
8
+
9
+ # Specify your gem's dependencies in middleman-blog.gemspec
4
10
  gemspec
11
+
12
+ group :development do
13
+ gem "rake", "~> 0.9.2"
14
+ gem "rdoc", "~> 3.9"
15
+ gem "yard", "~> 0.8.0"
16
+ end
17
+
18
+ group :test do
19
+ gem "cucumber", "~> 1.2.0"
20
+ gem "fivemat"
21
+ gem "aruba", "~> 0.4.11"
22
+ gem "rspec", "~> 2.7"
23
+ end
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # middleman-livereload
2
+
3
+ middleman-livereload is an extension for the [Middleman](http://middlemanapp.com) static site generator that adds livereloading functionality.
4
+
5
+ # Install
6
+ If you're just getting started, install the `middleman` and `middleman-livereload` gems and generate a new project:
7
+
8
+ ```
9
+ gem install middleman
10
+ gem install middleman-livereload
11
+ middleman init MY_PROJECT
12
+ ```
13
+
14
+ If you already have a Middleman project:
15
+ Add `middleman-livereload` to your `Gemfile`, and open your `config.rb` and add:
16
+
17
+ ```
18
+ activate :livereload
19
+ ```
20
+
21
+ # Community
22
+
23
+ The official community forum is available at:
24
+
25
+ http://forum.middlemanapp.com/
26
+
27
+ # Bug Reports
28
+
29
+ GitHub Issues are used for managing bug reports and feature requests. If you run into issues, please search the issues and submit new problems:
30
+
31
+ https://github.com/middleman/middleman-livereload/issues
32
+
33
+ The best way to get quick responses to your issues and swift fixes to your bugs is to submit detailed bug reports, include test cases and respond to developer questions in a timely manner. Even better, if you know Ruby, you can submit Pull Requests containing Cucumber Features which describe how your feature should work or exploit the bug you are submitting.
34
+
35
+ # Donate
36
+
37
+ [![Click here to lend your support to Middleman](https://www.pledgie.com/campaigns/15807.png)](http://www.pledgie.com/campaigns/15807)
data/Rakefile CHANGED
@@ -1,2 +1,22 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ ENV["TEST"] = "true"
8
+
9
+ exempt_tags = ""
10
+ exempt_tags << "--tags ~@nojava" if RUBY_PLATFORM == "java"
11
+
12
+ t.cucumber_opts = "--color --tags ~@wip #{exempt_tags} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
13
+ end
14
+
15
+ require 'rake/clean'
16
+
17
+ task :test => ["cucumber"]
18
+
19
+ desc "Build HTML documentation"
20
+ task :doc do
21
+ sh 'bundle exec yard'
22
+ end
data/features/.gitkeep ADDED
File without changes
data/fixtures/.gitkeep ADDED
File without changes
@@ -1,21 +1,7 @@
1
- require "middleman/guard"
2
- require "guard/livereload"
3
-
4
- Middleman::Guard.add_guard do |options, livereload|
5
- if livereload
6
- livereload_options_hash = ""
7
-
8
- livereload.each do |k,v|
9
- livereload_options_hash << ", :#{k} => "
10
- livereload_options_hash << ((v.kind_of?(String)) ? "'#{v}'" : "#{v.to_s}")
11
- end
12
-
13
- %Q{
14
- guard 'livereload'#{livereload_options_hash} do
15
- watch(%r{^source/([^\.].*)$})
16
- end
17
- }
18
- else
19
- nil
20
- end
1
+ require "middleman-core"
2
+ require "middleman-livereload/version"
3
+
4
+ ::Middleman::Extensions.register(:livereload) do
5
+ require "middleman-livereload/extension"
6
+ ::Middleman::LiveReload
21
7
  end
@@ -0,0 +1,90 @@
1
+ require 'rack/livereload'
2
+ require 'em-websocket'
3
+ require 'multi_json'
4
+
5
+ module Middleman
6
+ 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)
22
+
23
+ files.changed { |file| reactor.reload_browser(file) }
24
+ files.deleted { |file| reactor.reload_browser(file) }
25
+
26
+ use ::Rack::LiveReload
27
+ end
28
+ end
29
+ end
30
+ alias :included :registered
31
+ end
32
+
33
+ class Reactor
34
+ attr_reader :thread, :web_sockets
35
+
36
+ def initialize(options)
37
+ @web_sockets = []
38
+ @options = options
39
+ @thread = start_threaded_reactor(options)
40
+ end
41
+
42
+ def stop
43
+ thread.kill
44
+ end
45
+
46
+ def reload_browser(paths = [])
47
+ paths = Array(paths)
48
+ puts "Reloading browser: #{paths.join(' ')}"
49
+ paths.each do |path|
50
+ data = MultiJson.encode(['refresh', {
51
+ :path => "#{Dir.pwd}/#{path}",
52
+ :apply_js_live => @options[:apply_js_live],
53
+ :apply_css_live => @options[:apply_css_live]
54
+ }])
55
+ # UI.debug data
56
+ @web_sockets.each { |ws| ws.send(data) }
57
+ end
58
+ end
59
+
60
+ def start_threaded_reactor(options)
61
+ Thread.new do
62
+ EventMachine.run do
63
+ puts "LiveReload #{options[:api_version]} is waiting for a browser to connect."
64
+ EventMachine.start_server(options[:host], options[:port], EventMachine::WebSocket::Connection, {}) do |ws|
65
+ ws.onopen do
66
+ begin
67
+ ws.send "!!ver:#{options[:api_version]}"
68
+ @web_sockets << ws
69
+ puts "Browser connected."
70
+ rescue
71
+ $stderr.puts $!
72
+ $stderr.puts $!.backtrace
73
+ end
74
+ end
75
+
76
+ ws.onmessage do |msg|
77
+ puts "Browser URL: #{msg}"
78
+ end
79
+
80
+ ws.onclose do
81
+ @web_sockets.delete ws
82
+ puts "Browser disconnected."
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module LiveReload
3
- VERSION = "0.2.2"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
File without changes
@@ -14,12 +14,12 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "middleman-livereload"
16
16
 
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.files = `git ls-files -z`.split("\0")
18
+ s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
20
19
  s.require_paths = ["lib"]
21
20
 
22
- # s.add_runtime_dependency("middleman", ["~> 2.0.6"])
23
- s.add_runtime_dependency("guard-livereload", ["~> 1.0"])
24
- s.add_development_dependency("rake")
21
+ s.add_dependency("middleman-core", ["~> 3.0.0"])
22
+ s.add_runtime_dependency('rack-livereload')
23
+ s.add_runtime_dependency('em-websocket', ['>= 0.2.0'])
24
+ s.add_runtime_dependency('multi_json', ['~> 1.0'])
25
25
  end
metadata CHANGED
@@ -1,80 +1,126 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: middleman-livereload
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 3
7
+ - 0
8
+ - 0
9
+ version: 3.0.0
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Thomas Reynolds
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-06-23 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: guard-livereload
16
- requirement: &70148725068240 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
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:
19
24
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '1.0'
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 3
28
+ - 0
29
+ - 0
30
+ version: 3.0.0
31
+ name: middleman-core
32
+ requirement: *id001
33
+ prerelease: false
34
+ - !ruby/object:Gem::Dependency
22
35
  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
23
45
  prerelease: false
24
- version_requirements: *70148725068240
25
- - !ruby/object:Gem::Dependency
26
- name: rake
27
- requirement: &70148725067820 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ 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
+ prerelease: false
60
+ - !ruby/object:Gem::Dependency
61
+ 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"
70
+ name: multi_json
71
+ requirement: *id004
34
72
  prerelease: false
35
- version_requirements: *70148725067820
36
73
  description: Adds LiveReload to Middleman
37
- email:
74
+ email:
38
75
  - me@tdreyno.com
39
76
  executables: []
77
+
40
78
  extensions: []
79
+
41
80
  extra_rdoc_files: []
42
- files:
81
+
82
+ files:
43
83
  - .gitignore
44
84
  - Gemfile
85
+ - README.md
45
86
  - Rakefile
87
+ - features/.gitkeep
88
+ - fixtures/.gitkeep
46
89
  - lib/middleman-livereload.rb
90
+ - lib/middleman-livereload/extension.rb
47
91
  - lib/middleman-livereload/version.rb
48
- - lib/middleman_init.rb
92
+ - lib/middleman_extension.rb
49
93
  - middleman-livereload.gemspec
94
+ has_rdoc: true
50
95
  homepage: https://github.com/tdreyno/middleman-livereload
51
96
  licenses: []
97
+
52
98
  post_install_message:
53
99
  rdoc_options: []
54
- require_paths:
100
+
101
+ require_paths:
55
102
  - lib
56
- required_ruby_version: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- segments:
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
63
108
  - 0
64
- hash: -3112455916319069585
65
- required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- segments:
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ segments:
72
115
  - 0
73
- hash: -3112455916319069585
116
+ version: "0"
74
117
  requirements: []
118
+
75
119
  rubyforge_project: middleman-livereload
76
- rubygems_version: 1.8.10
120
+ rubygems_version: 1.3.6
77
121
  signing_key:
78
122
  specification_version: 3
79
123
  summary: Adds LiveReload to Middleman
80
- test_files: []
124
+ test_files:
125
+ - features/.gitkeep
126
+ - fixtures/.gitkeep