Module: Plushie::Widget::Build

Defined in:
lib/plushie/widget/build.rb

Overview

Internal helpers for widget builder build implementations.

Class Method Summary collapse

Class Method Details

.children_to_nodes(children) ⇒ Object

Converts an array of children (Nodes or builder objects) to Nodes.



23
24
25
26
27
28
29
30
31
# File 'lib/plushie/widget/build.rb', line 23

def children_to_nodes(children)
  children.map do |child|
    case child
    when Plushie::Node then child
    else
      child.respond_to?(:build) ? child.build : child
    end
  end
end

.put_if(props, key, value) ⇒ Object

Adds key => value to props hash if value is non-nil.



11
12
13
14
# File 'lib/plushie/widget/build.rb', line 11

def put_if(props, key, value)
  props[key] = value unless value.nil?
  props
end

.put_if_map(props, key, value, &transform) ⇒ Object

Adds key => transform(value) to props hash if value is non-nil.



17
18
19
20
# File 'lib/plushie/widget/build.rb', line 17

def put_if_map(props, key, value, &transform)
  props[key] = transform.call(value) unless value.nil?
  props
end