Skip to content

Commit c91f98f

Browse files
author
Ary Borenszweig
committed
Document CGI.build_form
1 parent 538baa5 commit c91f98f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/cgi.cr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,27 @@ module CGI
9090
end
9191
end
9292

93+
# Builds a CGI form.
94+
#
95+
# The yielded object has an `add` method that accepts two arguments,
96+
# a key (String) and a value (String or Nil). Keys and values are escaped
97+
# using `CGI#escape`.
98+
#
99+
# ```
100+
# params = CGI.build_form do |form|
101+
# form.add "color", "black"
102+
# form.add "name", "crystal"
103+
# form.add "year", "2012 - today"
104+
# end
105+
# params #=> "color=black&name=crystal&year=2012%20-%20today"
106+
# ```
93107
def self.build_form
94108
form_builder = FormBuilder.new
95109
yield form_builder
96110
form_builder.to_s
97111
end
98112

113+
# :nodoc:
99114
struct FormBuilder
100115
def initialize
101116
@string = StringIO.new

0 commit comments

Comments
 (0)