Skip to content

Commit 6fe25c5

Browse files
committed
refactor(input-base): move methods to input_html_helper
1 parent 6871fb5 commit 6fe25c5

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

lib/activeadmin_addons/support/input_base.rb

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,5 @@ class InputBase < Formtastic::Inputs::StringInput
77
include InputOptionsHandler
88
include InputMethods
99
include InputHtmlHelpers
10-
11-
def to_html
12-
load_input_class
13-
load_control_attributes
14-
render_custom_input
15-
if parts.any?
16-
input_wrapping { parts_to_html }
17-
else
18-
super
19-
end
20-
end
21-
22-
def input_html_options
23-
# maxwidth and size are added by Formtastic::Inputs::StringInput
24-
# but according to the HTML standard these are not valid attributes
25-
# on the inputs provided by this module
26-
super.except(:maxlength, :size).merge(control_attributes)
27-
end
28-
29-
def parts_to_html
30-
parts.flatten.join("\n").html_safe
31-
end
32-
33-
def load_input_class
34-
load_class(self.class.to_s.underscore.dasherize)
35-
end
36-
37-
def load_control_attributes
38-
# Override on child classes if needed
39-
end
40-
41-
def render_custom_input
42-
# Override on child classes if needed
43-
end
44-
45-
def parts
46-
@parts ||= []
47-
end
48-
49-
def concat(part)
50-
parts << part
51-
end
5210
end
5311
end

lib/activeadmin_addons/support/input_helpers/input_html_helpers.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,47 @@ def build_hidden_control(id, name, value = nil)
4040
value: value
4141
)
4242
end
43+
44+
def to_html
45+
load_input_class
46+
load_control_attributes
47+
render_custom_input
48+
if parts.any?
49+
input_wrapping { parts_to_html }
50+
else
51+
super
52+
end
53+
end
54+
55+
def input_html_options
56+
# maxwidth and size are added by Formtastic::Inputs::StringInput
57+
# but according to the HTML standard these are not valid attributes
58+
# on the inputs provided by this module
59+
super.except(:maxlength, :size).merge(control_attributes)
60+
end
61+
62+
def load_input_class
63+
load_class(self.class.to_s.underscore.dasherize)
64+
end
65+
66+
def load_control_attributes
67+
# Override on child classes if needed
68+
end
69+
70+
def render_custom_input
71+
# Override on child classes if needed
72+
end
73+
74+
def parts_to_html
75+
parts.flatten.join("\n").html_safe # rubocop:disable Rails/OutputSafety
76+
end
77+
78+
def concat(part)
79+
parts << part
80+
end
81+
82+
def parts
83+
@parts ||= []
84+
end
4385
end
4486
end

0 commit comments

Comments
 (0)