erector 0.4.191 → 0.4.200

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.
@@ -8,12 +8,8 @@ require "#{dir}/erector/raw_string"
8
8
  require "#{dir}/erector/widget"
9
9
  require "#{dir}/erector/unicode"
10
10
  require "#{dir}/erector/widgets"
11
+ require "#{dir}/erector/version"
11
12
  if Object.const_defined?(:RAILS_ROOT)
12
13
  require "#{dir}/erector/rails"
13
14
  end
14
15
 
15
- ##
16
- # Erector view framework
17
- module Erector
18
- VERSION = "0.4.191"
19
- end
@@ -2,6 +2,8 @@ module Erector
2
2
  # A proxy to an IO object that adds methods to add xml.
3
3
  class Doc
4
4
 
5
+ cattr_accessor :prettyprint_default
6
+
5
7
  NON_NEWLINEY = {'i' => true, 'b' => true, 'small' => true,
6
8
  'img' => true, 'span' => true, 'a' => true,
7
9
  'input' => true, 'textarea' => true, 'button' => true, 'select' => true
@@ -15,6 +17,7 @@ module Erector
15
17
  @output = output
16
18
  @at_start_of_line = true
17
19
  @indent = 0
20
+ @enable_prettyprint = prettyprint_default
18
21
  end
19
22
 
20
23
  def output
@@ -0,0 +1,6 @@
1
+ ##
2
+ # Erector view framework
3
+ module Erector
4
+ VERSION = "0.4.200"
5
+ end
6
+
@@ -252,6 +252,20 @@ module Erector
252
252
  def close_tag(tag_name)
253
253
  @doc.close_tag tag_name
254
254
  end
255
+
256
+ # Emits the result of joining the elements in array with the separator.
257
+ # The array elements and separator can be Erector::Widget objects,
258
+ # which are rendered, or strings, which are quoted and output.
259
+ def join(array, separator)
260
+ first = true
261
+ array.each do |widget_or_text|
262
+ if !first
263
+ text separator
264
+ end
265
+ first = false
266
+ text widget_or_text
267
+ end
268
+ end
255
269
 
256
270
  # Emits an XML instruction, which looks like this: <?xml version=\"1.0\" encoding=\"UTF-8\"?>
257
271
  def instruct(attributes={:version => "1.0", :encoding => "UTF-8"})
@@ -1 +1,2 @@
1
- require "erector/widgets/table"
1
+ require "#{File.dirname(__FILE__)}/widgets/table"
2
+
@@ -123,5 +123,13 @@ END
123
123
  end.enable_prettyprint(true).to_pretty.should == "One\n<p>Two</p>\n"
124
124
  end
125
125
 
126
+ it "can turn newlines on/off via global variable" do
127
+ Erector::Widget.new { br }.to_s.should == "<br />"
128
+ Erector::Doc.prettyprint_default = true
129
+ Erector::Widget.new { br }.to_s.should == "<br />\n"
130
+ Erector::Doc.prettyprint_default = false
131
+ Erector::Widget.new { br }.to_s.should == "<br />"
132
+ end
133
+
126
134
  end
127
135
 
@@ -401,6 +401,50 @@ module WidgetSpec
401
401
  end
402
402
  end
403
403
 
404
+ describe "#join" do
405
+
406
+ it "empty array means nothing to join" do
407
+ Erector::Widget.new do
408
+ join [], Erector::Widget.new { text "x" }
409
+ end.to_s.should == ""
410
+ end
411
+
412
+ it "larger example with two tabs" do
413
+ Erector::Widget.new do
414
+ tab1 =
415
+ Erector::Widget.new do
416
+ a "Upload document", :href => "/upload"
417
+ end
418
+ tab2 =
419
+ Erector::Widget.new do
420
+ a "Logout", :href => "/logout"
421
+ end
422
+ join [tab1, tab2],
423
+ Erector::Widget.new { text nbsp(" |"); text " " }
424
+ end.to_s.should ==
425
+ '<a href="/upload">Upload document</a>&#160;| <a href="/logout">Logout</a>'
426
+ end
427
+
428
+ it "plain string as join separator means pass it to text" do
429
+ Erector::Widget.new do
430
+ join [
431
+ Erector::Widget.new { text "x" },
432
+ Erector::Widget.new { text "y" }
433
+ ], "<>"
434
+ end.to_s.should == "x&lt;&gt;y"
435
+ end
436
+
437
+ it "plain string as item to join means pass it to text" do
438
+ Erector::Widget.new do
439
+ join [
440
+ "<",
441
+ "&"
442
+ ], Erector::Widget.new { text " + " }
443
+ end.to_s.should == "&lt; + &amp;"
444
+ end
445
+
446
+ end
447
+
404
448
  describe '#h' do
405
449
  before do
406
450
  @widget = Erector::Widget.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.191
4
+ version: 0.4.200
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal Labs
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-29 00:00:00 -07:00
12
+ date: 2008-10-12 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,26 +51,6 @@ extra_rdoc_files:
51
51
  files:
52
52
  - spec/spec_helper.rb
53
53
  - spec/core_spec_suite.rb
54
- - spec/rails
55
- - spec/rails/rails_root
56
- - spec/rails/rails_root/doc
57
- - spec/rails/rails_root/config
58
- - spec/rails/rails_root/config/environments
59
- - spec/rails/rails_root/config/initializers
60
- - spec/rails/rails_root/spec
61
- - spec/rails/rails_root/spec/extensions
62
- - spec/rails/rails_root/script
63
- - spec/rails/rails_root/script/process
64
- - spec/rails/rails_root/script/performance
65
- - spec/rails/rails_root/app
66
- - spec/rails/rails_root/app/views
67
- - spec/rails/rails_root/app/views/template_handler_spec
68
- - spec/rails/rails_root/app/controllers
69
- - spec/rails/rails_root/app/helpers
70
- - spec/rails/rails_root/public
71
- - spec/rails/rails_root/public/javascripts
72
- - spec/rails/rails_root/public/images
73
- - spec/rails/extensions
74
54
  - spec/rails_spec_suite.rb
75
55
  - spec/erect
76
56
  - spec/erect/rhtml_parser_spec.rb
@@ -80,7 +60,6 @@ files:
80
60
  - spec/erector/widgets
81
61
  - spec/erector/widgets/table_spec.rb
82
62
  - spec/erector/doc_spec.rb
83
- - spec/erector/extensions
84
63
  - spec/erector/widget_spec.rb
85
64
  - spec/erector/indentation_spec.rb
86
65
  - spec/erector/unicode_builder_spec.rb
@@ -109,6 +88,7 @@ files:
109
88
  - lib/erector/rhtml.treetop
110
89
  - lib/erector/rails.rb
111
90
  - lib/erector/indenting.rb
91
+ - lib/erector/version.rb
112
92
  - lib/erector/erected.rb
113
93
  - README.txt
114
94
  - bin/erect