Class: Arbre::Form::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/arbre/form/config.rb

Defined Under Namespace

Classes: Component

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Config

Returns a new instance of Config.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/arbre/form/config.rb', line 20

def initialize(&block)
  self.wrappers = OpenStruct.new(
    field: Arbre::HTML::Div,
    group: Arbre::Form::Component::Group,
    association: Arbre::Form::Component::Group,
    record: Arbre::HTML::Fieldset,
    error: Arbre::Form::Field::Validation,
    success: Arbre::Form::Field::Validation,
  )

  self.classes = OpenStruct.new(
    error: 'is-invalid',
    errors: 'invalid-feedback',
    success: 'is-valid',
    successes: 'valid-feedback'
  )

  self.components = OpenStruct.new(
    input: Component.new(
      tag: Arbre::HTML::Input
    ),

    checkbox: Component.new(
      tag: Arbre::HTML::Input,
      type: 'checkbox',
      formatter: proc { |value| value ? '1' : '0' },
    ),

    date: Component.new(tag: Arbre::HTML::Input,
      type: 'date',
      formatter: proc { |date| date.strftime('%Y-%m-%d') if date },
    ),

    datetime: Component.new(
      tag: Arbre::HTML::Input,
      type: 'datetime-local',
      formatter: proc { |time| time.strftime('%Y-%m-%dT%H:%M') if time }
    ),

    email: Component.new(
      tag: Arbre::HTML::Input,
      type: 'email'
    ),

    file: Component.new(
      tag: Arbre::HTML::Input,
      type: 'file'
    ),

    hidden: Component.new(
      tag: Arbre::HTML::Input,
      type: 'hidden'
    ),

    image: Component.new(
      tag: Arbre::HTML::Input,
      type: 'image'
    ),

    month: Component.new(
      tag: Arbre::HTML::Input,
      type: 'month'
    ),

    number: Component.new(
      tag: Arbre::HTML::Input,
      type: 'number'
    ),

    password: Component.new(
      tag: Arbre::HTML::Input,
      type: 'password'
    ),

    radio: Component.new(
      tag: Arbre::HTML::Input,
      type: 'radio'
    ),

    range: Component.new(
      tag: Arbre::HTML::Input,
      type: 'range'
    ),

    search: Component.new(
      tag: Arbre::HTML::Input,
      type: 'search'
    ),

    tel: Component.new(
      tag: Arbre::HTML::Input,
      type: 'tel'
    ),

    text: Component.new(
      tag: Arbre::HTML::Input,
      type: 'text'
    ),

    time: Component.new(
      tag: Arbre::HTML::Input,
      type: 'time'
    ),

    url: Component.new(
      tag: Arbre::HTML::Input,
      type: 'url'
    ),

    week: Component.new(
      tag: Arbre::HTML::Input,
      type: 'week'
    ),

    select: Component.new(
      tag: Arbre::HTML::Select
    ),

    textarea: Component.new(
      tag: Arbre::HTML::Textarea
    )
  )

  instance_exec(&block) if block
end

Instance Attribute Details

#classesObject

Returns the value of attribute classes.



8
9
10
# File 'lib/arbre/form/config.rb', line 8

def classes
  @classes
end

#componentsObject

Returns the value of attribute components.



8
9
10
# File 'lib/arbre/form/config.rb', line 8

def components
  @components
end

#wrappersObject

Returns the value of attribute wrappers.



8
9
10
# File 'lib/arbre/form/config.rb', line 8

def wrappers
  @wrappers
end