wunderbar 0.20.2 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +16 -0
- data/lib/wunderbar/cssproxy.rb +14 -10
- data/lib/wunderbar/html-methods.rb +10 -4
- data/lib/wunderbar/jquery/filter.rb +141 -0
- data/lib/wunderbar/node.rb +23 -12
- data/lib/wunderbar/version.rb +2 -2
- data/wunderbar.gemspec +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTFhYjVkZGYwMGZmMWJkMDE3OWVhNTYzOTg0YWMwMjc0OWE0MTMzZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmJkOTM5YTQ3Yjc2MDQ5YjhmYTVjNjRhODAxOWUwYzdjZjFmNmU0MQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTZmZWMyZWRmMTc1NTc0ZTM4NDFlNjMzNzQ4YTRiNWUxMDVjNzQxZmJiMmU0
|
10
|
+
N2ZjZGQ3MWJiN2YyMjRmMGJiOGYzYTYxNTQyMTRjMGJiOTE0MGIzMjFhMmMz
|
11
|
+
ZTU4YTI4NmQxZGU3YjY0ODI0Nzk2OTRkMWM2OWMyZWRlYTM2NzA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDg2NDI0ZDYxNDdlOWY5M2JjY2Q3MTJhYzYzMzg2YTlmODhmN2Y4NTVmM2Jl
|
14
|
+
ZmQzYWNmYmE2ODNlNWM1MmYyZTkyOGMzYTAzMzhjOWQ1NTA4ZTlmOTVmZDYy
|
15
|
+
MDNiOTFhNWFiOWEzNGNmYmQyZmFmNDM3MTcwMWZjNWFjODdmMTg=
|
data/README.md
CHANGED
@@ -422,10 +422,26 @@ Additionally, the following options are supported:
|
|
422
422
|
Optional dependencies:
|
423
423
|
---
|
424
424
|
|
425
|
+
The following gems are needed based on what functions you use:
|
426
|
+
|
427
|
+
* `em-websocket' is required by `wunderbar/websocket`
|
428
|
+
* `kramdown' is required by `wunderbar/markdown`
|
429
|
+
* `ruby2js' adds support for scripts written as blocks
|
430
|
+
* `sourcify' is required by `wunderbar/opal`
|
431
|
+
|
432
|
+
The following gems are required by extensions of the same name:
|
433
|
+
|
434
|
+
* `coderay` - syntax highlighting
|
435
|
+
* `opal` - ruby to javascript compiler
|
436
|
+
* `rack` - webserver interface
|
437
|
+
* `rails` - web application framework
|
438
|
+
* `sinatra` - DSL for creating web applications
|
439
|
+
|
425
440
|
The following gems, if installed, will produce cleaner and prettier output:
|
426
441
|
|
427
442
|
* `nokogiri` cleans up HTML fragments inserted via `<<`
|
428
443
|
* `escape` prettier quoting of `system` commands
|
444
|
+
* `sanitize` will remove unsafe markup from tainted input
|
429
445
|
|
430
446
|
Related efforts:
|
431
447
|
---
|
data/lib/wunderbar/cssproxy.rb
CHANGED
@@ -43,18 +43,22 @@ module Wunderbar
|
|
43
43
|
|
44
44
|
if empty and not block
|
45
45
|
proxy = @builder.proxiable_tag! @node.name, *args
|
46
|
-
if SpacedNode
|
47
|
-
|
48
|
-
elsif CompactNode === @node
|
49
|
-
class << proxy.node?; include CompactNode; end
|
50
|
-
end
|
46
|
+
class << proxy.node?; include SpacedNode; end if SpacedNode === @node
|
47
|
+
class << proxy.node?; include CompactNode; end if CompactNode === @node
|
51
48
|
proxy
|
52
|
-
elsif SpacedNode === @node
|
53
|
-
@builder.__send__ "_#{@node.name.to_s.gsub('-', '_')}_", *args, &block
|
54
|
-
elsif CompactNode === @node and @node.name != :pre
|
55
|
-
@builder.__send__ "_#{@node.name.to_s.gsub('-', '_')}!", *args, &block
|
56
49
|
else
|
57
|
-
|
50
|
+
name = @node.name.to_s.gsub('-', '_')
|
51
|
+
if CompactNode === @node and @node.name != :pre
|
52
|
+
if SpacedNode === @node
|
53
|
+
@builder.__send__ "_#{name}_!", *args, &block
|
54
|
+
else
|
55
|
+
@builder.__send__ "_#{name}!", *args, &block
|
56
|
+
end
|
57
|
+
elsif SpacedNode === @node
|
58
|
+
@builder.__send__ "_#{name}_", *args, &block
|
59
|
+
else
|
60
|
+
@builder.__send__ "_#{name}", *args, &block
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
@@ -105,12 +105,16 @@ module Wunderbar
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
|
109
|
-
|
108
|
+
def find_name(name)
|
109
|
+
proc {|child| child.respond_to? :name and child.name == name}
|
110
|
+
end
|
111
|
+
|
112
|
+
if not head.children.any? &find_name('title')
|
113
|
+
h1 = body.children.find &find_name('h1')
|
110
114
|
head.add_child Node.new('title', h1.text) if h1 and h1.text
|
111
115
|
end
|
112
116
|
|
113
|
-
base = head.children.index
|
117
|
+
base = head.children.index &find_name('base')
|
114
118
|
if base
|
115
119
|
head.children.insert 1, head.children.delete_at(base) if base > 1
|
116
120
|
base_href = head.children[1].attrs[:href]
|
@@ -144,7 +148,9 @@ module Wunderbar
|
|
144
148
|
|
145
149
|
if name.sub!(/_$/,'')
|
146
150
|
@_x.spaced!
|
147
|
-
|
151
|
+
if flag != '!' and respond_to? "_#{name}"
|
152
|
+
return __send__ "_#{name}#{flag}", *args, &block
|
153
|
+
end
|
148
154
|
end
|
149
155
|
|
150
156
|
name = name.to_s.gsub('_', '-')
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'wunderbar/jquery'
|
2
|
+
require 'ruby2js/filter/jquery'
|
3
|
+
#
|
4
|
+
|
5
|
+
module Wunderbar
|
6
|
+
module Filter
|
7
|
+
module JQuery
|
8
|
+
include Ruby2JS::Filter::SEXP
|
9
|
+
|
10
|
+
def on_send(node)
|
11
|
+
if node.children[0] == nil and node.children[1] =~ /^_\w/
|
12
|
+
# map method calls starting with an underscore to jquery calls
|
13
|
+
# to create an element.
|
14
|
+
#
|
15
|
+
# input:
|
16
|
+
# _a 'name', href: 'link'
|
17
|
+
# output:
|
18
|
+
# $('<a></a>').text('name').attr(href: 'link')
|
19
|
+
#
|
20
|
+
tag = node.children[1].to_s[1..-1]
|
21
|
+
if Node::VOID.include? tag
|
22
|
+
element = s(:send, s(:str, "<#{tag}/>"), :~)
|
23
|
+
else
|
24
|
+
element = s(:send, s(:str, "<#{tag}></#{tag}>"), :~)
|
25
|
+
end
|
26
|
+
node.children[2..-1].each do |child|
|
27
|
+
if child.type == :hash
|
28
|
+
# convert _ to - in attribute names
|
29
|
+
pairs = child.children.map do |pair|
|
30
|
+
key, value = pair.children
|
31
|
+
if key.type == :sym
|
32
|
+
s(:pair, s(:str, key.children[0].to_s.gsub('_', '-')), value)
|
33
|
+
else
|
34
|
+
pair
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
element = s(:send, element, :attr, s(:hash, *pairs))
|
39
|
+
|
40
|
+
elsif child.type == :addClass
|
41
|
+
# :addClass arguments are inserted by "css proxy" logic below
|
42
|
+
element = s(:send, element, :addClass, s(:sym, *child.children))
|
43
|
+
|
44
|
+
elsif child.type == :block
|
45
|
+
# :block arguments are inserted by on_block logic below
|
46
|
+
element = s(:block, s(:send, element, :each!),
|
47
|
+
*node.children.last.children[1..-1])
|
48
|
+
|
49
|
+
else
|
50
|
+
# everything else added as text
|
51
|
+
element = s(:send, element, :text, child)
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
begin
|
57
|
+
jqchild, @_jqchild = @_jqchild, true
|
58
|
+
|
59
|
+
# have nested elements append themselves to their parent
|
60
|
+
if jqchild
|
61
|
+
element = s(:send, element, :appendTo,
|
62
|
+
s(:send, s(:lvar, :_parent), :~))
|
63
|
+
end
|
64
|
+
|
65
|
+
process element
|
66
|
+
ensure
|
67
|
+
@_jqchild = jqchild
|
68
|
+
end
|
69
|
+
|
70
|
+
elsif node.children[0] and node.children[0].type == :send
|
71
|
+
# determine if markaby style class and id names are being used
|
72
|
+
child = node
|
73
|
+
test = child.children.first
|
74
|
+
while test and test.type == :send and not test.is_method?
|
75
|
+
child, test = test, test.children.first
|
76
|
+
end
|
77
|
+
|
78
|
+
if child.children[0] == nil and child.children[1] =~ /^_\w/
|
79
|
+
# capture the arguments provided on the current node
|
80
|
+
children = node.children[2..-1]
|
81
|
+
|
82
|
+
# convert method calls to id and class values
|
83
|
+
prefix = []
|
84
|
+
while node != child
|
85
|
+
if node.children[1] !~ /!$/
|
86
|
+
# add class (mapping underscores to dashes)
|
87
|
+
prefix.unshift s(:addClass, node.children[1].to_s.gsub('_','-'))
|
88
|
+
else
|
89
|
+
# convert method name to hash {id: name} pair
|
90
|
+
pair = s(:pair, s(:sym, :id),
|
91
|
+
s(:str, node.children[1].to_s[0..-2].gsub('_','-')))
|
92
|
+
|
93
|
+
# if a hash argument is already passed, merge in id value
|
94
|
+
hash = children.find_index {|node| node.type == :hash}
|
95
|
+
if hash
|
96
|
+
children[hash] = s(:hash, pair, *children[hash].children)
|
97
|
+
else
|
98
|
+
prefix.unshift s(:hash, pair)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# advance to next node
|
103
|
+
node = node.children.first
|
104
|
+
end
|
105
|
+
|
106
|
+
# collapse series of method calls into a single call
|
107
|
+
return process(s(:send, *node.children[0..1], *prefix, *children))
|
108
|
+
else
|
109
|
+
super
|
110
|
+
end
|
111
|
+
|
112
|
+
else
|
113
|
+
super
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def on_block(node)
|
118
|
+
return super unless node.children[1].children.empty?
|
119
|
+
|
120
|
+
# traverse through potential "css proxy" style method calls
|
121
|
+
child = node.children.first
|
122
|
+
test = child.children.first
|
123
|
+
while test and test.type == :send and not test.is_method?
|
124
|
+
child, test = test, test.children.first
|
125
|
+
end
|
126
|
+
|
127
|
+
# append block as a standalone proc to wunderbar style method call
|
128
|
+
if child.children[0] == nil and child.children[1] =~ /^_\w/
|
129
|
+
block = s(:block, s(:send, nil, :proc),
|
130
|
+
s(:args, s(:arg, :_index), s(:arg, :_parent)),
|
131
|
+
*node.children[2..-1])
|
132
|
+
return on_send s(:send, *node.children.first.children, block)
|
133
|
+
end
|
134
|
+
|
135
|
+
super
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
Ruby2JS::Filter::DEFAULTS.push JQuery
|
140
|
+
end
|
141
|
+
end
|
data/lib/wunderbar/node.rb
CHANGED
@@ -76,7 +76,7 @@ module Wunderbar
|
|
76
76
|
else
|
77
77
|
width = options[:width] if name != :pre
|
78
78
|
line += ">#{text.to_s.gsub(/[&<>]/,ESCAPE)}</#{name}>"
|
79
|
-
if width and line.length > width
|
79
|
+
if indent and width and line.length > width
|
80
80
|
reflowed = IndentedTextNode.reflow(indent, line, width)
|
81
81
|
line = reflowed.pop
|
82
82
|
result.push *reflowed
|
@@ -87,24 +87,35 @@ module Wunderbar
|
|
87
87
|
else
|
88
88
|
line += "></#{name}>"
|
89
89
|
end
|
90
|
-
elsif CompactNode === self
|
90
|
+
elsif CompactNode === self and not CompactNode === parent
|
91
91
|
work = []
|
92
92
|
walk(work, nil, options)
|
93
93
|
width = options[:width]
|
94
94
|
if width
|
95
95
|
line += ">"
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
96
|
+
work = work.join + "</#{name}>"
|
97
|
+
if line.length + work.length <= width
|
98
|
+
line += work
|
99
|
+
else
|
100
|
+
# split work into tokens with balanced <>
|
101
|
+
tokens = work.split(' ')
|
102
|
+
(tokens.length-1).downto(1) do |i|
|
103
|
+
if tokens[i].count('<') != tokens[i].count('>')
|
104
|
+
tokens[i-1,2] = tokens[i-1] + ' ' + tokens[i]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
line += tokens.shift
|
109
|
+
|
110
|
+
# add tokens to line, breaking when line length would exceed width
|
111
|
+
tokens.each do |token|
|
112
|
+
if line.length + token.length < width
|
113
|
+
line += ' ' + token
|
114
|
+
else
|
115
|
+
result << line
|
116
|
+
line = indent.to_s + token
|
105
117
|
end
|
106
118
|
end
|
107
|
-
line += node
|
108
119
|
end
|
109
120
|
else
|
110
121
|
line += ">#{work.join}</#{name}>"
|
data/lib/wunderbar/version.rb
CHANGED
data/wunderbar.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "wunderbar"
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.21.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 = "2014-01-
|
9
|
+
s.date = "2014-01-26"
|
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/logger.rb", "lib/wunderbar/coderay.rb", "lib/wunderbar/rails.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/coffeescript.rb", "lib/wunderbar/vendor", "lib/wunderbar/vendor/polymer-v0.0.20131003.min.js", "lib/wunderbar/vendor/bootstrap.min.js", "lib/wunderbar/vendor/angular-resource.min.js", "lib/wunderbar/vendor/jquery-1.10.2.min.js", "lib/wunderbar/vendor/Markdown.Converter.js", "lib/wunderbar/vendor/bootstrap-theme.min.css", "lib/wunderbar/vendor/angular-route.min.js", "lib/wunderbar/vendor/angular.min.js", "lib/wunderbar/vendor/underscore-min.js", "lib/wunderbar/vendor/stupidtable.min.js", "lib/wunderbar/vendor/bootstrap.min.css", "lib/wunderbar/markdown.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/pagedown.rb", "lib/wunderbar/underscore.rb", "lib/wunderbar/server.rb", "lib/wunderbar/polymer.rb", "lib/wunderbar/version.rb", "lib/wunderbar/node.rb", "lib/wunderbar/asset.rb", "lib/wunderbar/script.rb", "lib/wunderbar/websocket.rb", "lib/wunderbar/bootstrap.rb", "lib/wunderbar/jquery", "lib/wunderbar/jquery/stupidtable.rb", "lib/wunderbar/angularjs", "lib/wunderbar/angularjs/route.rb", "lib/wunderbar/angularjs/resource.rb", "lib/wunderbar/opal", "lib/wunderbar/opal/browser.rb", "lib/wunderbar/opal/jquery.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/cssproxy.rb", "lib/wunderbar/angularjs.rb", "lib/wunderbar/jquery.rb", "lib/wunderbar/bootstrap", "lib/wunderbar/bootstrap/theme.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/sinatra.rb", "lib/wunderbar/rack.rb", "lib/wunderbar/opal.rb", "lib/wunderbar/installation.rb"]
|
12
|
+
s.files = ["wunderbar.gemspec", "README.md", "COPYING", "lib/wunderbar.rb", "lib/wunderbar", "lib/wunderbar/logger.rb", "lib/wunderbar/coderay.rb", "lib/wunderbar/rails.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/coffeescript.rb", "lib/wunderbar/vendor", "lib/wunderbar/vendor/polymer-v0.0.20131003.min.js", "lib/wunderbar/vendor/bootstrap.min.js", "lib/wunderbar/vendor/angular-resource.min.js", "lib/wunderbar/vendor/jquery-1.10.2.min.js", "lib/wunderbar/vendor/Markdown.Converter.js", "lib/wunderbar/vendor/bootstrap-theme.min.css", "lib/wunderbar/vendor/angular-route.min.js", "lib/wunderbar/vendor/angular.min.js", "lib/wunderbar/vendor/underscore-min.js", "lib/wunderbar/vendor/stupidtable.min.js", "lib/wunderbar/vendor/bootstrap.min.css", "lib/wunderbar/markdown.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/pagedown.rb", "lib/wunderbar/underscore.rb", "lib/wunderbar/server.rb", "lib/wunderbar/polymer.rb", "lib/wunderbar/version.rb", "lib/wunderbar/node.rb", "lib/wunderbar/asset.rb", "lib/wunderbar/script.rb", "lib/wunderbar/websocket.rb", "lib/wunderbar/bootstrap.rb", "lib/wunderbar/jquery", "lib/wunderbar/jquery/filter.rb", "lib/wunderbar/jquery/stupidtable.rb", "lib/wunderbar/angularjs", "lib/wunderbar/angularjs/route.rb", "lib/wunderbar/angularjs/resource.rb", "lib/wunderbar/opal", "lib/wunderbar/opal/browser.rb", "lib/wunderbar/opal/jquery.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/cssproxy.rb", "lib/wunderbar/angularjs.rb", "lib/wunderbar/jquery.rb", "lib/wunderbar/bootstrap", "lib/wunderbar/bootstrap/theme.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/sinatra.rb", "lib/wunderbar/rack.rb", "lib/wunderbar/opal.rb", "lib/wunderbar/installation.rb"]
|
13
13
|
s.homepage = "http://github.com/rubys/wunderbar"
|
14
14
|
s.licenses = ["MIT"]
|
15
15
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wunderbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/wunderbar/script.rb
|
66
66
|
- lib/wunderbar/websocket.rb
|
67
67
|
- lib/wunderbar/bootstrap.rb
|
68
|
+
- lib/wunderbar/jquery/filter.rb
|
68
69
|
- lib/wunderbar/jquery/stupidtable.rb
|
69
70
|
- lib/wunderbar/angularjs/route.rb
|
70
71
|
- lib/wunderbar/angularjs/resource.rb
|