wunderbar 0.12.3 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  # run command/block as a background daemon
2
2
  module Wunderbar
3
- def submit(cmd=nil)
3
+ def self.submit(cmd=nil)
4
4
  fork do
5
5
  # detach from tty
6
6
  Process.setsid
@@ -17,8 +17,10 @@ module Wunderbar
17
17
 
18
18
  # clear environment of cgi cruft
19
19
  require 'cgi'
20
- ENV.delete_if {|key,value| key =~ /^HTTP_/}
21
- CGI::QueryExtension.public_instance_methods.each do |method|
20
+ ENV.keys.select {|key| key =~ /^HTTP_/}.each do |key|
21
+ ENV.delete key.dup.untaint
22
+ end
23
+ ::CGI::QueryExtension.public_instance_methods.each do |method|
22
24
  ENV.delete method.to_s.upcase
23
25
  end
24
26
 
@@ -1,8 +1,8 @@
1
1
  module Wunderbar
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 12
5
- TINY = 3
4
+ MINOR = 13
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'open3'
4
+ require 'socket'
5
+
6
+ begin
7
+ require 'em-websocket'
8
+ rescue LoadError
9
+ module EM
10
+ class Channel
11
+ def initialize
12
+ require 'em-websocket'
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ module Wunderbar
19
+ class Channel < EM::Channel
20
+ attr_reader :port
21
+
22
+ def initialize(port, limit=nil)
23
+ TCPSocket.new('localhost', port).close
24
+ raise ArgumentError.new "Socket #{port} is not available"
25
+ rescue Errno::ECONNREFUSED
26
+ super()
27
+ @port = port
28
+ @memory = []
29
+ @memory_channel = subscribe do |msg|
30
+ @memory << msg.chomp unless Symbol === msg
31
+ @memory.shift while limit and @memory.length > limit
32
+ end
33
+ websocket.run
34
+ end
35
+
36
+ def websocket
37
+ @websocket ||= Thread.new do
38
+ EM::WebSocket.start(:host => '0.0.0.0', :port => @port) do |ws|
39
+ ws.onopen {@memory.each {|msg| ws.send msg }}
40
+
41
+ sid = subscribe do |msg|
42
+ if msg == :shutdown
43
+ ws.close_websocket
44
+ else
45
+ ws.send msg
46
+ end
47
+ end
48
+
49
+ ws.onclose {unsubscribe sid}
50
+ end
51
+ end
52
+ end
53
+
54
+ def _(msg=nil, &block)
55
+ return self if msg==nil
56
+ push(msg.to_json)
57
+ end
58
+
59
+ def system(command)
60
+ Open3.popen3(command) do |pin, pout, perr|
61
+ _ :type=>:stdin, :line=>command
62
+ [
63
+ Thread.new do
64
+ pout.sync=true
65
+ _ :type=>:stdout, :line=>pout.readline.chomp until pout.eof?
66
+ end,
67
+ Thread.new do
68
+ perr.sync=true
69
+ _ :type=>:stderr, :line=>perr.readline.chomp until perr.eof?
70
+ end,
71
+ Thread.new { pin.close }
72
+ ].each {|thread| thread.join}
73
+ end
74
+ end
75
+
76
+ def close
77
+ unsubscribe @memory_channel if @memory_channel
78
+ push :shutdown
79
+ sleep 1
80
+ EM::WebSocket.stop
81
+ websocket.join
82
+ end
83
+ end
84
+
85
+ if defined? EventMachine::WebSocket
86
+ def self.websocket(port=nil, &block)
87
+ if not port
88
+ socket = TCPServer.new(0)
89
+ port = Socket.unpack_sockaddr_in(socket.getsockname).first
90
+ socket.close
91
+ end
92
+
93
+ submit do
94
+ begin
95
+ channel = Wunderbar::Channel.new(port)
96
+ channel.instance_eval &block
97
+ rescue Exception => exception
98
+ channel._ :type=>:stderr, :line=>exception.inspect
99
+ exception.backtrace.each do |frame|
100
+ next if Wunderbar::CALLERS_TO_IGNORE.any? {|re| frame =~ re}
101
+ channel._ :type=>:stderr, :line=>" #{frame}"
102
+ end
103
+ ensure
104
+ channel.push :shutdown
105
+ sleep 5
106
+ channel.close if channel
107
+ end
108
+ end
109
+
110
+ sleep 1
111
+
112
+ port
113
+ end
114
+ end
115
+ end
data/lib/wunderbar.rb CHANGED
@@ -11,5 +11,6 @@ require 'wunderbar/installation'
11
11
  require 'wunderbar/job-control'
12
12
  require 'wunderbar/logger'
13
13
  require 'wunderbar/server'
14
+ require 'wunderbar/websocket'
14
15
 
15
16
  W_ = Wunderbar
data/wunderbar.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "wunderbar"
5
- s.version = "0.12.3"
5
+ s.version = "0.13.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sam Ruby"]
9
- s.date = "2012-04-25"
9
+ s.date = "2012-04-28"
10
10
  s.description = " Wunderbar makes it easy to produce valid HTML5, wellformed XHTML, Unicode\n (utf-8), consistently indented, readable applications. This includes\n output that conforms to the Polyglot specification and the emerging\n results from the XML Error Recovery Community Group.\n"
11
11
  s.email = "rubys@intertwingly.net"
12
- s.files = ["wunderbar.gemspec", "README.md", "COPYING", "lib/wunderbar.rb", "lib/wunderbar", "lib/wunderbar/version.rb", "lib/wunderbar/installation.rb", "lib/wunderbar/cssproxy.rb", "lib/wunderbar/rack.rb", "lib/wunderbar/logger.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/sinatra.rb", "lib/wunderbar/rails.rb", "lib/wunderbar/server.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/cgi-methods.rb"]
12
+ s.files = ["wunderbar.gemspec", "README.md", "COPYING", "lib/wunderbar.rb", "lib/wunderbar", "lib/wunderbar/installation.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/server.rb", "lib/wunderbar/logger.rb", "lib/wunderbar/rack.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/websocket.rb", "lib/wunderbar/sinatra.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/rails.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/cssproxy.rb", "lib/wunderbar/version.rb"]
13
13
  s.homepage = "http://github.com/rubys/wunderbar"
14
14
  s.require_paths = ["lib"]
15
- s.rubygems_version = "1.8.23"
15
+ s.rubygems_version = "1.8.21"
16
16
  s.summary = "HTML Generator and CGI application support"
17
17
 
18
18
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,96 +1,110 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wunderbar
3
- version: !ruby/object:Gem::Version
4
- version: 0.12.3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 43
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 13
9
+ - 0
10
+ version: 0.13.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Sam Ruby
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-04-28 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: builder
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '3.0'
22
- type: :runtime
23
22
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '3.0'
30
- - !ruby/object:Gem::Dependency
31
- name: json
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ version: "3.0"
38
33
  type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
39
37
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- description: ! " Wunderbar makes it easy to produce valid HTML5, wellformed XHTML,
47
- Unicode\n (utf-8), consistently indented, readable applications. This includes\n
48
- \ output that conforms to the Polyglot specification and the emerging\n results
49
- from the XML Error Recovery Community Group.\n"
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: " Wunderbar makes it easy to produce valid HTML5, wellformed XHTML, Unicode\n (utf-8), consistently indented, readable applications. This includes\n output that conforms to the Polyglot specification and the emerging\n results from the XML Error Recovery Community Group.\n"
50
50
  email: rubys@intertwingly.net
51
51
  executables: []
52
+
52
53
  extensions: []
54
+
53
55
  extra_rdoc_files: []
54
- files:
56
+
57
+ files:
55
58
  - wunderbar.gemspec
56
59
  - README.md
57
60
  - COPYING
58
61
  - lib/wunderbar.rb
59
- - lib/wunderbar/version.rb
60
62
  - lib/wunderbar/installation.rb
61
- - lib/wunderbar/cssproxy.rb
62
- - lib/wunderbar/rack.rb
63
+ - lib/wunderbar/html-methods.rb
64
+ - lib/wunderbar/job-control.rb
65
+ - lib/wunderbar/server.rb
63
66
  - lib/wunderbar/logger.rb
67
+ - lib/wunderbar/rack.rb
64
68
  - lib/wunderbar/builder.rb
69
+ - lib/wunderbar/websocket.rb
65
70
  - lib/wunderbar/sinatra.rb
66
- - lib/wunderbar/rails.rb
67
- - lib/wunderbar/server.rb
68
- - lib/wunderbar/html-methods.rb
69
- - lib/wunderbar/job-control.rb
70
71
  - lib/wunderbar/environment.rb
72
+ - lib/wunderbar/rails.rb
71
73
  - lib/wunderbar/cgi-methods.rb
74
+ - lib/wunderbar/cssproxy.rb
75
+ - lib/wunderbar/version.rb
72
76
  homepage: http://github.com/rubys/wunderbar
73
77
  licenses: []
78
+
74
79
  post_install_message:
75
80
  rdoc_options: []
76
- require_paths:
81
+
82
+ require_paths:
77
83
  - lib
78
- required_ruby_version: !ruby/object:Gem::Requirement
84
+ required_ruby_version: !ruby/object:Gem::Requirement
79
85
  none: false
80
- requirements:
81
- - - ! '>='
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
94
  none: false
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
90
102
  requirements: []
103
+
91
104
  rubyforge_project:
92
- rubygems_version: 1.8.23
105
+ rubygems_version: 1.8.21
93
106
  signing_key:
94
107
  specification_version: 3
95
108
  summary: HTML Generator and CGI application support
96
109
  test_files: []
110
+