wunderbar 0.12.1 → 0.12.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -266,6 +266,7 @@ the block
266
266
  * Example: `_([1,2,3]) {|n| n*n}`
267
267
 
268
268
  * arrays can be also be built using the `_` method:
269
+
269
270
  _ 1
270
271
  _ 2
271
272
 
@@ -37,39 +37,7 @@ class HtmlMarkup < Wunderbar::BuilderBase
37
37
  end
38
38
 
39
39
  if @_width
40
- # reflow long lines
41
- source = @x.target!.slice!(0..-1)
42
- indent = col = 0
43
- breakable = true
44
- pre = false
45
- while not source.empty?
46
- token = source.shift
47
- indent = token[/^ */].length if col == 0
48
-
49
- if token.start_with? '<'
50
- breakable = false
51
- pre = true if token == '<pre'
52
- end
53
-
54
- while token.length + col > @_width and breakable and not pre
55
- break if token[0...-1].include? "\n"
56
- split = token.rindex(' ', [@_width-col,0].max) || token.index(' ')
57
- break unless split
58
- break if col+split < indent+@_width/2
59
- @x.target! << token[0...split] << "\n" << (' '*indent)
60
- col = indent
61
- token = token[split+1..-1]
62
- end
63
-
64
- if token.end_with? '>'
65
- breakable = true
66
- pre = false if token == '</pre>'
67
- end
68
-
69
- @x.target! << token
70
- col += token.length
71
- col = 0 if token.end_with? "\n"
72
- end
40
+ self.class.reflow(@x.target!, @_width)
73
41
  end
74
42
 
75
43
  @x.target!.join
@@ -131,8 +99,12 @@ class HtmlMarkup < Wunderbar::BuilderBase
131
99
  end
132
100
 
133
101
  # ensure that non-void elements are explicitly closed
134
- if args.length == 0 or (args.length == 1 and Hash === args.first)
135
- args.unshift '' if not VOID.include?(name) and not block
102
+ if not block and not VOID.include?(name)
103
+ symbol = (args.shift if args.length > 0 and Symbol === args.first)
104
+ if args.length == 0 or (args.length == 1 and Hash === args.first)
105
+ args.unshift ''
106
+ end
107
+ args.unshift(symbol) if symbol
136
108
  end
137
109
 
138
110
  if String === args.first and args.first.respond_to? :html_safe?
@@ -236,35 +208,6 @@ class HtmlMarkup < Wunderbar::BuilderBase
236
208
  @x.text! text.to_s
237
209
  end
238
210
 
239
- def _coffeescript(text)
240
- require 'coffee-script'
241
- _script CoffeeScript.compile(text)
242
- rescue LoadError
243
- _script text, :lang => 'text/coffeescript'
244
- end
245
-
246
- def clear!
247
- @x.target!.clear
248
- end
249
-
250
- def self.flatten?(children)
251
- # do any of the text nodes need special processing to preserve spacing?
252
- flatten = false
253
- space = true
254
- if children.any? {|child| child.text? and !child.text.strip.empty?}
255
- children.each do |child|
256
- if child.text? or child.element?
257
- unless child.text == ''
258
- flatten = true if not space and not child.text =~ /\A\s/
259
- space = (child.text =~ /\s\Z/)
260
- end
261
- space = true if child.element? and HTML5_BLOCK.include? child.name
262
- end
263
- end
264
- end
265
- flatten
266
- end
267
-
268
211
  def _(children=nil)
269
212
  return @x if children == nil
270
213
 
@@ -338,4 +281,93 @@ class HtmlMarkup < Wunderbar::BuilderBase
338
281
  end
339
282
  end
340
283
  end
284
+
285
+ def _coffeescript(text)
286
+ require 'coffee-script'
287
+ _script CoffeeScript.compile(text)
288
+ rescue LoadError
289
+ _script text, :lang => 'text/coffeescript'
290
+ end
291
+
292
+ def clear!
293
+ @x.target!.clear
294
+ end
295
+
296
+ def self.flatten?(children)
297
+ # do any of the text nodes need special processing to preserve spacing?
298
+ flatten = false
299
+ space = true
300
+ if children.any? {|child| child.text? and !child.text.strip.empty?}
301
+ children.each do |child|
302
+ if child.text? or child.element?
303
+ unless child.text == ''
304
+ flatten = true if not space and not child.text =~ /\A\s/
305
+ space = (child.text =~ /\s\Z/)
306
+ end
307
+ space = true if child.element? and HTML5_BLOCK.include? child.name
308
+ end
309
+ end
310
+ end
311
+ flatten
312
+ end
313
+
314
+ # reflow long lines
315
+ def self.reflow(stream, width)
316
+ source = stream.slice!(0..-1)
317
+ indent = col = 0
318
+ breakable = true
319
+ pre = false
320
+ while not source.empty?
321
+ token = source.shift
322
+ indent = token[/^ */].length if col == 0
323
+
324
+ if token.start_with? '<'
325
+ breakable = false
326
+ pre = true if token == '<pre'
327
+ end
328
+
329
+ # flow text
330
+ while token.length + col > width and breakable and not pre
331
+ break if token[0...-1].include? "\n"
332
+ split = token.rindex(' ', [width-col,0].max) || token.index(' ')
333
+ break unless split
334
+ break if col+split < indent+width/2
335
+ stream << token[0...split] << "\n" << (' '*indent)
336
+ col = indent
337
+ token = token[split+1..-1]
338
+ end
339
+
340
+ # break around tags
341
+ if token.end_with? '>'
342
+ if col > indent + 4 and stream[-2..-1] == ['<br', '/']
343
+ stream << token << "\n"
344
+ col = 0
345
+ token = ' '*indent
346
+ source[0] = source.first.lstrip unless source.empty?
347
+ elsif col > width and not pre
348
+ # break on previous space within text
349
+ pcol = col
350
+ stream.reverse_each do |xtoken|
351
+ break if xtoken.include? "\n"
352
+ split = xtoken.rindex(' ')
353
+ breakable = false if xtoken.end_with? '>'
354
+ if breakable and split
355
+ col = col - pcol + xtoken.length - split + indent
356
+ xtoken[split] = "\n#{' '*indent}"
357
+ break
358
+ end
359
+ breakable = true if xtoken.start_with? '<'
360
+ pcol -= xtoken.length
361
+ break if pcol < (width + indent)/2
362
+ end
363
+ end
364
+ breakable = true
365
+ pre = false if token == '</pre>'
366
+ end
367
+
368
+ stream << token
369
+ col += token.length
370
+ col = 0 if token.end_with? "\n"
371
+ end
372
+ end
341
373
  end
@@ -2,7 +2,7 @@ module Wunderbar
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 12
5
- TINY = 1
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.12.1"
5
+ s.version = "0.12.3"
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-24"
9
+ s.date = "2012-04-25"
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/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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wunderbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000 Z
12
+ date: 2012-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder