aurita-gui 0.5.0 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ ./README.txt
2
+ ./Manifest.txt
3
+ ./spec
4
+ ./spec/html.rb
5
+ ./spec/form.rb
6
+ ./spec/element.rb
7
+ ./spec/options.rb
8
+ ./spec/fieldset.rb
9
+ ./spec/javascript.rb
10
+ ./spec/marshal.rb
11
+ ./spec/selection_list.rb
12
+ ./spec/init_code.rb
13
+ ./spec/table.rb
14
+ ./TODO
15
+ ./samples
16
+ ./samples/putstest.rb
17
+ ./samples/recurse.rb
18
+ ./samples/cheatsheet.rb
19
+ ./samples/valuetest.rb
20
+ ./samples/pushtest.rb
21
+ ./aurita-gui.gemspec
22
+ ./lib
23
+ ./lib/aurita-gui.rb
24
+ ./lib/aurita-gui
25
+ ./lib/aurita-gui/element_fixed.rb
26
+ ./lib/aurita-gui/html.rb
27
+ ./lib/aurita-gui/form.rb
28
+ ./lib/aurita-gui/widget.rb
29
+ ./lib/aurita-gui/button.rb
30
+ ./lib/aurita-gui/element.rb
31
+ ./lib/aurita-gui/form
32
+ ./lib/aurita-gui/form/datetime_field.rb
33
+ ./lib/aurita-gui/form/input_field.rb
34
+ ./lib/aurita-gui/form/radio_field.rb
35
+ ./lib/aurita-gui/form/checkbox_field.rb
36
+ ./lib/aurita-gui/form/time_field.rb
37
+ ./lib/aurita-gui/form/date_field.rb
38
+ ./lib/aurita-gui/form/form_field.rb
39
+ ./lib/aurita-gui/form/options_field.rb
40
+ ./lib/aurita-gui/form/password_field.rb
41
+ ./lib/aurita-gui/form/text_field.rb
42
+ ./lib/aurita-gui/form/textarea_field.rb
43
+ ./lib/aurita-gui/form/select_field.rb
44
+ ./lib/aurita-gui/form/file_field.rb
45
+ ./lib/aurita-gui/form/hidden_field.rb
46
+ ./lib/aurita-gui/form/template_helper.rb
47
+ ./lib/aurita-gui/form/boolean_field.rb
48
+ ./lib/aurita-gui/form/form_error.rb
49
+ ./lib/aurita-gui/form/fieldset.rb
50
+ ./lib/aurita-gui/form/selection_list.rb
51
+ ./lib/aurita-gui/javascript.rb
52
+ ./lib/aurita-gui/marshal.rb
53
+ ./lib/aurita-gui/table.rb
54
+ ./bin
55
+ ./LICENSE
@@ -14,19 +14,69 @@ as stand-alone library in any context (such as rails).
14
14
  As there seems to be a lack of ruby form generators, i decided to release this
15
15
  part of Aurita in a single gem with no dependencies on aurita itself.
16
16
  EOF
17
- s.version = '0.5.0'
17
+ s.version = '0.5.9'
18
18
  s.author = 'Tobias Fuchs'
19
19
  s.email = 'fuchs@wortundform.de'
20
20
  s.date = Time.now
21
21
  s.files = '*.rb'
22
22
  s.add_dependency('arrayfields', '>= 4.6.0')
23
- s.files = FileList['*',
24
- 'lib/*',
25
- 'lib/aurita-gui/*',
26
- 'lib/aurita-gui/form/*',
27
- 'bin/*',
28
- 'samples/*',
29
- 'spec/*'].to_a
23
+ s.files = [
24
+ './README.txt',
25
+ './Manifest.txt',
26
+ './spec',
27
+ './spec/html.rb',
28
+ './spec/form.rb',
29
+ './spec/element.rb',
30
+ './spec/options.rb',
31
+ './spec/fieldset.rb',
32
+ './spec/javascript.rb',
33
+ './spec/marshal.rb',
34
+ './spec/selection_list.rb',
35
+ './spec/init_code.rb',
36
+ './spec/table.rb',
37
+ './TODO',
38
+ './samples',
39
+ './samples/putstest.rb',
40
+ './samples/recurse.rb',
41
+ './samples/cheatsheet.rb',
42
+ './samples/valuetest.rb',
43
+ './samples/pushtest.rb',
44
+ './aurita-gui.gemspec',
45
+ './lib',
46
+ './lib/aurita-gui.rb',
47
+ './lib/aurita-gui',
48
+ './lib/aurita-gui/element_fixed.rb',
49
+ './lib/aurita-gui/html.rb',
50
+ './lib/aurita-gui/form.rb',
51
+ './lib/aurita-gui/widget.rb',
52
+ './lib/aurita-gui/button.rb',
53
+ './lib/aurita-gui/element.rb',
54
+ './lib/aurita-gui/form',
55
+ './lib/aurita-gui/form/datetime_field.rb',
56
+ './lib/aurita-gui/form/input_field.rb',
57
+ './lib/aurita-gui/form/radio_field.rb',
58
+ './lib/aurita-gui/form/checkbox_field.rb',
59
+ './lib/aurita-gui/form/time_field.rb',
60
+ './lib/aurita-gui/form/date_field.rb',
61
+ './lib/aurita-gui/form/form_field.rb',
62
+ './lib/aurita-gui/form/options_field.rb',
63
+ './lib/aurita-gui/form/password_field.rb',
64
+ './lib/aurita-gui/form/text_field.rb',
65
+ './lib/aurita-gui/form/textarea_field.rb',
66
+ './lib/aurita-gui/form/select_field.rb',
67
+ './lib/aurita-gui/form/file_field.rb',
68
+ './lib/aurita-gui/form/hidden_field.rb',
69
+ './lib/aurita-gui/form/template_helper.rb',
70
+ './lib/aurita-gui/form/boolean_field.rb',
71
+ './lib/aurita-gui/form/form_error.rb',
72
+ './lib/aurita-gui/form/fieldset.rb',
73
+ './lib/aurita-gui/form/selection_list.rb',
74
+ './lib/aurita-gui/javascript.rb',
75
+ './lib/aurita-gui/marshal.rb',
76
+ './lib/aurita-gui/table.rb',
77
+ './bin',
78
+ './LICENSE'
79
+ ]
30
80
 
31
81
  s.has_rdoc = true
32
82
  s.rdoc_options << '--title' << 'Aurita::GUI' <<
@@ -203,7 +203,7 @@ module GUI
203
203
  @content = params[:content] unless @content
204
204
  end
205
205
  # DON'T EVER USE @content.string UNLESS FOR RENDERING!!
206
- # @content = nil if @content.to_s.length == 0
206
+ # @content = nil if @content.to_s.length == 0 # <--- NOOOOooo!
207
207
  # instead, do:
208
208
  @content = nil if !@content.is_a?(Element) && ((@content.respond_to?(:length) && @content.length == 0))
209
209
  @content = [ @content ] unless (@content.kind_of? Array or @content.nil?)
@@ -222,6 +222,10 @@ module GUI
222
222
  super(@content)
223
223
  end
224
224
 
225
+ def inspect
226
+ "#{self.class.to_s}: <#{@tag}>, #{@attrib.inspect} { #{@content.inspect} }"
227
+ end
228
+
225
229
  # To definitely tell if a class is
226
230
  # anyhow derived from Element, use
227
231
  #
@@ -241,7 +245,8 @@ module GUI
241
245
  def touch
242
246
  @touched = true
243
247
  @string = nil
244
- @parent.touch() if @parent
248
+ # Don't re-touch! Parent could have been caller!
249
+ @parent.touch() if (@parent && !@parent.touched?)
245
250
  end
246
251
  alias touch! touch
247
252
  def touched?
@@ -42,7 +42,7 @@ module GUI
42
42
  # To use your own implementation as defaut, overload Form.initialize
43
43
  # like
44
44
  #
45
- # class My_Form < Aurita::GUI::Form
45
+ # class My_Form < Aurita::GUI::For
46
46
  # def initialize(params={}, &block)
47
47
  # super(params, &block)
48
48
  # @field_decorator = My_Field_Decorator
@@ -313,7 +313,29 @@ module GUI
313
313
  #
314
314
  class Form < Element
315
315
 
316
- attr_accessor :fields, :elements, :element_map, :values, :field_decorator, :content_decorator
316
+ # Array of form field names ordered by appearance in the form.
317
+ # It is used to determine which fields to render, and in which
318
+ # order.
319
+ attr_accessor :fields
320
+
321
+ # Array of Form_Field instances includes in this form.
322
+ attr_accessor :elements
323
+
324
+ # Hash mapping field names to Form_Field instances.
325
+ attr_accessor :element_map
326
+
327
+ # Hash mapping form field names to their values.
328
+ attr_accessor :values
329
+
330
+ # Field decorator class to use for decorating single fields.
331
+ attr_accessor :field_decorator
332
+
333
+ # Decorator class to use for decorating the form content.
334
+ attr_accessor :content_decorator
335
+
336
+ # Array of fieldsets in this form, ordered by appearance in
337
+ # the form.
338
+ attr_reader :fieldsets
317
339
 
318
340
  def initialize(params={}, &block)
319
341
  @fields = params[:fields]
@@ -321,6 +343,7 @@ module GUI
321
343
  @fields ||= []
322
344
  @elements = []
323
345
  @element_map = {}
346
+ @fieldsets = {}
324
347
  @values ||= {}
325
348
  @title = false
326
349
  @custom_fields = false
@@ -351,6 +374,7 @@ module GUI
351
374
  # parameter is of type Numeric, by name otherwhise)
352
375
  def [](index)
353
376
  return @elements[index] if index.kind_of? Numeric
377
+ return @element_map[index] if @element_map[index]
354
378
  return @element_map[index.to_s]
355
379
  end
356
380
 
@@ -391,13 +415,21 @@ module GUI
391
415
  # with same field name.
392
416
  def add(form_field_element)
393
417
  touch()
394
- field_name = form_field_element.name.to_s
395
- form_field_element.value = @values[field_name] unless form_field_element.value.to_s != ''
396
- if !form_field_element.dom_id then
397
- form_field_element.dom_id = field_name.gsub('.','_')
418
+ if form_field_element.is_a?(Fieldset) then
419
+ form_field_element.field_decorator = @field_decorator
420
+ form_field_element.content_decorator = @content_decorator
421
+ @element_map.update(form_field_element.element_map)
422
+ @elements << form_field_element
423
+ @fieldsets[form_field_element.name.to_s] = form_field_element
424
+ else
425
+ field_name = form_field_element.name.to_s
426
+ form_field_element.value = @values[field_name] unless form_field_element.value.to_s != ''
427
+ if !form_field_element.dom_id then
428
+ form_field_element.dom_id = field_name.gsub('.','_')
429
+ end
430
+ @element_map[field_name] = form_field_element
431
+ @elements << form_field_element
398
432
  end
399
- @element_map[field_name] = form_field_element
400
- @elements << form_field_element
401
433
  @content = false # Invalidate
402
434
  end
403
435
 
@@ -413,10 +445,50 @@ module GUI
413
445
  def fields=(attrib_array)
414
446
  touch()
415
447
  @custom_fields = true
416
- @fields = attrib_array.flatten.collect { |fieldname| fieldname.to_s }
448
+ @fields = attrib_array.map { |field|
449
+ (field.is_a?(Hash))? field : field.to_s
450
+ }
451
+ attrib_array.each { |attrib|
452
+ if attrib.is_a?(Hash) then
453
+ attrib.each_pair { |fieldset_name, fieldset_fields|
454
+ legend = false
455
+ if fieldset_fields.is_a?(Hash) then
456
+ legend = fieldset_fields[:legend]
457
+ fieldset_fields = fieldset_fields[:fields]
458
+ end
459
+ # This is a configuration for a fieldset.
460
+ # There are two cases:
461
+ fieldset = @fieldsets[fieldset_name.to_s]
462
+ if fieldset then
463
+ # - The fieldset already has been added to this form.
464
+ # In this case, just pass field settings along to
465
+ # the fieldset.
466
+ fieldset.fields = fieldset_fields
467
+ else
468
+ # - There is no fieldset with given name in this form.
469
+ # In this case, we expect that at least the given
470
+ # form fields are present in this form, and we
471
+ # implicitly create a Fieldset instance here.
472
+ fieldset = Fieldset.new(:name => fieldset_name, :legend => legend)
473
+ fieldset_fields.each { |field|
474
+ existing_field = @element_map[field.to_s]
475
+ fieldset.add(existing_field) if existing_field
476
+ }
477
+ fieldset.fields = fieldset_fields
478
+ add(fieldset)
479
+ end
480
+ }
481
+ end
482
+ }
417
483
  @elements.each { |field|
418
- @element_map[field.name.to_s] = field
484
+ if field.is_a?(Form_Field) then
485
+ # Update element map only if referenced eleemnt is a
486
+ # Form_Field, do not include Fieldset elements.
487
+ @element_map[field.name.to_s] = field
488
+ elsif field.is_a?(Fieldset) then
489
+ end
419
490
  }
491
+ @content = false # Invalidate
420
492
  end
421
493
  alias set_field_config fields=
422
494
 
@@ -436,21 +508,18 @@ module GUI
436
508
  end
437
509
  alias set_values values=
438
510
 
439
- # Set all elements to readonly rendering mode.
440
- def readonly!
441
- touch()
442
- @elements.each { |e|
443
- e.readonly!
444
- }
445
- end
446
-
447
511
  # Return array of field names currently
448
512
  # available for rendering.
449
513
  def fields()
450
514
  if !@custom_fields || @fields.length == 0 then
451
515
  @elements.each { |field|
452
- @fields << field.name.to_s
453
- @element_map[field.name.to_s] = field
516
+ if field.is_a?(Form_Field) then
517
+ @fields << field.name
518
+ @element_map[field.name.to_s] = field
519
+ elsif field.is_a?(Fieldset) then
520
+ @fields << { field.name => field.fields }
521
+ @element_map.update(field.element_map)
522
+ end
454
523
  }
455
524
  end
456
525
  @fields.uniq!
@@ -475,19 +544,26 @@ module GUI
475
544
  # Return underlying HTML element instance (HTML.ul),
476
545
  # without wrapping HTML.form element.
477
546
  def content
478
- # TODO: Provide Fieldset instances
479
547
  @content = []
480
548
  if @title then
481
549
  @content << HTML.h1(:class => :form_title) { @title }
482
550
  end
483
551
  fields().each { |field|
484
- element = @element_map[field.to_s]
485
- if element then
486
- element = element.to_hidden_field() if element.hidden?
487
- if element.kind_of? Aurita::GUI::Hidden_Field then
488
- @content << element
489
- else
490
- @content << @field_decorator.new(element)
552
+ if field.is_a?(Hash) then
553
+ # This is a fieldset
554
+ field.each_pair { |fieldset_name, fieldset_fields|
555
+ # Get Fieldset instance by name from @element_map:
556
+ @content << HTML.li { @fieldsets[fieldset_name.to_s] }
557
+ }
558
+ else
559
+ element = @element_map[field.to_s]
560
+ if element then
561
+ element = element.to_hidden_field() if element.hidden?
562
+ if element.kind_of? Aurita::GUI::Hidden_Field then
563
+ @content << element
564
+ else
565
+ @content << @field_decorator.new(element)
566
+ end
491
567
  end
492
568
  end
493
569
  }
@@ -5,24 +5,45 @@ module Aurita
5
5
  module GUI
6
6
 
7
7
  class Fieldset < Element
8
- attr_accessor :legend, :label, :name
8
+ attr_accessor :legend
9
+
10
+ attr_accessor :label
11
+
12
+ attr_accessor :name
13
+
14
+ attr_accessor :element_map
15
+
16
+ attr_accessor :elements
17
+
18
+ attr_accessor :field_decorator
19
+
20
+ attr_accessor :content_dacorator
9
21
 
10
22
  def initialize(params, &block)
11
- params[:tag] = :fieldset
12
- @name = params[:name]
13
- @elements = []
23
+ params[:tag] = :fieldset
24
+ params[:id] = params[:name] unless params[:id]
25
+ @name = params[:name]
26
+ @fields = []
27
+ @elements = []
28
+ @element_map = {}
29
+ @field_decorator = Aurita::GUI::Form_Field_Wrapper
30
+ @content_decorator = Aurita::GUI::Form_Content_Wrapper
31
+
14
32
  if block_given? then
15
33
  yield.each { |field_element|
16
34
  add(field_element)
17
35
  }
18
36
  end
37
+
19
38
  legend_element = params[:legend]
20
39
  legend_element ||= params[:label]
21
- set_legend(legend_element)
40
+ set_legend(legend_element) if legend_element
22
41
  params.delete(:legend)
23
42
  params.delete(:label)
24
43
  params.delete(:name)
25
44
  super(params, &block)
45
+
46
+ @content = false
26
47
  end
27
48
  alias legend label
28
49
 
@@ -36,19 +57,73 @@ module GUI
36
57
  alias set_legend legend=
37
58
  alias label= legend=
38
59
 
60
+ def each(&block)
61
+ @elements.each(&block)
62
+ end
63
+
39
64
  def add(field_element)
40
65
  @elements << field_element
66
+ @element_map[field_element.name.to_s] = field_element
67
+ @fields << field_element.name
68
+
69
+ touch()
70
+ end
71
+
72
+ def fields=(attrib_array)
73
+ @fields = attrib_array.map { |f| f.to_s }
74
+ touch()
75
+ end
76
+
77
+ def fields
78
+ @fields
79
+ end
80
+
81
+ # Set all elements to readonly rendering mode.
82
+ def readonly!
83
+ @elements.each { |e|
84
+ e.readonly!
85
+ }
86
+ touch()
87
+ end
88
+ # Set all form elements to editable mode.
89
+ def editable!
90
+ @elements.each { |e|
91
+ e.editable!
92
+ }
93
+ touch()
94
+ end
95
+
96
+ def length
97
+ @elements.length
41
98
  end
42
99
 
43
100
  def content
101
+ return @content if (@content && !@touched)
102
+
103
+ @content = fields().map { |field|
104
+ element = @element_map[field.to_s]
105
+ STDERR.puts "What the? #{field.inspect}" unless element
106
+ @field_decorator.new(element) if element
107
+ }
108
+
109
+ @content = @content_decorator.new() { @content }
110
+ @content.add_css_class(:fieldset)
111
+
44
112
  if @legend then
45
- @content = [ @legend, @elements ]
113
+ @content = HTML.fieldset { @legend + @content }
46
114
  else
47
- @content = @elements
115
+ @content = HTML.fieldset { @content}
48
116
  end
117
+
49
118
  return @content
50
119
  end
51
120
 
121
+ def string
122
+ content().to_s
123
+ end
124
+ alias to_s string
125
+ alias to_str string
126
+
52
127
  end
53
128
 
54
129
  end
@@ -131,13 +131,6 @@ module GUI
131
131
  super(params)
132
132
  end
133
133
 
134
- =begin
135
- def form=(form_instance)
136
- @form = form_instance
137
- @params[:parent] = @form
138
- end
139
- =end
140
-
141
134
  # Virtual method.
142
135
  def element
143
136
  raise Form_Error.new('Form_Field@element not set') unless @element
@@ -44,6 +44,7 @@ module GUI
44
44
  :class => :minute_select,
45
45
  :value => @minute, :options => options)
46
46
  end
47
+ @minute_element
47
48
  end
48
49
  def second_element
49
50
  if !@second_element then
@@ -58,7 +59,7 @@ module GUI
58
59
 
59
60
  def element
60
61
  select_fields = []
61
- @time_format.scan(/./).each { |c|
62
+ @time_format.to_s.split('').each { |c|
62
63
  case c
63
64
  when 'h' then
64
65
  select_fields << hour_element()
@@ -53,8 +53,8 @@ module GUI
53
53
  @column_css_classes = params[:column_css_classes]
54
54
  @column_css_classes ||= []
55
55
  @column_css_classes = [ @column_css_classes ] unless @column_css_classes.is_a?(Array)
56
- params[:cellpadding] = 0 unless params[:cellpadding]
57
- params[:cellspacing] = 0 unless params[:cellspacing]
56
+ params[:cellpadding] = 0 unless params[:cellpadding]
57
+ params[:cellspacing] = 0 unless params[:cellspacing]
58
58
  params.delete(:headers)
59
59
  params.delete(:num_columns)
60
60
  params.delete(:row_css_classes)
@@ -63,8 +63,9 @@ module GUI
63
63
  super(params, &block)
64
64
  end
65
65
 
66
- def headers=(headers)
66
+ def headers=(*headers)
67
67
  @headers = headers
68
+ @headers = headers.first if headers.is_a?(Array)
68
69
  if @headers.length > 0 then
69
70
  @headers.map! { |cell|
70
71
  if cell.is_a? Element then
@@ -77,6 +78,13 @@ module GUI
77
78
  end
78
79
  alias set_headers headers=
79
80
 
81
+ def column_css_classes=(*classes)
82
+ @column_css_classes = classes
83
+ @column_css_classes.flatten!
84
+ # touch()
85
+ end
86
+ alias set_column_css_classes column_css_classes=
87
+
80
88
  def add_row(*row_data)
81
89
  if row_data.first.is_a?(Array) then
82
90
  row_data = row_data.first
@@ -114,13 +122,17 @@ module GUI
114
122
  }
115
123
  end
116
124
 
125
+ # Returns cell at given column and row (like x, y coordinates)
117
126
  def cell(column, row)
118
127
  rows[row][column]
119
128
  end
120
129
 
130
+ # Returns Table_Row instance at given row index in table.
121
131
  def [](row_index)
122
132
  rows[row_index]
123
133
  end
134
+
135
+ # Sets Table_Row instance at given row index in table.
124
136
  def []=(row_index, row_data)
125
137
  rows[row_index] = row_data
126
138
  end
@@ -169,7 +181,7 @@ module GUI
169
181
  end
170
182
 
171
183
  def string
172
- if @touched then
184
+ if touched? then
173
185
  @cells = []
174
186
  @cell_data.each { |cell|
175
187
  @cells << @cell_class.new(cell, :parent => self, :column_index => column_index)
@@ -205,14 +217,14 @@ module GUI
205
217
  #
206
218
  # cell = my_table[row][column]
207
219
  # cell.content = 'New cell content'
208
- # cell.class = 'table_cell_css_class'
220
+ # cell.class = 'table_cell_css_class'
209
221
  #
210
222
  class Table_Cell < Element
211
223
 
212
224
  attr_accessor :value, :presentation_class, :parent
213
225
 
214
226
  def initialize(cell_element, params={})
215
- params[:tag] = :td
227
+ params[:tag] = :td
216
228
  @content ||= cell_element
217
229
  @value ||= cell_element
218
230
  @presentation_class ||= false
@@ -5,6 +5,46 @@ require('aurita-gui/element')
5
5
  module Aurita
6
6
  module GUI
7
7
 
8
+ # Widget is a proxy / factory for an actual Aurita::GUI::Element.
9
+ # Method #element has to be overloaded that defines the Element
10
+ # instance the class is delegating to.
11
+ #
12
+ # A simple widget could look like this:
13
+ #
14
+ # class Annotated_Image < Aurita::GUI::Widget
15
+ #
16
+ # attr_accessor :src, :title, :description
17
+ #
18
+ # def initialize(params={})
19
+ # @src = params[:src]
20
+ # @title = params[:title]
21
+ # @description = params[:description]
22
+ # end
23
+ #
24
+ # def element
25
+ # HTML.div.annotated_image {
26
+ # HTML.img(:src => @src, :title => @title, :alt => @title) +
27
+ # HTML.p { @description }
28
+ # }
29
+ # end
30
+ #
31
+ # end # class
32
+ #
33
+ # It then can be used like a regular Element instance:
34
+ #
35
+ # image = Annotated_Image.new(:src => '/images/wombat.jpg',
36
+ # :title => 'wombat',
37
+ # :description => 'A cute wombat')
38
+ # image.add_css_class(:active)
39
+ # puts image.string
40
+ #
41
+ # -->
42
+ #
43
+ # <div class="annotated_image active">
44
+ # <img src="/images/wombat.jpg" title="wombat" alt="wombat" />
45
+ # <p>A cute wombat</p>
46
+ # </div>
47
+ #
8
48
  class Widget < DelegateClass(Element)
9
49
  include Aurita::GUI
10
50
 
@@ -0,0 +1,127 @@
1
+
2
+ require('rubygems')
3
+ require('aurita-gui/form')
4
+
5
+ include Aurita::GUI
6
+
7
+ describe Aurita::GUI::Form, "basic rendering" do
8
+ before do
9
+ @form = Form.new()
10
+ @first_input_field = Input_Field.new(:name => :first_input_field, :value => 42)
11
+ @second_input_field = Input_Field.new(:name => :second_input_field)
12
+ @fieldset = Fieldset.new(:legend => 'First fieldset', :name => :the_fieldset) {
13
+ @first_input_field + @second_input_field
14
+ }
15
+ @third_input_field = Input_Field.new(:name => :third_input_field)
16
+ end
17
+
18
+ it "should provide method #add to add form fields" do
19
+ @form.add(@third_input_field)
20
+ @form.add(@fieldset)
21
+
22
+ @form.elements.length.should == 2
23
+
24
+ @form[:first_input_field].value.should == 42
25
+ @form[:second_input_field].value = 23
26
+ @form[:second_input_field].value.should == 23
27
+ end
28
+
29
+ it "should allow access to form fields by index" do
30
+ @form.add(@fieldset)
31
+ @form.add(@third_input_field)
32
+ @form.elements[0].should == @fieldset
33
+ @form.elements[1].should == @third_input_field
34
+ end
35
+
36
+ it "should render as a <fieldset> element" do
37
+ @form.add(@fieldset)
38
+ @form.add(@third_input_field)
39
+
40
+ expected = <<END
41
+ <form method="POST" enctype="multipart/form-data">
42
+ <ul class="form_fields">
43
+ <li>
44
+ <fieldset>
45
+ <legend>First fieldset</legend>
46
+ <ul class="form_fields fieldset">
47
+ <li class="input_field_wrap form_field" id="first_input_field_wrap">
48
+ <input type="text" value="42" name="first_input_field" id="first_input_field" />
49
+ </li>
50
+
51
+ <li class="input_field_wrap form_field" id="second_input_field_wrap">
52
+ <input type="text" name="second_input_field" id="second_input_field" />
53
+ </li>
54
+ </ul>
55
+ </fieldset>
56
+
57
+ </li>
58
+
59
+ <li class="input_field_wrap form_field" id="third_input_field_wrap">
60
+ <input type="text" name="third_input_field" id="third_input_field" />
61
+ </li>
62
+ </ul>
63
+ </form>
64
+ END
65
+ @form.to_s.gsub("\n",'').gsub(/>\s*</,'><').should == expected.gsub("\n",'').gsub(/>\s*</,'><')
66
+ end
67
+
68
+ it "should allow applying field settings to a form's fieldsets" do
69
+ form = Form.new()
70
+
71
+ first = Text_Field.new(:name => :first, :value => 1)
72
+ second = Text_Field.new(:name => :second, :value => 2)
73
+ third = Text_Field.new(:name => :third, :value => 3)
74
+
75
+ form.add(first)
76
+ form.add(second)
77
+ form.add(third)
78
+
79
+ form.fields = [ { :the_legend => [ :first, :third ] }, :second ]
80
+
81
+ expected = <<END
82
+ <form method="POST" enctype="multipart/form-data">
83
+ <ul class="form_fields">
84
+ <li>
85
+ <fieldset>
86
+ <ul class="form_fields fieldset">
87
+ <li class="text_field_wrap form_field" id="first_wrap">
88
+ <input type="text" value="1" name="first" id="first" />
89
+ </li>
90
+ <li class="text_field_wrap form_field" id="third_wrap">
91
+ <input type="text" value="3" name="third" id="third" />
92
+ </li>
93
+ </ul>
94
+ </fieldset>
95
+ </li>
96
+ <li class="text_field_wrap form_field" id="second_wrap">
97
+ <input type="text" value="2" name="second" id="second" />
98
+ </li>
99
+ </ul>
100
+ </form>
101
+ END
102
+
103
+ form.to_s.gsub("\n",'').gsub(/>\s*</,'><').should == expected.gsub("\n",'').gsub(/>\s*</,'><')
104
+
105
+ form.fields = [ { :the_legend => [ :third ] }, :second ]
106
+ expected = <<END
107
+ <form method="POST" enctype="multipart/form-data">
108
+ <ul class="form_fields">
109
+ <li>
110
+ <fieldset>
111
+ <ul class="form_fields fieldset">
112
+ <li class="text_field_wrap form_field" id="third_wrap">
113
+ <input type="text" value="3" name="third" id="third" />
114
+ </li>
115
+ </ul>
116
+ </fieldset>
117
+ </li>
118
+ <li class="text_field_wrap form_field" id="second_wrap">
119
+ <input type="text" value="2" name="second" id="second" />
120
+ </li>
121
+ </ul>
122
+ </form>
123
+ END
124
+ form.to_s.gsub("\n",'').gsub(/>\s*</,'><').should == expected.gsub("\n",'').gsub(/>\s*</,'><')
125
+ end
126
+
127
+ end
@@ -10,7 +10,7 @@ describe Aurita::GUI::Form, "basic rendering" do
10
10
  @text_field = Input_Field.new(:name => :textfield)
11
11
  end
12
12
 
13
- it "should probvide method #add to add form fields" do
13
+ it "should provide method #add to add form fields" do
14
14
  @form.add(@text_field)
15
15
  end
16
16
 
@@ -25,4 +25,22 @@ describe Aurita::GUI::Form, "basic rendering" do
25
25
  @form.to_s.should == '<form method="POST" enctype="multipart/form-data"><ul class="form_fields"><li class="input_field_wrap form_field" id="textfield_wrap"><input type="text" name="textfield" id="textfield" /></li></ul></form>'
26
26
  end
27
27
 
28
+ it "should provide reordering of form fields" do
29
+ form = Form.new
30
+
31
+ text_1 = Text_Field.new(:name => :first, :value => 1)
32
+ checkbox = Checkbox_Field.new(:name => :second, :options => { 'foo' => 1, 'bar' => 2 } )
33
+
34
+ form.add(text_1)
35
+ form.add(checkbox)
36
+
37
+ form.fields = [ 'first' ]
38
+
39
+ puts form.to_s.gsub('><', ">\n<")
40
+ end
41
+
42
+ it "should provide disabling form fields for rendering" do
43
+
44
+ end
45
+
28
46
  end
@@ -9,44 +9,44 @@ describe Aurita::GUI::Table, "basic rendering" do
9
9
  it "should provide headers" do
10
10
  table = Table.new(:headers => [ :username, :email, 'last login' ],
11
11
  :class => 'spectable')
12
- table.to_s.should == '<table class="spectable"><tr><th>username</th><th>email</th><th>last login</th></tr></table>'
12
+ table.to_s.should == '<table cellpadding="0" cellspacing="0" class="spectable"><tr><th>username</th><th>email</th><th>last login</th></tr></table>'
13
13
  end
14
14
 
15
15
  it "should be possible to add rows" do
16
16
  table = Table.new(:headers => [ :username, :email, 'last login' ],
17
17
  :class => 'spectable')
18
18
  table.add_row('a','b','c')
19
- table.to_s.should == '<table class="spectable"><tr><th>username</th><th>email</th><th>last login</th></tr><tr><td>a</td><td>b</td><td>c</td></tr></table>'
19
+ table.to_s.should == '<table cellpadding="0" cellspacing="0" class="spectable"><tr><th>username</th><th>email</th><th>last login</th></tr><tr><td>a</td><td>b</td><td>c</td></tr></table>'
20
20
  end
21
21
 
22
22
  it "should be possible to change cell values" do
23
23
  table = Table.new(:class => 'spectable')
24
24
  table.add_row('a','b','c')
25
25
  table[0][1] = 'changed'
26
- table.to_s.should == '<table class="spectable"><tr><td>a</td><td>changed</td><td>c</td></tr></table>'
26
+ table.to_s.should == '<table cellpadding="0" cellspacing="0" class="spectable"><tr><td>a</td><td>changed</td><td>c</td></tr></table>'
27
27
  end
28
28
 
29
29
  it "should be possible to modify Table_Cell elements" do
30
30
  table = Table.new(:column_css_classes => [ :c1, :c2, :c3 ] )
31
31
  table.add_row('a','b','c')
32
- table.to_s.should == '<table><tr><td class="c1">a</td><td class="c2">b</td><td class="c3">c</td></tr></table>'
32
+ table.to_s.should == '<table cellpadding="0" cellspacing="0"><tr><td class="c1">a</td><td class="c2">b</td><td class="c3">c</td></tr></table>'
33
33
  table.add_row('a','b','c')
34
34
  table[0].add_css_class(:gnarg)
35
35
  table[0][1].add_css_class(:knorg)
36
- table.to_s.should == '<table><tr class="gnarg"><td class="c1">a</td><td class="c2 knorg">b</td><td class="c3">c</td></tr><tr><td class="c1">a</td><td class="c2">b</td><td class="c3">c</td></tr></table>'
36
+ table.to_s.should == '<table cellpadding="0" cellspacing="0"><tr class="gnarg"><td class="c1">a</td><td class="c2 knorg">b</td><td class="c3">c</td></tr><tr><td class="c1">a</td><td class="c2">b</td><td class="c3">c</td></tr></table>'
37
37
  end
38
38
 
39
39
  it "should be possible to set CSS classes for columns" do
40
40
  table = Table.new(:class => 'spectable', :column_css_classes => [ :c1, :c2, :c3 ] )
41
41
  table.add_row('a','b','c')
42
- table.to_s.should == '<table class="spectable"><tr><td class="c1">a</td><td class="c2">b</td><td class="c3">c</td></tr></table>'
42
+ table.to_s.should == '<table cellpadding="0" cellspacing="0" class="spectable"><tr><td class="c1">a</td><td class="c2">b</td><td class="c3">c</td></tr></table>'
43
43
  end
44
44
 
45
45
  it "should be possible to set CSS classes for rows" do
46
46
  table = Table.new(:class => 'spectable', :row_css_classes => :trow )
47
47
  table.add_row('a','b','c')
48
48
  table.add_row('a','b','c')
49
- table.to_s.should == '<table class="spectable"><tr class="trow"><td>a</td><td>b</td><td>c</td></tr><tr class="trow"><td>a</td><td>b</td><td>c</td></tr></table>'
49
+ table.to_s.should == '<table cellpadding="0" cellspacing="0" class="spectable"><tr class="trow"><td>a</td><td>b</td><td>c</td></tr><tr class="trow"><td>a</td><td>b</td><td>c</td></tr></table>'
50
50
  end
51
51
 
52
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aurita-gui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Fuchs
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-23 00:00:00 +02:00
12
+ date: 2009-08-31 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -31,60 +31,61 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
 
33
33
  files:
34
- - test
35
- - README.txt
36
- - spec
37
- - TODO
38
- - samples
39
- - aurita-gui.gemspec
40
- - lib
41
- - bin
42
- - LICENSE
43
- - lib/aurita-gui.rb
44
- - lib/aurita-gui
45
- - lib/aurita-gui/element_fixed.rb
46
- - lib/aurita-gui/html.rb
47
- - lib/aurita-gui/form.rb
48
- - lib/aurita-gui/widget.rb
49
- - lib/aurita-gui/button.rb
50
- - lib/aurita-gui/element.rb
51
- - lib/aurita-gui/form
52
- - lib/aurita-gui/javascript.rb
53
- - lib/aurita-gui/marshal.rb
54
- - lib/aurita-gui/table.rb
55
- - lib/aurita-gui/form/datetime_field.rb
56
- - lib/aurita-gui/form/input_field.rb
57
- - lib/aurita-gui/form/radio_field.rb
58
- - lib/aurita-gui/form/checkbox_field.rb
59
- - lib/aurita-gui/form/time_field.rb
60
- - lib/aurita-gui/form/date_field.rb
61
- - lib/aurita-gui/form/form_field.rb
62
- - lib/aurita-gui/form/options_field.rb
63
- - lib/aurita-gui/form/password_field.rb
64
- - lib/aurita-gui/form/text_field.rb
65
- - lib/aurita-gui/form/textarea_field.rb
66
- - lib/aurita-gui/form/select_field.rb
67
- - lib/aurita-gui/form/file_field.rb
68
- - lib/aurita-gui/form/hidden_field.rb
69
- - lib/aurita-gui/form/template_helper.rb
70
- - lib/aurita-gui/form/boolean_field.rb
71
- - lib/aurita-gui/form/form_error.rb
72
- - lib/aurita-gui/form/fieldset.rb
73
- - lib/aurita-gui/form/selection_list.rb
74
- - samples/putstest.rb
75
- - samples/recurse.rb
76
- - samples/cheatsheet.rb
77
- - samples/valuetest.rb
78
- - samples/pushtest.rb
79
- - spec/html.rb
80
- - spec/form.rb
81
- - spec/element.rb
82
- - spec/options.rb
83
- - spec/javascript.rb
84
- - spec/marshal.rb
85
- - spec/selection_list.rb
86
- - spec/init_code.rb
87
- - spec/table.rb
34
+ - ./README.txt
35
+ - ./Manifest.txt
36
+ - ./spec
37
+ - ./spec/html.rb
38
+ - ./spec/form.rb
39
+ - ./spec/element.rb
40
+ - ./spec/options.rb
41
+ - ./spec/fieldset.rb
42
+ - ./spec/javascript.rb
43
+ - ./spec/marshal.rb
44
+ - ./spec/selection_list.rb
45
+ - ./spec/init_code.rb
46
+ - ./spec/table.rb
47
+ - ./TODO
48
+ - ./samples
49
+ - ./samples/putstest.rb
50
+ - ./samples/recurse.rb
51
+ - ./samples/cheatsheet.rb
52
+ - ./samples/valuetest.rb
53
+ - ./samples/pushtest.rb
54
+ - ./aurita-gui.gemspec
55
+ - ./lib
56
+ - ./lib/aurita-gui.rb
57
+ - ./lib/aurita-gui
58
+ - ./lib/aurita-gui/element_fixed.rb
59
+ - ./lib/aurita-gui/html.rb
60
+ - ./lib/aurita-gui/form.rb
61
+ - ./lib/aurita-gui/widget.rb
62
+ - ./lib/aurita-gui/button.rb
63
+ - ./lib/aurita-gui/element.rb
64
+ - ./lib/aurita-gui/form
65
+ - ./lib/aurita-gui/form/datetime_field.rb
66
+ - ./lib/aurita-gui/form/input_field.rb
67
+ - ./lib/aurita-gui/form/radio_field.rb
68
+ - ./lib/aurita-gui/form/checkbox_field.rb
69
+ - ./lib/aurita-gui/form/time_field.rb
70
+ - ./lib/aurita-gui/form/date_field.rb
71
+ - ./lib/aurita-gui/form/form_field.rb
72
+ - ./lib/aurita-gui/form/options_field.rb
73
+ - ./lib/aurita-gui/form/password_field.rb
74
+ - ./lib/aurita-gui/form/text_field.rb
75
+ - ./lib/aurita-gui/form/textarea_field.rb
76
+ - ./lib/aurita-gui/form/select_field.rb
77
+ - ./lib/aurita-gui/form/file_field.rb
78
+ - ./lib/aurita-gui/form/hidden_field.rb
79
+ - ./lib/aurita-gui/form/template_helper.rb
80
+ - ./lib/aurita-gui/form/boolean_field.rb
81
+ - ./lib/aurita-gui/form/form_error.rb
82
+ - ./lib/aurita-gui/form/fieldset.rb
83
+ - ./lib/aurita-gui/form/selection_list.rb
84
+ - ./lib/aurita-gui/javascript.rb
85
+ - ./lib/aurita-gui/marshal.rb
86
+ - ./lib/aurita-gui/table.rb
87
+ - ./bin
88
+ - ./LICENSE
88
89
  has_rdoc: true
89
90
  homepage: http://aurita.wortundform.de/
90
91
  post_install_message: