wunderbar 0.10.5 → 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -1
- data/lib/wunderbar/builder.rb +1 -1
- data/lib/wunderbar/html-methods.rb +62 -1
- data/lib/wunderbar/version.rb +1 -1
- data/wunderbar.gemspec +2 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -282,6 +282,7 @@ HTML methods
|
|
282
282
|
* `_svg`: insert svg namespace
|
283
283
|
* `_math`: insert math namespace
|
284
284
|
* `_coffeescript`: convert [coffeescript](http://coffeescript.org/) to JS and insert script tag
|
285
|
+
* `_import!`: insert markup with indentation matching the current output
|
285
286
|
* `xhtml?`: output as XHTML?
|
286
287
|
|
287
288
|
Note that adding an exclamation mark to the end of the tag name disables this
|
@@ -291,7 +292,7 @@ Builder extensions
|
|
291
292
|
---
|
292
293
|
* `indented_text!`: matches text indentation to markup
|
293
294
|
* `indented_data!`: useful for script and styles in HTML syntax
|
294
|
-
* `
|
295
|
+
* `disable_indentation!`: temporarily disable insertion of whitespace
|
295
296
|
* `margin!`: insert blank lines between tags
|
296
297
|
|
297
298
|
Logging:
|
data/lib/wunderbar/builder.rb
CHANGED
@@ -37,7 +37,7 @@ module Wunderbar
|
|
37
37
|
self << post if post
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def disable_indentation!(&block)
|
41
41
|
indent, level, pending_newline, pending_margin =
|
42
42
|
indentation_state! [0, 0, @pending_newline, @pending_margin]
|
43
43
|
text! " "*indent*level
|
@@ -5,6 +5,13 @@ class HtmlMarkup < Wunderbar::BuilderBase
|
|
5
5
|
link meta param source track wbr
|
6
6
|
)
|
7
7
|
|
8
|
+
HTML5_BLOCK = %w(
|
9
|
+
# https://developer.mozilla.org/en/HTML/Block-level_elements
|
10
|
+
address article aside audio blockquote br canvas dd div dl fieldset
|
11
|
+
figcaption figcaption figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr
|
12
|
+
noscript ol output p pre section table tfoot ul video
|
13
|
+
)
|
14
|
+
|
8
15
|
def initialize(scope)
|
9
16
|
@_scope = scope
|
10
17
|
@x = Wunderbar::XmlMarkup.new :scope => scope, :indent => 2, :target => []
|
@@ -99,7 +106,7 @@ class HtmlMarkup < Wunderbar::BuilderBase
|
|
99
106
|
end
|
100
107
|
|
101
108
|
if flag == '!'
|
102
|
-
@x.
|
109
|
+
@x.disable_indentation! do
|
103
110
|
@x.tag! name, *args, &block
|
104
111
|
end
|
105
112
|
elsif flag == '?'
|
@@ -193,4 +200,58 @@ class HtmlMarkup < Wunderbar::BuilderBase
|
|
193
200
|
def clear!
|
194
201
|
@x.target!.clear
|
195
202
|
end
|
203
|
+
|
204
|
+
def self.flatten?(children)
|
205
|
+
# do any of the text nodes need special processing to preserve spacing?
|
206
|
+
flatten = false
|
207
|
+
space = true
|
208
|
+
if children.any? {|child| child.text? and !child.text.strip.empty?}
|
209
|
+
children.each do |child|
|
210
|
+
if child.text? or child.element?
|
211
|
+
unless child.text == ''
|
212
|
+
flatten = true if not space and not child.text =~ /\A\s/
|
213
|
+
space = (child.text =~ /\s\Z/)
|
214
|
+
end
|
215
|
+
space = true if child.element? and HTML5_BLOCK.include? child.name
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
flatten
|
220
|
+
end
|
221
|
+
|
222
|
+
def _import!(children)
|
223
|
+
if String === children
|
224
|
+
require 'nokogiri'
|
225
|
+
children = Nokogiri::HTML::fragment(children.to_s).children
|
226
|
+
end
|
227
|
+
|
228
|
+
# remove leading and trailing space
|
229
|
+
children.shift if children.first.text.strip.empty?
|
230
|
+
children.pop if children.last.text.strip.empty?
|
231
|
+
|
232
|
+
children.each do |child|
|
233
|
+
if child.text?
|
234
|
+
text = child.text
|
235
|
+
if text.strip.empty?
|
236
|
+
@x.text! "\n" if text.count("\n")>1
|
237
|
+
elsif @x.indentation_state!.first == 0
|
238
|
+
@x.indented_text! text.gsub(/\s+/, ' ')
|
239
|
+
else
|
240
|
+
@x.indented_text! text.strip
|
241
|
+
end
|
242
|
+
else
|
243
|
+
if self.class.flatten? child.children
|
244
|
+
@x.disable_indentation! do
|
245
|
+
@x.tag!(child.name, child.attributes) {_import! child.children}
|
246
|
+
end
|
247
|
+
elsif child.children.empty?
|
248
|
+
@x.tag!(child.name, child.attributes)
|
249
|
+
elsif child.children.all? {|gchild| gchild.text?}
|
250
|
+
@x.tag!(child.name, child.text.strip, child.attributes)
|
251
|
+
else
|
252
|
+
@x.tag!(child.name, child.attributes) {_import! child.children}
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
196
257
|
end
|
data/lib/wunderbar/version.rb
CHANGED
data/wunderbar.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "wunderbar"
|
5
|
-
s.version = "0.10.
|
5
|
+
s.version = "0.10.6"
|
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-16"
|
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"]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wunderbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 10
|
9
|
-
-
|
10
|
-
version: 0.10.
|
9
|
+
- 6
|
10
|
+
version: 0.10.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Ruby
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: builder
|