Skip to content

Commit ad1d631

Browse files
authored
Port FormBuilder from Rails template (#61)
- Add capybara for html rspec matchers - Port over USWDSFormBuilder to Flex::FormBuilder - Add memorable_date function to form builder ## Context I think the form builder makes more sense in the flex module because: 1. We already have a case where a function we want to add to form builder (memorable_date) relies on Flex functionality (the memorable_date flex_attribute) 2. Over time it would be nice to add more functionality to the form builder that extends beyond the basic building blocks from USWDS. For example we'd want to be able to generate form elements for other flex_attributes like full_name, address, etc. This form builder is a straight port of USWDSFormBuilder with the following changes: 1. Namespaced to Flex module 2. Scoped content strings to flex.* 3. Renamed helper method from us_form_with to flex_form_with Note: the added capybara gem is for rspec html matchers like "expect(html_string).to have_element(...)"
1 parent e3bc037 commit ad1d631

13 files changed

Lines changed: 821 additions & 5 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ end
3434

3535
group :test do
3636
gem "simplecov", require: false
37+
gem "capybara"
3738
end

Gemfile.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ GEM
8585
benchmark (0.4.0)
8686
bigdecimal (3.1.9)
8787
builder (3.3.0)
88+
capybara (3.40.0)
89+
addressable
90+
matrix
91+
mini_mime (>= 0.1.3)
92+
nokogiri (~> 1.11)
93+
rack (>= 1.6.0)
94+
rack-test (>= 0.6.3)
95+
regexp_parser (>= 1.5, < 3.0)
96+
xpath (~> 3.2)
8897
coderay (1.1.3)
8998
concurrent-ruby (1.3.5)
9099
connection_pool (2.5.0)
@@ -161,6 +170,7 @@ GEM
161170
net-pop
162171
net-smtp
163172
marcel (1.0.4)
173+
matrix (0.4.2)
164174
method_source (1.1.0)
165175
mini_mime (1.1.5)
166176
minitest (5.25.5)
@@ -356,6 +366,8 @@ GEM
356366
base64
357367
websocket-extensions (>= 0.1.0)
358368
websocket-extensions (0.1.5)
369+
xpath (3.2.0)
370+
nokogiri (~> 1.8)
359371
yard (0.9.37)
360372
zeitwerk (2.7.2)
361373

@@ -371,6 +383,7 @@ PLATFORMS
371383

372384
DEPENDENCIES
373385
actioncable
386+
capybara
374387
flex!
375388
guard-rspec
376389
listen
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module Flex
22
module ApplicationHelper
3+
def flex_form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
4+
options[:builder] = Flex::FormBuilder
5+
form_with model: model, scope: scope, url: url, format: format, **options, &block
6+
end
37
end
48
end

0 commit comments

Comments
 (0)