nakajima-semi-formal 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/semi_formal/input.rb +29 -2
- metadata +1 -1
data/lib/semi_formal/input.rb
CHANGED
@@ -7,13 +7,40 @@ module SemiFormal
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(builder)
|
10
|
-
|
10
|
+
this = self
|
11
|
+
builder.label do
|
12
|
+
span { text this.label_name }
|
13
|
+
this.decorate(self)
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
|
-
|
17
|
+
alias_method :[], :call
|
18
|
+
|
19
|
+
def value
|
20
|
+
instance.send(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def label_name
|
24
|
+
name.to_s.titleize
|
25
|
+
end
|
14
26
|
|
15
27
|
def attr_name
|
16
28
|
instance.class.model_name.singular + "[#{name}]"
|
17
29
|
end
|
30
|
+
|
31
|
+
def field_type
|
32
|
+
instance.class.columns_hash[name.to_s].type
|
33
|
+
end
|
34
|
+
|
35
|
+
def decorate(builder)
|
36
|
+
this = self
|
37
|
+
case field_type
|
38
|
+
when :string
|
39
|
+
builder.input(:name => attr_name, :type => "text", :value => value)
|
40
|
+
when :text
|
41
|
+
this = self
|
42
|
+
builder.textarea(:name => attr_name) { text(this.value.to_s) }
|
43
|
+
end
|
44
|
+
end
|
18
45
|
end
|
19
46
|
end
|