wunderbar 0.10.3 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/wunderbar/builder.rb +29 -3
- data/lib/wunderbar/environment.rb +4 -0
- data/lib/wunderbar/html-methods.rb +17 -15
- data/lib/wunderbar/server.rb +49 -45
- data/lib/wunderbar/version.rb +1 -1
- data/wunderbar.gemspec +3 -3
- metadata +39 -62
data/lib/wunderbar/builder.rb
CHANGED
@@ -6,9 +6,11 @@ module Wunderbar
|
|
6
6
|
indented_data!(text) {|data| text! data}
|
7
7
|
end
|
8
8
|
|
9
|
-
def indented_data!(data, &block)
|
9
|
+
def indented_data!(data, pre=nil, post=nil, &block)
|
10
10
|
return if data.strip.length == 0
|
11
11
|
|
12
|
+
self << pre + target!.pop if pre
|
13
|
+
|
12
14
|
if @indent > 0
|
13
15
|
data.sub! /\n\s*\Z/, ''
|
14
16
|
data.sub! /\A\s*\n/, ''
|
@@ -31,6 +33,8 @@ module Wunderbar
|
|
31
33
|
end
|
32
34
|
|
33
35
|
_newline unless data =~ /\n\Z/
|
36
|
+
|
37
|
+
self << post if post
|
34
38
|
end
|
35
39
|
|
36
40
|
def disable_indendation!(&block)
|
@@ -189,8 +193,30 @@ module Wunderbar
|
|
189
193
|
|
190
194
|
# insert verbatim
|
191
195
|
def <<(string)
|
192
|
-
|
193
|
-
|
196
|
+
if not String === string or string.include? '<' or string.include? '&'
|
197
|
+
require 'nokogiri'
|
198
|
+
string = Nokogiri::HTML::fragment(string.to_s).to_xml
|
199
|
+
end
|
200
|
+
|
201
|
+
# fix CDATA in most cases (notably scripts)
|
202
|
+
string.gsub!(/<!\[CDATA\[(.*?)\]\]>/m) do |cdata|
|
203
|
+
if $1.include? '<' or $1.include? '&'
|
204
|
+
"//<![CDATA[\n#{$1}\n//]]>"
|
205
|
+
else
|
206
|
+
$1
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# fix CDATA for style elements
|
211
|
+
string.gsub!(/<style>\/\/<!\[CDATA\[\n(.*?)\s+\/\/\]\]>/m) do |cdata|
|
212
|
+
if $1.include? '<' or $1.include? '&'
|
213
|
+
"<style>/*<![CDATA[*/\n#{$1.gsub("\n\Z",'')}\n/*]]>*/"
|
214
|
+
else
|
215
|
+
$1
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
@_builder << string.to_s
|
194
220
|
rescue LoadError
|
195
221
|
@_builder << string
|
196
222
|
end
|
@@ -62,10 +62,18 @@ class HtmlMarkup < Wunderbar::BuilderBase
|
|
62
62
|
if %w(script style).include?(name)
|
63
63
|
if String === args.first and not block
|
64
64
|
text = args.shift
|
65
|
-
if
|
66
|
-
block = Proc.new
|
65
|
+
if !text.include? '&' and !text.include? '<'
|
66
|
+
block = Proc.new do
|
67
|
+
@x.indented_data!(text)
|
68
|
+
end
|
69
|
+
elsif name == 'style'
|
70
|
+
block = Proc.new do
|
71
|
+
@x.indented_data!(text, "/*<![CDATA[*/", "/*]]>*/")
|
72
|
+
end
|
67
73
|
else
|
68
|
-
block = Proc.new
|
74
|
+
block = Proc.new do
|
75
|
+
@x.indented_data!(text, "//<![CDATA[", "//]]>")
|
76
|
+
end
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
@@ -106,20 +114,14 @@ class HtmlMarkup < Wunderbar::BuilderBase
|
|
106
114
|
end
|
107
115
|
end
|
108
116
|
else
|
109
|
-
@x.tag! name, *args, &block
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
STDERR.puts @xhtml
|
115
|
-
if @xhtml
|
116
|
-
begin
|
117
|
-
require 'nokogiri'
|
118
|
-
string = Nokogiri::HTML::fragment(string).to_xml
|
119
|
-
rescue LoadError
|
117
|
+
target = @x.tag! name, *args, &block
|
118
|
+
if block and %w(script style).include?(name)
|
119
|
+
if %w{//]]> /*]]>*/}.include? target[-4]
|
120
|
+
target[-4], target[-3] = target[-3], target[-4]
|
121
|
+
end
|
120
122
|
end
|
123
|
+
target
|
121
124
|
end
|
122
|
-
super(string)
|
123
125
|
end
|
124
126
|
|
125
127
|
def _exception(*args)
|
data/lib/wunderbar/server.rb
CHANGED
@@ -12,70 +12,74 @@ module Wunderbar
|
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
port = $1.to_i
|
15
|
+
port = ARGV.find {|arg| arg =~ /--port=(.*)/}
|
16
|
+
if port and ARGV.delete(port)
|
17
|
+
port = $1.to_i
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
# Evaluate optional data from the script (after __END__)
|
20
|
+
eval Wunderbar.data if Object.const_defined? :DATA
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
# Allow optional environment override
|
23
|
+
environment = ARGV.find {|arg| arg =~ /--environment=(.*)/}
|
24
|
+
ENV['RACK_ENV'] = environment if environment and ARGV.delete(environment)
|
26
25
|
|
26
|
+
at_exit do
|
27
27
|
# start the server
|
28
28
|
require 'rack'
|
29
29
|
require 'wunderbar/rack'
|
30
30
|
Rack::Server.start :app => Wunderbar::RackApp.new, :Port => port,
|
31
31
|
:environment => (ENV['RACK_ENV'] || 'development')
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
+
elsif defined? Sinatra
|
34
35
|
|
35
|
-
|
36
|
+
require 'wunderbar/sinatra'
|
36
37
|
|
37
|
-
|
38
|
+
else
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
require 'etc'
|
41
|
+
$USER = ENV['REMOTE_USER'] ||= ENV['USER'] || Etc.getlogin
|
42
|
+
if $USER.nil?
|
43
|
+
if RUBY_PLATFORM =~ /darwin/i
|
44
|
+
$USER = `dscl . -search /Users UniqueID #{Process.uid}`.split.first
|
45
|
+
elsif RUBY_PLATFORM =~ /linux/i
|
46
|
+
$USER = `getent passwd #{Process.uid}`.split(':').first
|
47
|
+
end
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
class << cgi
|
46
|
-
attr_accessor :env
|
49
|
+
ENV['USER'] ||= $USER
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
ENV['HOME'] ||= Dir.home($USER) rescue nil
|
53
|
+
ENV['HOME'] = ENV['DOCUMENT_ROOT'] if not File.exist? ENV['HOME'].to_s
|
54
|
+
|
55
|
+
at_exit do
|
56
|
+
if Wunderbar.queue.length > 0
|
57
|
+
# Only prompt if explicitly asked for
|
58
|
+
ARGV.push '' if ARGV.empty?
|
59
|
+
ARGV.delete('--prompt') or ARGV.delete('--offline')
|
60
|
+
|
61
|
+
cgi = CGI.new
|
62
|
+
cgi.instance_variable_set '@env', ENV
|
63
|
+
class << cgi
|
64
|
+
attr_accessor :env
|
65
|
+
|
66
|
+
# was this invoked via HTTP POST?
|
67
|
+
%w(delete get head options post put trace).each do |http_method|
|
68
|
+
define_method "#{http_method}?" do
|
69
|
+
env['REQUEST_METHOD'].to_s.downcase == http_method
|
70
|
+
end
|
52
71
|
end
|
53
72
|
end
|
54
|
-
end
|
55
73
|
|
56
|
-
|
57
|
-
|
74
|
+
# get arguments if CGI couldn't find any...
|
75
|
+
cgi.params.merge!(CGI.parse(ARGV.join('&'))) if cgi.params.empty?
|
58
76
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
if RUBY_PLATFORM =~ /darwin/i
|
63
|
-
$USER = `dscl . -search /Users UniqueID #{Process.uid}`.split.first
|
64
|
-
elsif RUBY_PLATFORM =~ /linux/i
|
65
|
-
$USER = `getent passwd #{Process.uid}`.split(':').first
|
66
|
-
end
|
77
|
+
# allow the REQUEST_METHOD to be set for command line invocations
|
78
|
+
ENV['REQUEST_METHOD'] ||= 'POST' if ARGV.delete('--post')
|
79
|
+
ENV['REQUEST_METHOD'] ||= 'GET' if ARGV.delete('--get')
|
67
80
|
|
68
|
-
|
81
|
+
# CGI or command line
|
82
|
+
Wunderbar::CGI.call(cgi)
|
69
83
|
end
|
70
|
-
|
71
|
-
ENV['HOME'] ||= Dir.home($USER) rescue nil
|
72
|
-
ENV['HOME'] = ENV['DOCUMENT_ROOT'] if not File.exist? ENV['HOME'].to_s
|
73
|
-
|
74
|
-
# allow the REQUEST_METHOD to be set for command line invocations
|
75
|
-
ENV['REQUEST_METHOD'] ||= 'POST' if ARGV.delete('--post')
|
76
|
-
ENV['REQUEST_METHOD'] ||= 'GET' if ARGV.delete('--get')
|
77
|
-
|
78
|
-
# CGI or command line
|
79
|
-
Wunderbar::CGI.call(cgi)
|
80
84
|
end
|
81
85
|
end
|
data/lib/wunderbar/version.rb
CHANGED
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.10.
|
5
|
+
s.version = "0.10.4"
|
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-
|
9
|
+
s.date = "2012-04-15"
|
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
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/sinatra.rb", "lib/wunderbar/environment.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.
|
15
|
+
s.rubygems_version = "1.8.15"
|
16
16
|
s.summary = "HTML Generator and CGI application support"
|
17
17
|
|
18
18
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,60 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: wunderbar
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 10
|
9
|
-
- 3
|
10
|
-
version: 0.10.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Sam Ruby
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-04-15 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: builder
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &13584540 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 3
|
31
|
-
- 0
|
32
|
-
version: "3.0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: json
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: *13584540
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
requirement: &13583500 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
47
33
|
type: :runtime
|
48
|
-
|
49
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *13583500
|
36
|
+
description: ! " Wunderbar makes it easy to produce valid HTML5, wellformed XHTML,
|
37
|
+
Unicode\n (utf-8), consistently indented, readable applications. This includes\n
|
38
|
+
\ output that conforms to the Polyglot specification and the emerging\n results
|
39
|
+
from the XML Error Recovery Community Group.\n"
|
50
40
|
email: rubys@intertwingly.net
|
51
41
|
executables: []
|
52
|
-
|
53
42
|
extensions: []
|
54
|
-
|
55
43
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
44
|
+
files:
|
58
45
|
- wunderbar.gemspec
|
59
46
|
- README.md
|
60
47
|
- COPYING
|
@@ -73,36 +60,26 @@ files:
|
|
73
60
|
- lib/wunderbar/version.rb
|
74
61
|
homepage: http://github.com/rubys/wunderbar
|
75
62
|
licenses: []
|
76
|
-
|
77
63
|
post_install_message:
|
78
64
|
rdoc_options: []
|
79
|
-
|
80
|
-
require_paths:
|
65
|
+
require_paths:
|
81
66
|
- lib
|
82
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
68
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
|
89
|
-
- 0
|
90
|
-
version: "0"
|
91
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
74
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
|
97
|
-
segments:
|
98
|
-
- 0
|
99
|
-
version: "0"
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
100
79
|
requirements: []
|
101
|
-
|
102
80
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.8.
|
81
|
+
rubygems_version: 1.8.15
|
104
82
|
signing_key:
|
105
83
|
specification_version: 3
|
106
84
|
summary: HTML Generator and CGI application support
|
107
85
|
test_files: []
|
108
|
-
|