Module: XRB::Formatters::HTML::DefinitionListForm

Includes:
FormFormatter
Defined in:
lib/xrb/formatters/html/definition_list_form.rb

Instance Method Summary collapse

Methods included from FormFormatter

#button, #button_attributes_for, #button_title_for, #checkbox_attributes_for, #details_for, #field_for, #hidden, #hidden_attributes_for, #input_attributes_for, #new_record?, #object_value_for, #output_attributes_for, #pattern_for, #placeholder_for, #raw_value_for, #submit_attributes_for, #submit_title_for, #textarea_attributes_for, #title_for, #value_for

Instance Method Details

#checkbox(**options) ⇒ Object

A checkbox field.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/xrb/formatters/html/definition_list_form.rb', line 73

def checkbox(**options)
	options = @options.merge(**options)
	
	Builder.fragment do |builder|
		builder.tag(:dd) do
			builder.tag :input, :type => :hidden, :name => name_for(**options), :value => "false"
			
			builder.inline(:label) do
				builder.tag :input, checkbox_attributes_for(**options)
				# We would like a little bit of whitespace between the checkbox and the title.
				builder.text " " + title_for(**options)
			end
			
			if details = details_for(**options)
				builder.inline(:small, class: "details") {builder.text details}
			end
		end
	end
end

#element(klass, **options, &block) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/xrb/formatters/html/definition_list_form.rb', line 103

def element(klass, **options, &block)
	options = @options.merge(**options)
	
	Builder.fragment(block&.binding) do |builder|
		builder.inline(:dt) do
			builder.text title_for(**options)
		end
		
		builder.tag(:dd) do
			klass.call(self, builder, **options, &block)
			
			if details = details_for(**options)
				builder.inline(:small, class: "details") {builder.text details}
			end
		end
	end
end

#fieldset(**options, &block) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/xrb/formatters/html/definition_list_form.rb', line 121

def fieldset(**options, &block)
	super do |builder|
		builder.tag(:dl) do
			yield(builder)
		end
	end
end

#input(**options) ⇒ Object

An input field (single line text).



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/xrb/formatters/html/definition_list_form.rb', line 18

def input(**options)
	options = @options.merge(**options)
	
	Builder.fragment do |builder|
		builder.inline(:dt) do
			builder.text title_for(**options)
		end
		
		builder.inline(:dd) do
			builder.tag :input, input_attributes_for(**options)
			
			if details = details_for(**options)
				builder.inline(:small, class: "details") {builder.text details}
			end
		end
	end
end

#output(**options) ⇒ Object

An output field for the result of a computation.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/xrb/formatters/html/definition_list_form.rb', line 37

def output(**options)
	options = @options.merge(**options)

	Builder.fragment do |builder|
		builder.inline(:dt) {builder.text title_for(**options)}

		builder.inline(:dd) do
			builder.inline :output, output_attributes_for(**options) do
				builder.text value_for(**options)
			end
		end
	end
end

#submit(**options) ⇒ Object

A submission button



94
95
96
97
98
99
100
101
# File 'lib/xrb/formatters/html/definition_list_form.rb', line 94

def submit(**options)
	options = @options.merge(**options)
	options[:title] ||= submit_title_for(**options)
	
	Builder.fragment do |builder|
		builder.tag :input, submit_attributes_for(**options)
	end
end

#textarea(**options) ⇒ Object

A textarea field (multi-line text).



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/xrb/formatters/html/definition_list_form.rb', line 52

def textarea(**options)
	options = @options.merge(**options)

	Builder.fragment do |builder|
		builder.tag(:dt) do
			builder.text title_for(**options)
				
			if details = details_for(**options)
				builder.inline(:small, class: "details") {builder.text details}
			end
		end
		
		builder.inline(:dd) do
			builder.tag :textarea, textarea_attributes_for(**options) do
				builder.text value_for(**options)
			end
		end
	end
end