vidl-toolbox 0.0.9 → 0.0.10

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.
@@ -26,6 +26,25 @@ module Toolbox
26
26
  end
27
27
 
28
28
 
29
+ # Get the field value out of a model object
30
+ # If the attribute method is defined and it's a symbol, this method is called on the model object
31
+ # If the attribute method is defined and it's a block (Proc), the block is called with the model object as parameter
32
+ # In all other cases, the field name is interpreted as method and called on the model object
33
+ def value(rec)
34
+ val = rec.send(@widget_config.model_method) if @widget_config.model_method && @widget_config.model_method.is_a?(Symbol)
35
+ val = @widget_config.model_method.call(rec) if @widget_config.model_method && @widget_config.model_method.is_a?(Proc)
36
+ unless val # fallback
37
+ a = @widget_config.name.to_s.split('.')
38
+ a.each do |t|
39
+ rec = rec.send(t)
40
+ break unless rec # stop if nil is returned
41
+ end
42
+ val = rec
43
+ end
44
+ val = nil if val == ''
45
+ val
46
+ end
47
+
29
48
  # Renders the label of the widget.
30
49
  # If show_model is set to a model name, the model name of this widget
31
50
  # will be added in parenthesis if it differs to the value in show_model.
@@ -93,24 +112,6 @@ module Toolbox
93
112
  end
94
113
  end
95
114
 
96
- # Get the field value out of a model object
97
- # If the attribute method is defined and it's a symbol, this method is called on the model object
98
- # If the attribute method is defined and it's a block (Proc), the block is called with the model object as parameter
99
- # In all other cases, the field name is interpreted as method and called on the model object
100
- def value(rec)
101
- val = rec.send(@widget_config.model_method) if @widget_config.model_method && @widget_config.model_method.is_a?(Symbol)
102
- val = @widget_config.model_method.call(rec) if @widget_config.model_method && @widget_config.model_method.is_a?(Proc)
103
- unless val # fallback
104
- a = @widget_config.name.to_s.split('.')
105
- a.each do |t|
106
- rec = rec.send(t)
107
- break unless rec # stop if nil is returned
108
- end
109
- val = rec
110
- end
111
- val = nil if val == ''
112
- val
113
- end
114
115
 
115
116
  # Renders the value of an attribute of a given object.
116
117
  # Parameters:
@@ -282,7 +283,7 @@ module Toolbox
282
283
  end
283
284
 
284
285
  def render_textfield form, rec, options
285
- val = rec.send @widget_config.name
286
+ val = value(rec) #rec.send @widget_config.name
286
287
  text = val.to_s
287
288
  text = val.to_s(:local_date) if val.instance_of? Date
288
289
  text = val.to_s(:local_time) if val.instance_of? Time
@@ -292,16 +293,16 @@ module Toolbox
292
293
 
293
294
  def render_textarea form, rec, options
294
295
  size = @widget_config.size || '40x10'
295
- val = rec.send @widget_config.name
296
- if val
297
- row = 0
298
- col = 0
299
- val.each_line do |line|
300
- row = row.succ
301
- col = [col, line.length].max
302
- end
303
- size = "#{col}x#{row}"
304
- end
296
+ #val = rec.send @widget_config.name
297
+ #if val
298
+ # row = 0
299
+ # col = 0
300
+ # val.each_line do |line|
301
+ # row = row.succ
302
+ # col = [col, line.length].max
303
+ # end
304
+ # size = "#{col}x#{row}"
305
+ #end
305
306
  form.text_area @widget_config.name, options.merge({:size => size})
306
307
  end
307
308
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Toolbox
3
- VERSION = '0.0.9'
3
+ VERSION = '0.0.10'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidl-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Nyffenegger