livereload 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/livereload +9 -0
  2. data/lib/livereload.rb +33 -0
  3. metadata +89 -0
data/bin/livereload ADDED
@@ -0,0 +1,9 @@
1
+ #! /usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'livereload'
4
+
5
+ dir = File.expand_path('.')
6
+ exts = "html,css,js,png,gif,jpg,php,py,rb"
7
+ host = "0.0.0.0"
8
+ port = 10083
9
+ LiveReload.run host, port, dir, exts
data/lib/livereload.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'em-websocket'
2
+ require 'directory_watcher'
3
+
4
+ module LiveReload
5
+ def self.run(host, port, dir, exts)
6
+ EM.kqueue = true
7
+ $dw = DirectoryWatcher.new dir, :glob => "**/*.{#{exts}}", :scanner => :em
8
+
9
+ def start_watching ws
10
+ $dw.add_observer { |*args|
11
+ args.each { |event|
12
+ if event[:type] == :modified
13
+ name = File.basename(event[:path])
14
+ puts "Modified: #{name}"
15
+ ws.send name
16
+ end
17
+ }
18
+ }
19
+ $dw.start
20
+ end
21
+
22
+ puts
23
+ puts "Port: #{port}"
24
+ puts "Directory: #{dir}"
25
+ puts "Extensions: " + exts.split(",").collect {|e| ".#{e}"}.join(" ")
26
+ puts "LiveReload is waiting for browser to connect."
27
+ EventMachine::WebSocket.start(:host => host, :port => port, :debug => false) do |ws|
28
+ ws.onopen { puts "Browser connected."; start_watching ws }
29
+ ws.onmessage { |msg| puts "Browser URL: #{msg}" }
30
+ ws.onclose { puts "Browser disconnected." }
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: livereload
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - Andrey Tarantsov
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-07-11 00:00:00 +07:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: em-websocket
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ - 1
29
+ - 2
30
+ version: 0.1.2
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: directory_watcher
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 3
43
+ - 2
44
+ version: 1.3.2
45
+ type: :runtime
46
+ version_requirements: *id002
47
+ description: A command-line server for the LiveReload Safari extension
48
+ email: andreyvit@gmail.com
49
+ executables:
50
+ - livereload
51
+ extensions: []
52
+
53
+ extra_rdoc_files: []
54
+
55
+ files:
56
+ - bin/livereload
57
+ - lib/livereload.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/mockko/livereload/
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements:
82
+ - LiveReload Safari extension
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.6
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A command-line server for the LiveReload Safari extension
88
+ test_files: []
89
+