wunderbar 0.22.2 → 0.22.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,10 @@
1
1
  module Wunderbar
2
+ @@options = {indent: 2}
3
+ def self.option(values={})
4
+ @@options.merge!(values)
5
+ @@options
6
+ end
7
+
2
8
  class BuilderBase
3
9
  def set_variables_from_params(locals={})
4
10
  params = @_scope.params.map do |key, value|
@@ -121,16 +127,16 @@ module Wunderbar
121
127
 
122
128
  def initialize(args={})
123
129
  @_scope = args.delete(:scope)
124
- @_indent = args.delete(:indent) || 2
130
+ @_indent = args.delete(:indent) || Wunderbar.option[:indent]
131
+ @_width = args.delete(:width) || Wunderbar.option[:width]
125
132
  @_pdf = false
126
133
  @doc = Node.new(nil)
127
134
  @node = @doc
128
135
  @indentation_enabled = true
129
- @width = nil
130
136
  @spaced = false
131
137
  end
132
138
 
133
- attr_accessor :width
139
+ attr_accessor :_width
134
140
 
135
141
  # forward to Wunderbar or @_scope
136
142
  def method_missing(method, *args, &block)
@@ -176,7 +182,7 @@ module Wunderbar
176
182
  end
177
183
 
178
184
  def target!
179
- "#{@doc.serialize(indent: ' ' * @_indent, width: @width).join("\n")}\n"
185
+ "#{@doc.serialize(indent: ' ' * @_indent, width: @_width).join("\n")}\n"
180
186
  end
181
187
 
182
188
  def clear!
@@ -39,7 +39,7 @@ module Wunderbar
39
39
 
40
40
  def initialize(scope)
41
41
  @_scope = scope
42
- @_x = XmlMarkup.new :scope => scope, :indent => 2
42
+ @_x = XmlMarkup.new :scope => scope
43
43
  end
44
44
 
45
45
  def html(*args, &block)
@@ -47,7 +47,7 @@ module Wunderbar
47
47
  args << {} if args.empty?
48
48
  if Hash === args.first
49
49
  args.first[:xmlns] ||= 'http://www.w3.org/1999/xhtml'
50
- @_x.width = args.first.delete(:_width).to_i if args.first[:_width]
50
+ @_x._width = args.first.delete(:_width).to_i if args.first[:_width]
51
51
  end
52
52
 
53
53
  bom = "\ufeff"
@@ -292,9 +292,7 @@ module Wunderbar
292
292
  end
293
293
 
294
294
  def _textarea(*args, &block)
295
- @_x.compact! do
296
- proxiable_tag! :textarea, PreformattedNode, *args, &block
297
- end
295
+ proxiable_tag! :textarea, PreformattedNode, *args, &block
298
296
  end
299
297
 
300
298
  def _ul(*args, &block)
@@ -91,8 +91,9 @@ module Wunderbar
91
91
  line += "></#{name}>"
92
92
  end
93
93
 
94
- if indent and width and line.length > width
95
- reflowed = IndentedTextNode.reflow(indent, line, width)
94
+ if indent and width and (line.length > width or line.include? "\n")
95
+ reflowed = IndentedTextNode.reflow(indent, line, width,
96
+ options[:indent])
96
97
  line = reflowed.pop
97
98
  result.push *reflowed
98
99
  end
@@ -224,10 +225,10 @@ module Wunderbar
224
225
  end
225
226
 
226
227
  class IndentedTextNode < TextNode
227
- def self.reflow(indent, line, width)
228
+ def self.reflow(indent, line, width, next_indent)
228
229
  return [line] unless width and indent
229
- line = indent + line.gsub!(/\s+/, ' ').strip
230
- indent += ' '
230
+ line = indent + line.gsub(/\s+/, ' ').strip
231
+ indent += next_indent
231
232
 
232
233
  result = []
233
234
  while line.length > width
@@ -248,7 +249,7 @@ module Wunderbar
248
249
  end
249
250
 
250
251
  result.push *IndentedTextNode.reflow(indent,
251
- text.to_s.gsub(/[&<>\u00A0]/,ESCAPE), options[:width])
252
+ text.to_s.gsub(/[&<>\u00A0]/,ESCAPE), options[:width], '')
252
253
  end
253
254
  end
254
255
 
@@ -201,6 +201,16 @@ module Wunderbar
201
201
  end
202
202
  end
203
203
 
204
+ # text, json shortcuts
205
+ if block == nil and args.length >= 1
206
+ case args.first
207
+ when Array, Hash
208
+ block = proc { _! args.first } if ext == :_json
209
+ when String
210
+ block = proc { _ args.first } if ext == :_text
211
+ end
212
+ end
213
+
204
214
  template.evaluate(ext, self, *args, &block)
205
215
  end
206
216
 
@@ -2,7 +2,7 @@ module Wunderbar
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 22
5
- TINY = 2
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.22.2"
5
+ s.version = "0.22.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 = "2015-01-08"
9
+ s.date = "2015-01-14"
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/script.rb", "lib/wunderbar/jquery.rb", "lib/wunderbar/underscore.rb", "lib/wunderbar/polymer.rb", "lib/wunderbar/jquery", "lib/wunderbar/jquery/filter.rb", "lib/wunderbar/jquery/stupidtable.rb", "lib/wunderbar/vendor", "lib/wunderbar/vendor/polymer-v0.0.20131003.min.js", "lib/wunderbar/vendor/stupidtable.min.js", "lib/wunderbar/vendor/bootstrap.min.js", "lib/wunderbar/vendor/Markdown.Converter.js", "lib/wunderbar/vendor/angular.min.js", "lib/wunderbar/vendor/bootstrap-theme.min.css", "lib/wunderbar/vendor/jquery-1.11.0.min.js", "lib/wunderbar/vendor/angular-resource.min.js", "lib/wunderbar/vendor/bootstrap.min.css", "lib/wunderbar/vendor/underscore-min.js", "lib/wunderbar/vendor/angular-route.min.js", "lib/wunderbar/websocket.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/pagedown.rb", "lib/wunderbar/version.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/server.rb", "lib/wunderbar/angularjs.rb", "lib/wunderbar/logger.rb", "lib/wunderbar/asset.rb", "lib/wunderbar/backtick.rb", "lib/wunderbar/opal", "lib/wunderbar/opal/browser.rb", "lib/wunderbar/opal/jquery.rb", "lib/wunderbar/coffeescript.rb", "lib/wunderbar/markdown.rb", "lib/wunderbar/opal.rb", "lib/wunderbar/installation.rb", "lib/wunderbar/bootstrap.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/sinatra.rb", "lib/wunderbar/rails.rb", "lib/wunderbar/angularjs", "lib/wunderbar/angularjs/resource.rb", "lib/wunderbar/angularjs/route.rb", "lib/wunderbar/rack.rb", "lib/wunderbar/coderay.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/bootstrap", "lib/wunderbar/bootstrap/theme.rb", "lib/wunderbar/cssproxy.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/node.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.22.2
4
+ version: 0.22.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: 2015-01-08 00:00:00.000000000 Z
12
+ date: 2015-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json