Skip to content

Commit

Permalink
Support :hr as select option value to use a hr tag instead of an opti…
Browse files Browse the repository at this point in the history
…on tag
  • Loading branch information
jeremyevans committed May 9, 2024
1 parent 35d7ae8 commit 52454c8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Support :hr as select option value to use a hr tag instead of an option tag (jeremyevans)

* Support maxlength and minlength options as attributes for textareas (jeremyevans)

* Support minlength option as attribute for text inputs (jeremyevans)
Expand Down
2 changes: 2 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,8 @@ Creates a select tag, containing option tags specified by the :options option.
array, uses the first entry of the array as the text of the option, and
the last entry of the array as the value of the option. If the last entry
of the array is a hash, uses the hash as the attributes for the option.
If the option value is +:hr+, uses an hr tag (allowed in recent versions of
the HTML standard).
:selected :: The value that should be selected. Any options that are equal to
this value (or included in this value if a multiple select box),
are set to selected.
Expand Down
4 changes: 3 additions & 1 deletion lib/forme/transformers/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ def process_select_options(os)

os.map do |x|
attr = {}
if tm
if x == :hr
next form._tag(:hr, {})
elsif tm
text = x.send(tm)
val = x.send(vm) if vm
elsif x.is_a?(Array)
Expand Down
2 changes: 1 addition & 1 deletion lib/forme/transformers/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Serializer
Forme.register_transformer(:serializer, :default, new)

# Which tags are self closing (such tags ignore children).
SELF_CLOSING = [:img, :input]
SELF_CLOSING = [:img, :input, :hr]

# Serialize the tag object to an html string. Supports +Tag+ instances,
# +Input+ instances (recursing into +call+ with the result of formatting the input),
Expand Down
4 changes: 4 additions & 0 deletions spec/forme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ def sel(opts, s)
@f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).must_equal '<select><option value="1">a</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
end

it "should support :hr as hr attribute in select options" do
@f.input(:select, :options=>[[:a, 1], :hr, [:c, 3]], :selected=>2).must_equal '<select><option value="1">a</option><hr/><option value="3">c</option></select>'
end

it "should have select work with false values" do
@f.input(:select, :options=>[[1, true], [2, false]], :value=>false).must_equal '<select><option value="true">1</option><option selected="selected" value="false">2</option></select>'
end
Expand Down

0 comments on commit 52454c8

Please sign in to comment.