Skip to content

Commit d3b50e0

Browse files
committed
erector-ify entry dl
1 parent 95111a0 commit d3b50e0

File tree

4 files changed

+59
-54
lines changed

4 files changed

+59
-54
lines changed

lib/formbuilder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require "formbuilder/engine"
22
require "formbuilder/entry"
3-
require "formbuilder/entry_renderer"
43
require "formbuilder/entry_validator"
54
require "formbuilder/views/form"
65
require "formbuilder/views/form_field"
6+
require "formbuilder/views/entry_dl"
77

88
module Formbuilder
99
def self.root

lib/formbuilder/entry_renderer.rb

Lines changed: 0 additions & 47 deletions
This file was deleted.

lib/formbuilder/views/entry_dl.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module Formbuilder
2+
module Views
3+
class EntryDl < Erector::Widget
4+
5+
needs :entry, :form, show_blind: false
6+
7+
def content
8+
dl(class: 'entry-dl') {
9+
response_fields.each do |rf|
10+
value = @entry.response_value(rf)
11+
12+
dt {
13+
text rf.label
14+
blind_label if rf.blind?
15+
admin_only_label if rf.admin_only?
16+
}
17+
18+
dd {
19+
if (x = rf.render_entry(value, entry: @entry))
20+
rawtext x
21+
else
22+
no_response
23+
end
24+
}
25+
end
26+
}
27+
end
28+
29+
private
30+
def blind_label
31+
text ' '
32+
span.label 'Blind'
33+
end
34+
35+
def admin_only_label
36+
text ' '
37+
span.label 'Admin only'
38+
end
39+
40+
def no_response
41+
span 'No response', class: 'no-response'
42+
end
43+
44+
def response_fields
45+
return_array = @form.response_fields.reject { |rf| !rf.input_field }
46+
return_array.reject! { |rf| rf.blind? } unless @show_blind
47+
return_array
48+
end
49+
50+
end
51+
end
52+
end
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper'
22

3-
describe Formbuilder::EntryRenderer do
3+
describe Formbuilder::Views::EntryDl do
44

55
TEXT_FIELD_PARAMS = { label: "Text", type: "Formbuilder::ResponseFieldText", sort_order: 0 }
66

@@ -9,29 +9,29 @@
99

1010
it 'should display a label for blind fields' do
1111
form.response_fields.create TEXT_FIELD_PARAMS.merge(blind: true)
12-
Formbuilder::EntryRenderer.new(entry, form, show_blind: true).to_html.should match('Blind')
12+
Formbuilder::Views::EntryDl.new(entry: entry, form: form, show_blind: true).to_html.should match('Blind')
1313
end
1414

1515
it 'should only display blind fields when instructed to' do
1616
form.response_fields.create TEXT_FIELD_PARAMS.merge(blind: true)
17-
Formbuilder::EntryRenderer.new(entry, form).to_html.should_not match('Blind')
17+
Formbuilder::Views::EntryDl.new(entry: entry, form: form).to_html.should_not match('Blind')
1818
end
1919

2020
it 'should display a label for admin only fields' do
2121
form.response_fields.create TEXT_FIELD_PARAMS.merge(admin_only: true)
22-
Formbuilder::EntryRenderer.new(entry, form).to_html.should match('Admin Only')
22+
Formbuilder::Views::EntryDl.new(entry: entry, form: form).to_html.should match('Admin only')
2323
end
2424

2525
it 'should display placeholder text if there is no response' do
2626
form.response_fields.create TEXT_FIELD_PARAMS
27-
Formbuilder::EntryRenderer.new(entry, form).to_html.should match('No response')
27+
Formbuilder::Views::EntryDl.new(entry: entry, form: form).to_html.should match('No response')
2828
end
2929

3030
it 'should display the response' do
3131
rf = form.response_fields.create TEXT_FIELD_PARAMS
3232
entry.save_response('buzz', rf)
3333
entry.save(validate: false)
34-
Formbuilder::EntryRenderer.new(entry, form).to_html.should match('buzz')
34+
Formbuilder::Views::EntryDl.new(entry: entry, form: form).to_html.should match('buzz')
3535
end
3636

3737
end

0 commit comments

Comments
 (0)